Skip to content

Instantly share code, notes, and snippets.

@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 {
@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
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>
// 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()));
}
}
@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
// 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 / TypefaceTextView.java
Last active March 31, 2020 15:48
An Android TextView with support for custom typefaces.
/*
* TypefaceTextView.java
* Simple
*
* Copyright 2012 Simple Finance Corporation (https://www.simple.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
// We imply that we expect a JSON response by using the SFJsonRequestHandler...
Future f = client.getPath("/foo/bar", new SFJsonRequesthandler() {
@Override
public void onStart() {
// Pass
}
@Override
public void onFinish() {
// Pass
}

Supported sizes

Camera.Parameters params = mCamera.getParameters();

Log.d(TAG, "Supported sizes:");
List<Camera.Size> sizes = params.getSupportedPictureSizes();
for (Camera.Size s : sizes) {
    Log.d(TAG, String.format("  %s x %s", s.width, s.height));
}
/**
* Instances of this class can be used to safely retain references to
* <code>View</code> objects.
*
* <p>
* Prior to Android 4.0 storing a <code>View</code> as a tag with the
* {@link View#setTag(int, Object)} method could <a
* href="http://code.google.com/p/android/issues/detail?id=18273">result in
* memory leaks</a>. Instead, the {@link View#setTag(Object)} method should be
* used with a <code>ViewHolder</code> instance as the object.