Skip to content

Instantly share code, notes, and snippets.

View igrigorik's full-sized avatar
:octocat:

Ilya Grigorik igrigorik

:octocat:
View GitHub Profile
# 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
#
@igrigorik
igrigorik / stats.rb
Created March 25, 2010 04:37 — forked from tmm1/stats.rb
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',
#!/bin/bash
# domainavailable
# Fast, domain name checker to use from the shell
# Use globs for real fun:
# domainavailable blah{1..3}.{com,net,org,co.uk}
# Inspired by foca / giles:
# http://gilesbowkett.blogspot.com/2009/02/simple-bash-domain-availability.html
trap 'exit 1' INT TERM EXIT
$_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
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 = ''
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:
#
# gem install em-proxy
require 'rubygems'
require 'em-proxy'
APP_ROOT = File.expand_path(ARGV[0])
module Unicorn

Rails 2.3.5 on App Engine (TinyDS)

Recently, Takeru Sasaki was able to patch the Rails 2.3.5 calls to rubygems, and now we have it working on App Engine. He also created a datastore adapter called TinyDS. I just created an integration plugin called Rails_TinyDS that provides certain ActiveRecord method calls for Rails 2.3.5 generated scaffold.

See the DataMapper version also: gist.github.com/268192

Install the Development Environment

The gems for the development environment include a pre-release appengine-tools gem that provides a pre-release version of jruby-rack.

sudo gem install google-appengine
@igrigorik
igrigorik / url_dsl.rb
Created December 26, 2009 23:23 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@igrigorik
igrigorik / gist:262924
Created December 24, 2009 00:09 — forked from penso/gist:262598
WORKING With Net:Http :
def twitter_oauth_consumer
@consumer ||= OAuth::Consumer.new(APP_CONFIG['twitter_consumer_key'],APP_CONFIG['twitter_consumer_secret'],{ :site=>"http://twitter.com" })
@consumer
end
def twitter_oauth_token
@token ||= OAuth::AccessToken.new(self.twitter_oauth_consumer, oauth_token, oauth_secret)
@token