Skip to content

Instantly share code, notes, and snippets.

View tomlins's full-sized avatar

Jason Tomlins tomlins

View GitHub Profile
@tomlins
tomlins / JSONHelper.java
Last active December 28, 2015 09:09
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;
@tomlins
tomlins / JavaToGSONExample.java
Last active December 28, 2015 09:19
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 -> https://code.google.com/p/google-gson/
package net.tomlins.testapplication.json;
import com.google.gson.*;
public class JavaObjToGSONStringExample {
public static void main(String... args) {
JavaObjToGSONStringExample app = new JavaObjToGSONStringExample();
System.out.println(app.toGSONStringExample());
@tomlins
tomlins / EnumSingletonExample.java
Last active December 29, 2015 12:29
An example of using an Enum class as a Singleton
// Using an Enum as a Singleton
//
public enum TestDAO {
// Our one and only instance
instance;
private DataSource dataSource = new DataSource();
// private constructor to prevent any instantiations
@tomlins
tomlins / Input.java
Last active August 29, 2015 14:00
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
tomlins / LambdaCalculator.java
Last active August 29, 2015 14:00
Simple usage of Lambda expression with an in-class defined functional interface
package lambdaCalculator;
/**
*
* @author @ectomorph
*/
public class LambdaCalculator {
// In-class defined interface
@FunctionalInterface
@tomlins
tomlins / number_guess.py
Created June 4, 2014 00:08
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.
#!/usr/bin/python
import random
print ("A Simple find the number game.")
score_table = {}
def get_high_scores():
high_score = 0
high_score_holder = None