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