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" |
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
# Sinatra: multiple route patterns / same action | |
['/foo', '/bar'].each do |pattern| | |
get pattern 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 'sinatra' | |
require 'compass' | |
require 'ostruct' | |
enable :static, :logging | |
set :views, "#{root}/app/views" | |
set :haml, :format => :html4, :attr_wrapper => '"' | |
set :sass, :style => :compact |
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 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 |
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
# 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 |
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
# ~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 |
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 '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 = { |
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/base' | |
require 'eventmachine' | |
require 'thin' | |
EventMachine.run do | |
class Dude < Sinatra::Base | |
get '/' do | |
'oh hai' | |
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
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 |
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
set :uid => "123" | |
set :token => "kljkl26adFGGHHklfha77676sdHHTYklfj" | |
use OmniAuth::Builder do | |
provider :twitter, 'XXX', 'XXXX' | |
end | |
helpers do | |
def admin? | |
session[ settings.uid ] == settings.token |
OlderNewer