This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'eventmachine' | |
require 'em-http' # gem install em-http-request | |
require 'yajl' # gem install yajl-ruby | |
module ChatClient | |
def post_init | |
@name = "anonymous_#{ChatClient.client_num+=1}" | |
@sid = ChatClient.channel.subscribe(method(:send_msg)) | |
@buf = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$_g := neo4j:open('neodb.neo') | |
$bob := g:add-v(g:map('name','Bob')) | |
$john := g:add-v(g:map('name','John')) | |
$alice := g:add-v(g:map('name','Alice')) | |
$e1 := g:add-e($bob,'link',$john) | |
$e2 := g:add-e($john,'link',$alice) | |
$e3 := g:add-e($alice,'link',$bob) | |
$e1/weight := 10 | |
$e2/weight := 1 | |
$e3/weight := 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example for multi-fiber workers | |
require "fiber" | |
require "eventmachine" | |
results = [] | |
work = [:a, :b, :c] | |
EventMachine.run { | |
Fiber.new do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
require 'rubygems' | |
require 'collectd/pkt' | |
class Stats | |
def initialize name, instance, opts = {} | |
@name, @instance = name, instance | |
@sock = UDPSocket.new | |
@sock.connect opts[:host] || '239.192.74.66', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Pieter Noordhuis | |
# Description: Simple demo to showcase Redis PubSub with EventMachine | |
# | |
# Requirements: | |
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby | |
# - a browser with WebSocket support | |
# | |
# Usage: | |
# ruby redis_pubsub_demo.rb | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FiberedMutex | |
# | |
# Creates a new FiberedMutex | |
# | |
def initialize | |
@waiting = [] | |
@locked = false | |
end | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This example shows how to setup an environment running Rails 3 beta under 1.9.2-head with a 'rails3' gem set. | |
∴ rvm update --head | |
# ((Open a new shell)) or do 'rvm reload' | |
# If you do not already have the ruby interpreter installed, install it: | |
∴ rvm install 1.9.2-head | |
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist. | |
∴ rvm --create use 1.9.2-head@rails3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# java -cp zookeeper-3.3.0.jar:log4j-1.2.15.jar:conf org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg | |
### Basics: creating & deleting nodes | |
jruby-1.4.0 > require 'zookeeper' | |
jruby-1.4.0 > @zk = ZooKeeper.new(:host => "localhost:2181", :watcher => SilentWatcher.new) | |
=> #<ZooKeeper:0x175b28d8> | |
jruby-1.4.0 > @zk.exists("/test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'digest/md5' | |
require 'fastercsv' | |
require 'json' | |
require 'curb' | |
require 'pp' | |
data = [] |