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
require "rubygems" | |
require "sinatra" | |
get '/' do | |
'hi' | |
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
class Doc | |
def method_missing(m, *args, &block) | |
args.empty? ? options[m] : options[m] = args[0] | |
end | |
def options | |
@options ||= {} | |
end | |
def initialize(&block) | |
self.instance_eval(&block) if block | |
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
helpers do | |
def rest | |
@rest ||= RestClient.new('http://foo.org') | |
end | |
end | |
get '/' do | |
rest.put '/foo' | |
'hey' |
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
# A Sinatra app that does the same thing | |
require 'rubygems' | |
require 'sinatra' | |
set :env, :production | |
get '/' do | |
"x" * (params[:size].to_i * 1024) | |
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
require 'rubygems' | |
require 'sinatra' | |
require 'sinatra/test/unit' | |
require 'app' | |
class MyAppTest < Test::Unit::TestCase | |
def test_hello_world | |
assert_equal :test, Sinatra.application.env | |
get_it '/' | |
assert @response.ok? |
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
require 'resolv' | |
def ips_for(host) | |
Resolv::DNS.open do |dns| | |
ress = dns.getresources(host, Resolv::DNS::Resource::IN::A) | |
ress.map { |r| r.address.to_s } | |
end | |
end | |
puts ips_for('heroku.com').sort.first |
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
class String | |
def space_case | |
gsub(/([a-z]|[A-Z]+)([A-Z])/){ "#{$1} #{$2}" } | |
end | |
def snake_case | |
gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_') | |
end | |
end | |
class Graph |
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
# meh is a rainy day experiment with atom and twitter | |
#---------------------------------------------------- | |
#use latest version of sinatra | |
$:.unshift File.dirname(__FILE__) + '/sinatra/lib' | |
require 'rubygems' | |
require 'sinatra' | |
require 'net/http' | |
require 'uri' |
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
require 'sinatra' | |
require 'thin' | |
require 'lizzy' | |
Thread.new do | |
sleep(1) until EM.reactor_running? | |
Lizzy.start | |
end | |
post "/some/url/:id" do |
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
class App1 < Sinatra::Base | |
set :views, "/path/to/views" | |
set :public, "/path/to/static/files" | |
def strong(text) | |
"<strong>#{text}</strong>" | |
end | |
get '/' do | |
strong "Hello World" |
OlderNewer