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 / 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 / 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 / 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 / results.md
Last active December 30, 2015 12:59
Node.js outbound SSL testing

Overview

Testing out fedor's SSL enhancements. You don't notice the difference... At first!

Once you adjust ciphers to disable ECDH, then you get the nice surprise.

Test Description

Running an http server that acts as a proxy to an SSL server, all running on localhost.

@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);
@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 / 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 / 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 = {