Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Tomlins tomlins

View GitHub Profile
@tomlins
tomlins / number_guess.py
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.
View number_guess.py
#!/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
@tomlins
tomlins / LambdaCalculator.java
Last active Aug 29, 2015
Simple usage of Lambda expression with an in-class defined functional interface
View LambdaCalculator.java
package lambdaCalculator;
/**
*
* @author @ectomorph
*/
public class LambdaCalculator {
// In-class defined interface
@FunctionalInterface
@tomlins
tomlins / Input.java
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…
View Input.java
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 / EnumSingletonExample.java
Last active Dec 29, 2015
An example of using an Enum class as a Singleton
View EnumSingletonExample.java
// 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 / JavaToGSONExample.java
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 -> https://code.google.com/p/google-gson/
View JavaToGSONExample.java
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 / JSONHelper.java
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.
View JSONHelper.java
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.