Skip to content

Instantly share code, notes, and snippets.


Nick DeLuca nddeluca

View GitHub Profile
bradwright / websockets-server.js
Created Jun 11, 2011
Pure Node.js WebSockets server
View websockets-server.js
* node-ws - pure Javascript WebSockets server
* Copyright Bradley Wright <>
// Use strict compilation rules - we're not animals
'use strict';
var net = require('net'),
crypto = require('crypto');
klovadis / gist:2549131
Created Apr 29, 2012
How to use optional arguments in node.js
View gist:2549131
// example function where arguments 2 and 3 are optional
function example( err, optionalA, optionalB, callback ) {
// retrieve arguments as array
var args = [];
for (var i = 0; i < arguments.length; i++) {
// first argument is the error object
cee-dub / postgres_timestamp_defaults.rb
Created Jan 29, 2012
Convenient methods to let PostgresQL manage created/updated_at
View postgres_timestamp_defaults.rb
require 'active_support/core_ext/string/filters'
module PostgresTimestampDefaults
def add_timestamp_defaults(table_name)
add_default_now(table_name, :created_at)
add_default_now(table_name, :updated_at)
def add_default_now(table_name, column_name)
View gist:8393897
Ruby 2.1.0 in Production: known bugs and patches
Last week, we upgraded the rails app to ruby 2.1.0 in production.
While testing the new build for rollout, we ran into a number of bugs. Most of
these have been fixed on trunk already, but I've documented them below to help
anyone else who might be testing ruby 2.1 in production.
@naruse I think we should backport these patches to the ruby_2_1 branch and
release 2.1.1 sooner rather than later, as some of the bugs are quite critical.
I'm happy to offer any assistance I can to expedite this process.
shapeshed / unicorn
Created Sep 16, 2011
Unicorn / Monit setup
View unicorn
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
shilov / redis_json_marshal_eval_benchmarks.rb
Created Jan 27, 2012
Ruby Redis benchmarks for JSON vs Marshal vs String
View redis_json_marshal_eval_benchmarks.rb
require 'benchmark'
require 'json'
require 'redis'
# -----------------
puts "Initialize variables.."
timruffles / hash_converter.rb
Created May 24, 2012
rails hash formatter - hash/json to/from camel case and underscores
View hash_converter.rb
module HashConverter
class << self
def to_underscore hash
convert hash, :underscore
def to_camel_case hash
convert hash, :camelize, :lower
def convert obj, *method
case obj
hotchpotch / unicorn_killer.rb
Created Oct 3, 2011
Unicorn process killer utility
View unicorn_killer.rb
# # your
# require 'unicorn_killer'
# use UnicornKiller::MaxRequests, 1000
# use UnicornKiller::Oom, 400 * 1024
module UnicornKiller
module Kill
def quit
sec = ( - @process_start).to_i
warn "#{self.class} send SIGQUIT (pid: #{})\talive: #{sec} sec"
PatrickJS / api.service.ts
Last active Sep 18, 2017
Universal Cache
View api.service.ts
// Something like this. I haven't tested this file
export class ApiService {
constructor(public _http: Http, public _cache: Cache) {
// whatever domain/feature method name
getModel(url) {
// you want to return the cache if there is a response in it. This would cache the first response so if your API isn't idempotent you probably want to remove the item from the cache after you use it. LRU of 1
klovadis / gist:2549029
Created Apr 29, 2012
Short circuit function chains if an error occurs
View gist:2549029
var fs = require('fs');
// read a file
function read_the_file(filename, callback) {
// begin by reading a file
fs.readFile(filename, function (err, contents) {
// an error occurred, i.e. the file was not found.
// instead of throwing an error, skip the other