Skip to content

Instantly share code, notes, and snippets.

// HTTP client for testing high connection concurrency
// Authors: Richard Jones and Rasmus Andersson
// Released in the public domain. No restrictions, no support.
#include <sys/types.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <stdlib.h>
#include <err.h>
#include <event.h>
#include <evhttp.h>
@zh
zh / server.js
Created April 13, 2011 08:16 — forked from sintaxi/server.js
simple reverse proxy with node.js
var http = require("http"),
util = require("util")
http.createServer(function(req, rsp){
var regex = /^\/(v1|v2)/g
var matches = req.url.match(regex)
if((matches && matches[0] === "/v1") || (req.headers["x-api-version"] === "v1"))
var port = 8001
@zh
zh / install.sh
Created May 11, 2011 13:00 — forked from brettbuddin/install.sh
New machine setup. SET IT! AND FORGET IT!
#!/bin/sh
# Usage: bash < <(curl -s https://gist.github.com/raw/965142/install.sh)
# Have sudo ask us for our password before we kick everything off so we can walk away.
sudo echo "Here we go..."
echo "Installing RVM..."
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
source $HOME/.rvm/scripts/rvm
@zh
zh / gist:1028773
Created June 16, 2011 06:17 — forked from carsonmcdonald/gist:911761
node.js SPDY proxy
var tls = require('tls');
var fs = require('fs');
var Buffer = require('buffer').Buffer;
var zlib = require('zlib');
var BufferList = require('bufferlist');
var Binary = require('bufferlist/binary');
var Put = require('put');
var http = require('http');
var options =
@zh
zh / redis-em-patch
Created September 12, 2011 10:07 — forked from gregorymostizky/redis-em-patch
Patch redis and em-redis to work together
require 'em-redis'
require 'redis'
require 'redis/distributed'
require "fiber_pool"
class Redis
class Distributed
def initialize(urls, options = {})
@tag = options.delete(:tag) || /^\{(.+?)\}/
/* Ismael Celis 2010
Simplified WebSocket events dispatcher (no channels, no users)
var socket = new FancyWebSocket();
// bind to server events
socket.bind('some_event', function(data){
alert(data.name + ' says: ' + data.message)
});
@zh
zh / rbenv-install-system-wide.sh
Created October 6, 2011 06:36
rbenv install and system wide install on Ubuntu 10.04 LTS.
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Extras for RubyGems and Rails:
apt-get -y install zlib1g-dev
apt-get -y install libssl-dev libsqlite3-dev
@zh
zh / mongo_pubsub.rb
Created October 19, 2011 06:48 — forked from octplane/mongo_pubsub.rb
Simple Pub/Sub system using MongoDB, capped collections and tailable cursors in ruby
require 'rubygems'
require 'mongo'
module MongoPubSub
QUEUES_COLLECTION = 'queues'
class EndSubscriptionException < Exception; end
class Publisher
def initialize(queue_name, mongo_connection)
# Initialize queue collection as a capped collection
if not mongo_connection[QUEUES_COLLECTION].collection_names.include?(queue_name)
@zh
zh / bot.rb
Created October 26, 2011 07:29 — forked from jpr5/bot.rb
XMPP/Ruby Bot for HipChat
#!/usr/bin/env ruby
#
# Script: HipChat bot in Ruby
# Author: Jordan Ritter <jpr5@darkridge.com>
#
unless `rvm-prompt i g`.chomp == "ree@xmpp"
exec("rvm ree@xmpp ruby #{$0}")
end
@zh
zh / dnsd.rb
Created December 9, 2011 04:42 — forked from peterc/dnsd.rb
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL