Skip to content

Instantly share code, notes, and snippets.

View sansmischevia's full-sized avatar

Bryant Chou sansmischevia

  • Webflow
  • San Francisco, CA
View GitHub Profile
@sansmischevia
sansmischevia / cluster.js
Created April 3, 2013 07:26
basic cluster bootloader
var cluster = require('cluster'),
os = require('os'),
http = require('http');
// List of 'active' workers:
var workers = [];
var start_count = 0;
// The amount of time we wait before killing a process during a reload:
@sansmischevia
sansmischevia / post-commit
Created March 15, 2013 20:03
@raydog's awesome post commit hook that takes a picture after every commit
#!/bin/sh
dest="$HOME/git-commit-snapshots/"
mkdir -p $dest
path=$dest/`date +%s`.jpg
imagesnap -w 1 -q $path &
@sansmischevia
sansmischevia / mockDynamo.js
Created January 8, 2013 20:49
A mock dynamo client that helps unit testing.
var DATABASE = {};
/**
* Start awk-sdk mock
*/
exports.getItem = function(params, cb) {
if (params.AttributesToGet) {
var ret = {
Item: {}
};
@sansmischevia
sansmischevia / .vimrc
Created December 16, 2011 09:23
.vimrc modified from niw
" .vimrc
" http://github.com/niw/profiles
"{{{ Initialize
if !exists('s:loaded_vimrc')
" Don't reset twice on reloading, 'compatible' has many side effects.
set nocompatible
endif
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
@sansmischevia
sansmischevia / cluster.js
Last active August 29, 2015 14:26
Cluster script that I wrote for both Vungle and Webflow to cluster node apps. This code is running on hundreds of nodes with no issues. Supports worker disconnect timeout and a daily process restart as well.
var cluster = require('cluster');
var os = require('os');
var http = require('http');
var workers = [];
var startCount = 0;
var TIMEOUT = 10000; // Wait 10 seconds for workers to disconnect
var RESTART = 86400000; // 24 hours
var intervalId;
var self = <My Model>;
var stripeOpts = {
description: self.getStripeDescription(subject),
email: self.email,
metadata: self.generateStripeMetadata(subject),
// acct_ ...
stripe_account: subject.managedAccountId
};
@sansmischevia
sansmischevia / nginx.elb.conf
Last active August 29, 2015 14:25
Safe ELB proxy_pass with nginx
location / {
set $backend "<ELB_A_RECORD?";
proxy_pass http://$backend$uri;
...
}
@sansmischevia
sansmischevia / gist:0ad030880fdf7bbda284
Created January 20, 2015 00:28
/Library/Ruby/Gems/2.0.0/gems/
/Library/Ruby/Gems/2.0.0/gems ᐅ ll
total 0
drwxr-xr-x 10 bryantchou1 wheel 340B Jan 19 14:53 builder-3.2.2
drwxr-xr-x 11 root wheel 374B Jan 19 16:25 chef-12.0.3
drwxr-xr-x 8 bryantchou1 wheel 272B Jan 19 14:49 chef-zero-3.2.1
drwxr-xr-x 7 bryantchou1 wheel 238B Jan 19 14:49 coderay-1.1.0
drwxr-xr-x 19 bryantchou1 wheel 646B Jan 19 14:49 diff-lcs-1.2.5
drwxr-xr-x 14 bryantchou1 wheel 476B Jan 19 14:49 erubis-2.7.0
drwxr-xr-x 15 bryantchou1 wheel 510B Jan 19 14:53 excon-0.43.0
drwxr-xr-x 12 bryantchou1 wheel 408B Jan 19 14:49 ffi-1.9.6
var ObjectID = require('mongodb').ObjectID;
var configHelper = /* redacted */;
var config = require('config');
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var lib = /* redacted */;
// Map of database connection keyed by collection's tenantId
var databaseConnectionMap = {};