Skip to content

Instantly share code, notes, and snippets.

require 'openssl'
require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new()
page = agent.get(:url => "https://www.gmail.com")
#use OpenSSL between mechanize requests.
public_key = OpenSSL::PKey::RSA.new(File.read(File.dirname(__FILE__) + "/mykeypublic.pem"))
private_key = OpenSSL::PKey::RSA.new(File.read(File.dirname(__FILE__) + "/mykey.pem"))
#vlad code, why on earth would you do this...???
def export receiver, *methods
methods.each do |method|
eval "def #{method} *args, █ #{receiver}.#{method}(*args, &block);end"
end
end
export "Thread.current[:task]", :get, :put, :rsync, :run, :sudo, :target_host
class CommentsController < ApplicationController
layout false
def show
headers['Cache-Control'] = 'must-revalidate'
item = Item.find(params[:item_id])
if stale?(:etag => item.comments.count, :public => true)
@comments = item.comments.all(:include => :user)
end
end
class ExamplesController < ApplicationController
def show
data = {:name => "Apple Pie", :price => "3.75"}
render :json => data, :callback => params[:callback]
end
end
class FoosController < ApplicationController
def http
http = EM::HttpRequest.new(params[:url]).get
http.callback {
render :text => http.response
}
end
end
class AccountsController < ApplicationController
before_filter :require_user
def destroy
@account = current_user.accounts.find(params[:id])
@account.destroy
respond_to do |format|
format.html { redirect_to(accounts_url) }
format.xml { head :ok }
end
class ForwardingSupport
def initialize(app)
@app = app
end
def call(env)
async_cb = env['async.callback']
env['async.callback'] = Proc.new do |status, headers, body|
async_cb.call(post_process(env, status, headers, body))
end
<!DOCTYPE html>
<html>
<head>
<title>Craigslist google maps mashup</title>
<script type="text/javascript" src="javascripts/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
$(document).ready(function(){
var latlng = new google.maps.LatLng(-34.397, 150.644);
var reverse_geocoder = new google.maps.Geocoder();
@nolman
nolman / async_io.rb
Created July 7, 2011 05:56
Async IO
require 'rubygems'
require 'eventmachine'
require 'em-http-request'
require 'fiber'
EventMachine.run do
http = EM::HttpRequest.new('http://www.google.com').get
begin
puts "Before"
http.callback {
# Eventually some non deterministic difference of signals received
missed signal @cont_count: 428 @usr2_count: 439