Skip to content

Instantly share code, notes, and snippets.

@zh
zh / gist:1496003
Created December 19, 2011 08:00 — forked from danbri/gist:1486527
// Basic XMPP bot example for HipChat using node.js
// To use:
// 1. Set config variables
// 2. Run `node notube_bot.js`
// 3. Send a message like "!weather 94085" in the room with the bot
// based on https://raw.github.com/gist/940969/413b5601292df26e06f325cbd6e3944a728fb590/hipchat_bot.js
var request = require('request'); // github.com/mikeal/request
var sys = require('sys');
@zh
zh / rbenv-install-system-wide.sh
Created December 15, 2011 07:21
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
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
@zh
zh / samples.rb
Created December 10, 2011 03:00
Some good Ruby syntax examples
w = %w[a c d b e]
w.sort #=> ["a", "b", "c", "d", "e"]
w.sort.reverse #=> ["e", "d", "c", "b", "a"]
w.sort { |a,b| b<=>a } #=> ["e", "d", "c", "b", "a"]
w.reduce(&:+) #=> "acdbe"
w.map(&:upcase) #=> ["A", "C", "D", "B", "E"]
w.include? "a" #=> true
w.member? "a" #=> true
@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
@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 <[email protected]>
#
unless `rvm-prompt i g`.chomp == "ree@xmpp"
exec("rvm ree@xmpp ruby #{$0}")
end
@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 / 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
/* 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 / 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) || /^\{(.+?)\}/
@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 =