Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'rubygems'
require 'json'
require 'pp'
if !ARGV[0]
puts "Usage: iphone.rb STATE"
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
Minstrel: 1
Bard: 1
Troubadour: 1
Jongleur: 1
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
# 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
Router.prepare do |r|
r.match("/something",
:user_agent => %r[(?:one|two|three)]
).to(:controller => "foo", :action => "bar")
end
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
@codeslinger
codeslinger / gist:1513
Created July 23, 2008 03:42
YAML layout of Twitter API
---
host: twitter.com
scheme: http
auth: httpbasic
version: 2008-07-07T00:00:00-0800
parameters:
id:
type: id
required: False
id_num:
@jaguarjaws
jaguarjaws / HelloWorld
Created July 23, 2008 03:48
Simple C Hello World
#include<stdio.h>
int main() {
printf("Hello World!\n");
}
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?