Skip to content

Instantly share code, notes, and snippets.

// Create a thread pool
private ExecutorService mThreadPool = Executors.newSingleThreadExecutor();
// Execute a new Runnable on a background Thread
Future f = pool.submit(new Runnable() {
public void run() {
while (true) {
// We're running!
Log.d(TAG, ".");
@twaddington
twaddington / rename.sh
Created August 31, 2012 20:02
Rename Android Action Bar Icons
#!/bin/bash
for i in *.png ; do
mv "$i" "ic_menu_${i##*[0-9]_}";
done
// List all security providers
for (Provider p : Security.getProviders()) {
Log.d(TAG, String.format("== %s ==", p.getName()));
for (Provider.Service s : p.getServices()) {
Log.d(TAG, String.format("- %s", s.getAlgorithm()));
}
}
package com.geoloqi.android.sdk.util;
import java.util.Random;
/**
* <p>This class will efficiently generate insecure random
* alpha-numeric Strings.</p>
*
* <p>Source largely based on
* <a href="http://stackoverflow.com/a/41156/772122">this example</a>
@twaddington
twaddington / udp-client.py
Created June 15, 2012 01:14
Geoloqi Python UDP Client Demo
#!/usr/bin/python
"""
A Geoloqi socket client demo.
:author: Tristan Waddington
"""
import sys
import time
import socket
@twaddington
twaddington / Timer.java
Created May 8, 2012 07:07
Simple Java Timer class.
package com.geoloqi.android.sdk.util;
import java.util.concurrent.TimeUnit;
/**
* A simple class for timing short lived events.
*
* @author Tristan Waddington
*/
public class Timer {
public classd MyActivity extends Activity implements OnClickListener {
private LQService mService;
private boolean mBound;
private SampleReceiver mLocationReceiver = new SampleReceiver();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
LQSession session = mService.getSession();
// Get the current user's profile
session.runGetRequest("account/profile", new OnRunApiRequestListener() {
@Override
public void onSuccess(LQSession session, HttpResponse response) {
// Consume the response!
// ...
JSONObject json = new JSONObject(EntityUtils.toString(response.getEntity()));
}
time = "10 minutes ago"
if ((distance_moved *since* time) < 200):
# Possibly return a 420 or 429 response code? Possibly not a 429,
# since we might want to use that for actual API request rate limiting.
#
# http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#420
response = {
"error": "back_off",
"error_message": "...",
"latitude": 125.45,
# Loop over each object and either update or create.
try:
obj = MyObject.objects.get(pk=id)
obj.value1 = 1
obj.value2 = 2
except MyObject.DoesNotExist:
obj = MyObject(value1=1, value2=2, ...)
# Update the object