Skip to content

Instantly share code, notes, and snippets.

@zh
zh / gist:584260
Created September 17, 2010 13:50
**Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance.
You can install the extension as follows:
gem install bson_ext
If you continue to receive this message after installing, make sure that the
bson_ext gem is in your load path and that the bson_ext and mongo gems are of the same version.
require 'mechanize'
require 'singleton'
BASE = 'http://goo.gl/'.freeze
REDIR = "#{BASE}?authen=1".freeze
NOISE = "#{BASE}?url=".freeze
class GooAPI
include Singleton
// 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.coffee
Created January 21, 2011 09:16
Socket.IO example chat, converted to CoffeeScript
http = require('http')
url = require('url')
fs = require('fs')
io = require('../')
sys = require(if process.binding('natives').util then 'util' else 'sys')
server = http.createServer (req, res) ->
path = url.parse(req.url).pathname
switch path
when "/"
@zh
zh / em_stream.rb
Created March 18, 2011 03:53
Working with twitter stream (eventmachine)
require 'rubygems'
require 'em-http'
require 'json'
EM.run {
username = 'tw_user'
password = 'tw_password'
buffer = ""
http = EventMachine::HttpRequest.new('http://stream.twitter.com/1/statuses/filter.json').post({
@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)
});