Skip to content

Instantly share code, notes, and snippets.

View include's full-sized avatar
👽
Free Jaffa

Francisco Cabrita include

👽
Free Jaffa
View GitHub Profile
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"
# Sinatra: multiple route patterns / same action
['/foo', '/bar'].each do |pattern|
get pattern do
"Hello World!"
end
end
require 'sinatra'
require 'compass'
require 'ostruct'
enable :static, :logging
set :views, "#{root}/app/views"
set :haml, :format => :html4, :attr_wrapper => '"'
set :sass, :style => :compact
class CachePolicy < Sinatra::Base
# always forward the request downstream immediately (before processing routes)
before { forward }
# anything with a cache breaking timestamp gets an insanely long max-age
get '/public/*' do
pass unless request.query_string =~ /^\d+$/
response['Cache-Control'] = 'public, max-age=1000000000'
end
# The code in lib/foobar.rb
require 'sinatra/base'
class Foobar < Sinatra::Base
VERSION = '1.0.0'
configure do
set :foobar, environment
end
end
# The tests in test/test_foobar.rb
@rtomayko
rtomayko / .screenrc
Created October 28, 2009 07:42
~rtomayko/.screenrc
# ~rtomayko/.screenrc
# -------------------------------------------------------------------
# Settings
# -------------------------------------------------------------------
crlf off # No Microsoft linebreaks
startup_message off # bypass GPL notice (we're aware)
defscrollback 15000 # big scrollback
shell bash # don't start login shells
shelltitle "" # no title by default - set in PS1
require 'bcrypt'
module EasyAuth
# http://techspeak.plainlystated.com/2010/03/drop-dead-simple-authentication-for.html
# To generate a crypted password (in irb):
# require 'easy_auth'
# EasyAuth.encrypt_password('my_password') # Put returned array in AUTHORIZED_USERS
AUTHORIZED_USERS = {
@kennystone
kennystone / gist:810182
Created February 3, 2011 20:57
em/sinatra example
require 'sinatra/base'
require 'eventmachine'
require 'thin'
EventMachine.run do
class Dude < Sinatra::Base
get '/' do
'oh hai'
end
def run_in_background(&block)
Process.fork do
Process.fork do
puts "Launching Background Process"
Daemons.call &block
puts "Background Process has been Launched"
end
exit
end
end
@daz4126
daz4126 / gist:1106958
Created July 26, 2011 15:03
Ominauth Twitter Login
set :uid => "123"
set :token => "kljkl26adFGGHHklfha77676sdHHTYklfj"
use OmniAuth::Builder do
provider :twitter, 'XXX', 'XXXX'
end
helpers do
def admin?
session[ settings.uid ] == settings.token