Discover gists
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
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'uri' | |
require 'rubygems' | |
require 'json' | |
require 'pp' | |
if !ARGV[0] | |
puts "Usage: iphone.rb STATE" |
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
Router.prepare do |r| | |
# generating this requires :domain, :controller, and :action | |
r.match("/:domain/complicated/url").to(:controller => "what", :action => "index") | |
# generating this requires :controller and :index | |
r.match("/:controller/:index").to | |
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
Minstrel: 1 | |
Bard: 1 | |
Troubadour: 1 | |
Jongleur: 1 |
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
Router.prepare do |r| | |
r.match("/something", :user_agent => %r[some/complex/regexp/with/parentheses]).to(:browser => ":user_agent[1]") | |
end | |
Router.generate(:browser => "something") | |
# => I can't tell if something is a valid match | |
# from the original :user_agent regex | |
# since we have :browser => "something", and we know that :browser is :user_agent[1], we match "something" against the regex |
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: Dirceu Pereira Tiegs <dirceutiegs@gmail.com> | |
# | |
# Script to roll dices (used to play D&D). Example: | |
# | |
# >> require 'dices' | |
# >> 3.d6 | |
# => 10 | |
# >> 3.d6+7 | |
# => 14 | |
# >> 1.d4+2.d8+1.d12+3 |
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
Router.prepare do |r| | |
r.match("/something", | |
:user_agent => %r[(?:one|two|three)] | |
).to(:controller => "foo", :action => "bar") | |
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
Router.prepare do |r| | |
r.match("/something", | |
:user_agent => %r[(?:one|two|three)] | |
).to(:controller => "foo", :action => "bar") | |
r.match("/something/else", | |
:user_agent => %r[(?:four|five|six)] | |
).to(:controller => "foo", :action => "bar") | |
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
--- | |
host: twitter.com | |
scheme: http | |
auth: httpbasic | |
version: 2008-07-07T00:00:00-0800 | |
parameters: | |
id: | |
type: id | |
required: False | |
id_num: |
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
#include<stdio.h> | |
int main() { | |
printf("Hello World!\n"); | |
} |
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
Router.prepare do |r| | |
r.match(:controller => "users") do | |
r.match("/users/:id", :method => :get).to(:action => "show") | |
r.match("/users/:id", :method => :put).to(:action => "update") | |
end | |
end | |
# Both routes generate the exact same path, so do we just | |
# require the minimum necessary to differentiate them? |