Skip to content

Instantly share code, notes, and snippets.

@TomTasche
TomTasche / appengine.java
Created May 9, 2013 15:16
a demonstration of a file upload without any additional libraries on Android. More information here: http://blog.tomtasche.at/2013/05/android-upload-file-to-appengine.html
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
InputStream stream = req.getInputStream();
// do whatever you want with the stream now
} catch (Exception ex) {
throw new ServletException(ex);
}
@TomTasche
TomTasche / GTalkOAuthSASLMechanism.java
Last active December 17, 2015 04:08
this gist describes how to 1. get an OAuth token from Android's AccountManager, 2. use this token to connect with GTalk via XMPP. Blog post about it: http://blog.tomtasche.at/2013/05/gtalk-and-oauth-on-android.html
// taken from: http://stackoverflow.com/a/10712949/198996
// note: you don't have to change anything in this class
public class GTalkOAuthSASLMechanism extends SASLMechanism {
public static final String NAME = "X-GOOGLE-TOKEN";
public GTalkOAuthSASLMechanism(SASLAuthentication saslAuthentication) {
super(saslAuthentication);
}
@TomTasche
TomTasche / EinStern.java
Last active December 17, 2015 02:19
EinStern is a mixture of routing algorithms like depth-first and dijkstra. it is able to find a path between "things" - points without any distance or similar between each other. Blog post about it: http://blog.tomtasche.at/2013/05/routing-things-and-stuff.html
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* some kind of depth-first and dijkstra mixture. this little code snippet is
* able to find a path between "things" - points without any distance or similar
* between each other
*
@TomTasche
TomTasche / DoesStringPoolExist.java
Created May 4, 2013 19:42
i had a discussion about the possible existence of a global "String pool" in newer versions of Java. turns out, there is no such thing. however, hardcoded strings are "pooled", i.e. String a and String b in the example are the *same instance of String*.
String a = "test";
String b = "test";
System.out.println("a == b? " + (a == b)); // true
String c = "tester";
String d = a + "er";
System.out.println("c == d? " + (c == d)); // false
@TomTasche
TomTasche / git_status_all_the_things.bash
Last active December 16, 2015 09:39
"git status" for all folders in the current directory
#!/bin/bash
for dir in */;
do
clear;
echo $dir;
cd $dir;
git status;
cd ..;
read -p "Press [Enter] key to continue..."
@TomTasche
TomTasche / whitespace_trimmer
Created January 27, 2013 18:06
Trim surrounding whitespace from pictures
#!/bin/bash
if [ -z "$1" ]
then
exit 1
fi
cd "$1"
cropImage() {
@TomTasche
TomTasche / feedback_android.java
Created October 21, 2012 12:22
Use built-in feedback mechanism on Android
// more information here: http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html
try {
int i = 3 / 0;
} catch (Exception e) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = getApplication()
.getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
@TomTasche
TomTasche / TextToSpeechService.java
Created April 24, 2012 08:23
Sample implementation for InfiniteWakefulIntentService
import android.content.Intent;
import com.announcify.uberall.droid.util.TextToSpeechHelper;
public class TextToSpeechService extends InfiniteWakelockIntentService {
private TextToSpeechHelper helper;
public TextToSpeechService() {
super("Announcify - Text-To-Speech");
@TomTasche
TomTasche / InfiniteWakelockIntentService.java
Created April 24, 2012 08:21
Mix of IntentService and WakefulIntentService
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue.IdleHandler;
import android.os.PowerManager;
@TomTasche
TomTasche / cisco_ap_show_rogue.txt
Created November 29, 2011 15:45
List rogue networks of a Cisco Access Point and inspect them in detail.
!taken from http://www.cisco.com/en/US/products/ps6366/products_tech_note09186a0080b40901.shtml
(Cisco Controller) >show rogue ap summary
Rogue on wire Auto-Contain....................... Disabled
Rogue using our SSID Auto-Contain................ Disabled
Valid client on rogue AP Auto-Contain............ Disabled
Rogue AP timeout................................. 1200