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
module EventMachine | |
# A simple iterator for concurrent asynchronous work. | |
# | |
# Unlike ruby's built-in iterators, the end of the current iteration cycle is signaled manually, | |
# instead of happening automatically after the yielded block finishes executing. For example: | |
# | |
# (0..10).each{ |num| } | |
# | |
# becomes: | |
# |
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
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
# minimal async sinatra app | |
# requires ruby 1.9.x | |
require 'sinatra' | |
require 'em-http' | |
require 'em-synchrony' | |
require 'em-synchrony/em-http' | |
require 'rack/fiber_pool' | |
use Rack::FiberPool |
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 "date" | |
require "time" | |
# converts base10 integers into NewBase60 | |
def num_to_sxg(num=nil) | |
sxg = "" | |
vocabulary = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz" | |
return 0 if num.nil? || num.zero? |