Skip to content

Instantly share code, notes, and snippets.

View vangberg's full-sized avatar

Harry Vangberg vangberg

View GitHub Profile
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
require 'sinatra'
enable :sessions
before do
session[:mine] ||= 0
end
get '/foo' do
(session[:mine] += 1).to_s
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)
@vangberg
vangberg / README
Created February 22, 2009 01:06
Deploying a Sinatra app to Heroku
# 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.
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:
@vangberg
vangberg / README
Created February 18, 2009 10:32
lambda v proc v Proc.new
In 1.8 proc == lambda && proc != Proc.new
In 1.9 proc == Proc.new && proc != lambda
require 'sinatra'
class Foo < Sinatra::Base
get '/' do
"Hello, world!"
end
end
@vangberg
vangberg / app.rb
Created February 8, 2009 14:34
file upload w/ sinatra
require 'rubygems'
require 'sinatra'
get '/' do
@files = Dir['public/*'].map {|f| File.basename(f) }
erb :index
end
post '/upload' do
filename = params[:file][:filename]
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 :)
@vangberg
vangberg / base.rb
Created January 30, 2009 01:57 — forked from bmizerany/base.rb
host "sinatrarb.com"
accept :xml
provides :xml
get '/' do
"Welcome!"
end
get '/' do
"You are not to be welcomed!"
end