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 MockSocket | |
def self.pipe | |
socket1, socket2 = new, new | |
socket1.in, socket2.out = IO.pipe | |
socket2.in, socket1.out = IO.pipe | |
[socket1, socket2] | |
end | |
attr_accessor :in, :out | |
def gets() @in.gets 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 'sinatra' | |
enable :sessions | |
before do | |
session[:mine] ||= 0 | |
end | |
get '/foo' do | |
(session[:mine] += 1).to_s |
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
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb | |
index 1d0cbe6..46d9d7b 100644 | |
--- a/lib/sinatra/base.rb | |
+++ b/lib/sinatra/base.rb | |
@@ -49,7 +49,7 @@ module Sinatra | |
else | |
body = @body || [] | |
body = [body] if body.respond_to? :to_str | |
- if header["Content-Length"].nil? && body.respond_to?(:to_ary) | |
+ if body.respond_to?(:to_ary) |
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
# Deploying a Sinatra app to Heroku | |
## Database | |
The location of the database Heroku provides can be found in the environment | |
variable DATABASE_URL. Check the configure-block of toodeloo.rb for an example | |
on how to use this. | |
## Server | |
Heroku is serving your apps with thin, with means you have all your thin goodness available, | |
such as EventMachine. |
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
If only one of the text fields are filled in the params will look like this: | |
{"foo" => "bar"} | |
While it looks like this if both are filled in: | |
{"foo" => ["bar", "baz"]} | |
And really, in the first case it *should* be: | |
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
In 1.8 proc == lambda && proc != Proc.new | |
In 1.9 proc == Proc.new && proc != lambda |
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' | |
class Foo < Sinatra::Base | |
get '/' do | |
"Hello, world!" | |
end | |
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' | |
get '/' do | |
@files = Dir['public/*'].map {|f| File.basename(f) } | |
erb :index | |
end | |
post '/upload' do | |
filename = params[:file][:filename] |
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
1. I copy http://github.com/ichverstehe/foo/commit/17a5a5d55cb28ea1440be1f704497a588694aab3 | |
2. In jello.rb L17 pasteboard.gets sets @current = http://github.com/ichverstehe/foo/commit/17a5a5d55cb28ea1440be1f704497a588694aab3 | |
3. I have shortener enabled, so after all moulds have been ran, the pasteboard now contains http://tr.im/f7v7?github | |
4. The loop is repeated, and at jello.rb L17 pasteboard.gets sets @last to @current, which is still the original github-url, and thus pasteboard.gets (which is http://tr.im/..) != @last and the moulds are walked through once more. | |
On the other hand, if Pasteboard#puts updates @current (which is logically correct, as the current pasteboard *is* whatever #puts sets it to) each copy will only get one time through the moulds. | |
Doesn't matter much, except, for my Growl mould, where I really prefer only getting one notification :) |
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 "sinatrarb.com" | |
accept :xml | |
provides :xml | |
get '/' do | |
"Welcome!" | |
end | |
get '/' do | |
"You are not to be welcomed!" | |
end |