Skip to content

Instantly share code, notes, and snippets.

View andrewvc's full-sized avatar

Andrew Cholakian andrewvc

View GitHub Profile
@andrewvc
andrewvc / routing_singleton.rb
Created October 31, 2010 05:52
How I implemented routing in DripDrop
# From: http://github.com/andrewvc/dripdrop/blob/master/lib/dripdrop/node.rb
# Defines a new route. Routes are the recommended way to instantiate
# handlers. For example:
#
# route :stats_pub, :zmq_publish, 'tcp://127.0.0.1:2200', :bind
# route :stats_sub, :zmq_subscribe, stats_pub.address, :connect
def route(name,handler_type,*handler_args)
handler = self.send(handler_type, *handler_args)
@routing[name] = handler
@andrewvc
andrewvc / funkyclosure.js
Created November 3, 2010 01:13
from node-streamlogger.js
for (var logLevel in this.levelList) {
this[logLevel] = (function(logLevel) {
return function (message,callback) {
this.logAtLevel(message, this.levelList[logLevel], callback);
}
})(logLevel);
}
});
require 'rubygems'
require 'ffi-rzmq'
ctx = ZMQ::Context.new 1
sock = ctx.socket(ZMQ::SUB)
sock.setsockopt(ZMQ::SUBSCRIBE, '')
pub = ctx.socket(ZMQ::PUB)
pub.connect 'tcp://127.0.0.1:2200'
# Rails.root/config.ru
require "config/environment"
require 'resque/server'
use Rails::Rack::LogTailer
use Rails::Rack::Static
# Set the AUTH env variable to your basic auth password to protect Resque.
AUTH_PASSWORD = ENV['AUTH']
if AUTH_PASSWORD
@andrewvc
andrewvc / rails_server.rb
Created November 30, 2010 23:45
A better script/server
#!/usr/bin/env ruby
exec *(%w(bundle exec unicorn config.ru -p 3000) + ARGV)
#Yeah, I know, I should probably use /bin/sh, but I don't need that extra 10ms in speed...
server {
listen 80;
server_name dev.cocodot.com;
access_log /var/log/dev.cocodot.com
location ~* ^/(stylesheets|javascripts|images)/.*$ {
root /vagrant/public;
}
require 'rubygems'
require 'ffi-rzmq'
require 'eventmachine'
module EM::ZMQ
def initialize(socket)
@socket = socket
//In public/javascripts/bike_shed.js
function($) {
function adjustHandlerbar() { //Private function
};
//coco is the global namespace, all functions should reside in a camel cased version of the JS filename
coco.bikeShed = {
cleanBike: function() { //Public Function
};
}
@andrewvc
andrewvc / fork_test.txt
Created January 2, 2011 17:45
how fork really works
#See which number the fork(2) system call actually is
$ grep fork /usr/include/asm/unistd_64.h
#define __NR_fork 57
__SYSCALL(__NR_fork, stub_fork)
#define __NR_vfork 58
__SYSCALL(__NR_vfork, stub_vfork)
#strace shows us that fork is indeed not seen anywhere, just as man 2 fork said
$ strace -f ruby -e 'fork' 2>&1 | egrep -A1 '^(fork|clone)'
clone(Process 4281 attached
---------------------------------------------------------
| Client(Browser) |
---------------------------------------------------------
| |
websocket control raw tcp stream(EM::bind_connect)
| |
----------------------------------------------------------
| ClientManager(DripDrop) |
----------------------------------------------------------