Skip to content

Instantly share code, notes, and snippets.


Jason Tomlins tomlins

View GitHub Profile
tomlins /
Created Jun 4, 2014
Guess The Number - My first proper Python program as I learn the language. If any Python experts can offer a refactored version, that would be great.
import random
print ("A Simple find the number game.")
score_table = {}
def get_high_scores():
high_score = 0
high_score_holder = None
tomlins /
Last active Aug 29, 2015
Simple usage of Lambda expression with an in-class defined functional interface
package lambdaCalculator;
* @author @ectomorph
public class LambdaCalculator {
// In-class defined interface
tomlins /
Last active Aug 29, 2015
The following code examples demonstrate where and how to use nested classes in your interfaces. It may look a bit strange at first, an interface with a nested class but after following the examples below it should make sense and you'll see how it fits together. The main thing to come away with is that the interface strictly types the classes tha…
import java.util.*;
public interface Input {
public class KeyEvent {
public static final int KEY_DOWN = 0;
public static final int KEY_UP = 1;
public int type;
public int keyCode;
public char keyChar;
tomlins /
Last active Dec 29, 2015
An example of using an Enum class as a Singleton
// Using an Enum as a Singleton
public enum TestDAO {
// Our one and only instance
private DataSource dataSource = new DataSource();
// private constructor to prevent any instantiations
tomlins /
Last active Dec 28, 2015
An example of creating a JSON string representation of an object with a nested object using the Gson library from Google. You will need to add the google-gson library as a dependency. Available here ->
package net.tomlins.testapplication.json;
public class JavaObjToGSONStringExample {
public static void main(String... args) {
JavaObjToGSONStringExample app = new JavaObjToGSONStringExample();
tomlins /
Last active Dec 28, 2015
A simple JSON reader I use for Android that reads a stream from a given URL and returns a org.json.JSONObject. You can optionally provide time-out values for socket and connection. Returns null if unsuccessful. You can remove the Android logging to use this elsewhere.
package net.tomlins.testapplication.json;
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
You can’t perform that action at this time.