Skip to content

Instantly share code, notes, and snippets.

View tlivings's full-sized avatar

Trevor Livingston tlivings

View GitHub Profile
function mergePartials(partials) {
const types = [];
const resolvers = [];
for (const partial of partials) {
resolvers.push(partial.resolvers);
Array.isArray(partial.types) ? types.push(...partial.types) : types.push(partial.types);
}
addEmptyRootTypes(types, resolvers);
@tlivings
tlivings / domain.js
Created February 1, 2017 22:31
Stateful domain thing for maintaining context across async calls
'use strict';
const Domain = require('domain');
const create = function (initialState = {}) {
const domain = Domain.create();
domain.state = initialState;
const enter = domain.enter;
@tlivings
tlivings / example.js
Last active April 18, 2016 16:05
RxJS based web server basics
const server = new RxServer(Http.createServer(), 3000);
server.flatMap(
//Read request content
({ request, response }) => {
return request.toArray().map((body) => {
request.payload = Buffer.concat(body);
return {request, response};
});
}
@tlivings
tlivings / command.sh
Created October 20, 2015 02:15
Testing connect time
wrk -c 30 -d 30s -t 30 http://127.0.0.1:8888
@tlivings
tlivings / example.js
Last active January 30, 2016 00:28
RxJS Observable from Object.observe
let obj = {
value: 1
};
Rx.Observable.fromObserving(obj).filter((change) => change.name === 'value').doOnNext((x) => console.log(x)).subscribe();
obj.value = 2;
@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 / 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 / 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 / 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 / trie.js
Created October 9, 2014 02:02
trie
'use strict';
function Trie() {
this.children = {};
}
Trie.prototype = {
search: function (str) {
var current = this;