Skip to content

Instantly share code, notes, and snippets.

require 'login_management'
use Rack::Session::Cookie
use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = LoginManager
end
run LoginManager
class MyApplication < Sinatra::Base
use Rack::Session::Cookie
use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = MyApplication
end
Warden::Manager.serialize_into_session{ |user| user.id }
@zzak
zzak / lisp.rb
Created September 5, 2010 16:20 — forked from dahlia/lisp.rb
# 30 minutes Lisp in Ruby
# Hong MinHee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,
# =====================
# Spell: Symbol to Proc
# =====================
# Convert a symbol to a block that calls a single method.
[1, 2, 3, 4].map(&:even?) # => [false, true, false, true]
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby
# =====================
# Spell: String of Code
# =====================
# Evaluate a string of Ruby code.
my_string_of_code = "1 + 1"
eval(my_string_of_code) # => 2
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby
# =======================
# Spell: Singleton Method
# =======================
# Define a method on a single object.
obj = "abc"
class << obj
def my_singleton_method
# ===================
# Spell: Shared Scope
# ===================
# Share variables among multiple contexts in the same Flat Scope (103).
lambda {
shared = 10
self.class.class_eval do
@zzak
zzak / self_yield.rb
Created September 13, 2010 16:53 — forked from nusco/self_yield.rb
# =================
# Spell: Self Yield
# =================
# Pass self to the current block.
class Person
attr_accessor :name, :surname
def initialize
@zzak
zzak / scope_gate.rb
Created September 13, 2010 16:53 — forked from nusco/scope_gate.rb
# =================
# Spell: Scope Gate
# =================
# Isolate a scope with the class, module, or def keyword.
a = 1
defined? a # => "local-variable"
module MyModule
@zzak
zzak / sandbox.rb
Created September 13, 2010 16:53 — forked from nusco/sandbox.rb
# ==============
# Spell: Sandbox
# ==============
# Execute untrusted code in a safe environment.
def sandbox(&code)
proc {
$SAFE = 2
yield