Skip to content

Instantly share code, notes, and snippets.

Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@jamiehodge
jamiehodge / gist:1327195
Created October 31, 2011 09:38
Warden and Sinatra example
require 'sinatra/base'
require 'rack/flash'
require 'warden'
require 'slim'
require 'sequel'
require 'sqlite3'
DB = Sequel.sqlite
DB.create_table :users do
primary_key :id
@cadwallion
cadwallion / gist:1409963
Created November 30, 2011 17:41
Writing custom warden strategies
# For more information on Warden strategies, read this: https://github.com/hassox/warden/wiki/Strategies
class SuperCoolWardenStrategy
def valid?
# you have access to env and request
# return true/false if this is strategy should run or not
# if it returns false, it will move onto the next strategy in the list
# defaults to true if you don't write this method
end
def authenticate!
@tansengming
tansengming / configure.rb
Created July 9, 2012 07:37
Ruby configure blocks
# How Clearance / Hoptoad does it
module Clearance
class << self
attr_accessor :configuration
end
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
@shunchu
shunchu / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created July 25, 2012 07:58
Convert seconds into HH:MM:SS in Ruby
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@ziadoz
ziadoz / stripe-checkout.html
Last active November 19, 2022 05:59
Custom Stripe Checkout Button
<form action="." method="post">
<noscript>You must <a href="http://www.enable-javascript.com" target="_blank">enable JavaScript</a> in your web browser in order to pay via Stripe.</noscript>
<input
type="submit"
value="Pay with Card"
data-key="PUBLISHABLE STRIPE KEY"
data-amount="500"
data-currency="cad"
data-name="Example Company Inc"
@mdesantis
mdesantis / schedule.rb
Last active May 28, 2023 16:11
Schedule script for using Whenever toghether with rbenv
# Schedule script for using Whenever toghether with rbenv
#
# Whenever: https://github.com/javan/whenever
# rbenv: https://github.com/sstephenson/rbenv
set :env_path, '"$HOME/.rbenv/shims":"$HOME/.rbenv/bin"'
# doesn't need modifications
# job_type :command, ":task :output"
@sathishmanohar
sathishmanohar / install_passenger_nginx_digital_ocean.sh
Last active June 2, 2020 12:30
Steps to setup and install passenger nginx and rails on digital ocean
# Login as root
ssh root@domain
# Create deploy user
adduser <username> #Adds User with username given. Enter Password when Prompted. Other Details are Optional
# Add user to sudo group
usermod -g <groupname> <username>
# Add .ssh/authorized_keys for deploy user
@davesag
davesag / Example Game server with Sinatra and Event Machine.
Last active August 18, 2020 01:51
This is the shell of my Game server built using Sinatra and EventMachine Websockets. I am trying to extract the cookie information that is passed to the Websocket's `onopen` method via the `handshake.headers['Cookie'], but have been unable to work out how to properly decode the cookie. See https://github.com/rack/rack/issues/551 or http://stacko…
#!/user/bin/env ruby
#coding: utf-8
APP_ROOT = File.dirname(__FILE__)
PROJECT_NAME = 'My Fantastic Game'
PROJECT_HOST = '0.0.0.0'
WEB_PORT = 9292
WS_PORT = 8080
COOKIE_KEY = 'my.session.key'
COOKIE_SECRET = 'shh_replace_me_withsomething_moresecret'