Skip to content

Instantly share code, notes, and snippets.

View tlivings's full-sized avatar

Trevor Livingston tlivings

View GitHub Profile
@tlivings
tlivings / bignums.js
Last active August 29, 2015 14:00
bignum vs bn.js
var anvil = require('anvil'),
bignum = require('bignum'),
bn = require('bn.js');
anvil('Bignum functions', function (forge, hammer) {
var bigBuffer, bigString;
bigBuffer = new Buffer([ 24, 7, 144, 87, 61, 194, 2, 7 ]);
bigString = '1731511286119924231';
@tlivings
tlivings / trie.js
Created October 9, 2014 02:02
trie
'use strict';
function Trie() {
this.children = {};
}
Trie.prototype = {
search: function (str) {
var current = this;
@tlivings
tlivings / keybase.md
Created December 6, 2014 18:45
keybase.md

Keybase proof

I hereby claim:

  • I am tlivings on github.
  • I am tlivings (https://keybase.io/tlivings) on keybase.
  • I have a public key whose fingerprint is E48C BB26 792C 4030 552B 0DC0 CBE2 A2AD E973 A9BD

To claim this, I am signing this object:

@tlivings
tlivings / authenticate.m
Created April 8, 2015 16:00
Authenticate local player
- (void) authenticateLocalPlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated) {
//Maybe do something
}
}];
}
@tlivings
tlivings / params.js
Created April 8, 2015 16:03
Passing parameters to javascript files
var scripts = document.getElementsByTagName('script');
var myScript = scripts[ scripts.length - 1 ];
var queryString = myScript.src.replace(/^[^\?]+\??/,'');
var params = parseQuery( queryString );
function parseQuery ( query ) {
var Params = new Object ();
if ( ! query ) return Params;
// return empty object
@tlivings
tlivings / distance.m
Created April 8, 2015 16:06
Distance from CLLocation
//Uses the haversine formula.
-(double) distanceFromCLLocation:(CLLocation*)location {
double result;
double earthRadius = 3959; //miles
double latDelta = (location.coordinate.latitude - self.latitude.doubleValue) * (M_PI/180);
double lonDelta = (location.coordinate.longitude - self.longitude.doubleValue) * (M_PI/180);
double lat1 = self.latitude.doubleValue * (M_PI/180);
@tlivings
tlivings / zoom.m
Last active September 23, 2015 21:38
Example of zooming to user location in MKMapView when location annotation appears
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views {
for(MKAnnotationView *annotationView in views) {
if(annotationView.annotation == mv.userLocation) {
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.05;
span.longitudeDelta=0.05;
CLLocationCoordinate2D location=mv.userLocation.coordinate;
@tlivings
tlivings / ScriptObjectLoader.java
Created November 21, 2010 16:37
Simplistic utility class loads scripts into Java interfaces
public class ScriptObjectLoader {
public static ScriptEngineManager scriptEngineManager;
public static ScriptEngine engine;
static {
scriptEngineManager = new ScriptEngineManager();
engine = scriptEngineManager.getEngineByName("JavaScript"); //Or whatever
}
@tlivings
tlivings / NSManagedObject+JSON.m
Created May 7, 2011 16:04
Quick and Dirty proxyForJson Implementation on NSManagedObject
@implementation NSManagedObject (NSManagedObject_JSON)
/*
*
* This method is implemented to help NSObject+JSON with transforming to JSON as per SBJSON's JSONValue helper method.
*
*/
-(NSDictionary*) proxyForJson {
NSDictionary * attributes = [[self entity] attributesByName];
NSDictionary * relationships = [[self entity] relationshipsByName];
@tlivings
tlivings / mongoconnection.js
Created January 26, 2012 00:48
Sample MongoDB connection that uses node-mongodb-native and connects with URIs
/*
* Usage example:
* var MongoConnection = require('./mongoconnection').MongoConnection;
* mongo_connection = new MongoConnection(process.env.MONGOHQ_URL);
*
* See also: https://github.com/christkv/node-mongodb-native
*
* Hat tip to: http://howtonode.org/express-mongodb
*/