Skip to content

Instantly share code, notes, and snippets.

View tlivings's full-sized avatar

Trevor Livingston tlivings

View GitHub Profile
@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
*/
@tlivings
tlivings / bookmarklet.js
Created December 31, 2012 22:30
Boilerplate Bookmarklet
(function() {
try {
var s = d.createElement("script");
s.setAttribute("type","text/javascript");
s.setAttribute("src","http://<myhost>/<myscript>.js?t="+(new Date().getTime()));
b.appendChild(s);
}
catch(e) {
alert(e);
}
@tlivings
tlivings / extend.js
Last active December 18, 2015 07:09
Javascript extend utility function.
/**
* Extend an Object from another Object.
* @param child
* @param parent
* @param proto - prototype mixins
* @returns {*}
*/
function(child, parent, proto) {
//Constructor
var properties = {
@tlivings
tlivings / promisify.js
Created June 12, 2013 15:30
Object promisification. Playing with method mixin to build chain of callbacks and flatten. Not real promises yet.
function Promisify(obj) {
var original = Object.getPrototypeOf(obj);
var Promise = function Promise() {
this._chain = [];
};
Promise.prototype = Object.create(Promise, {
constructor : {
@tlivings
tlivings / test-resume.js
Last active December 24, 2015 06:49
Example of the undocumented reuse of an SSL session in Node.js. This is a very simplistic example, but demonstrates the undocumented option for 'session' on a client connection.
'use strict';
var assert = require('assert');
var https = require('https'),
fs = require('fs');
describe('SSL Connection', function () {
var server, server_options;
@tlivings
tlivings / TestServer.java
Created October 10, 2013 00:58
Simple Jetty Test Server with SSL.
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;
public class TestServer {
public static void main(String[] args) throws Exception {
@tlivings
tlivings / attempt.js
Last active December 27, 2015 15:39
Try catch utility so optimization still occurs in the calling function. lol?
'use strict';
function attempt(fn) {
return Object.create({
'fail': function (onError) {
try {
fn();
}
catch (e) {
return onError(e);