Skip to content

Instantly share code, notes, and snippets.

@karmi
karmi / gist:25475
Created November 16, 2008 12:56 — forked from lifo/gist:25300
Rails' `assigns` helper for Sinatra tests by lifo
$: << "/Users/lifo/Rails/sinatra/lib"
require 'rubygems'
require 'sinatra'
require 'sinatra/test/unit'
require 'app'
class Rack::Response
attr_accessor :variables
end
@ryanb
ryanb / application.html.erb
Created January 19, 2011 19:31
Example of very simple password authentication.
<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>
require "minitest/autorun"
# inspired by some code from Chris Wanstrath (shared w. me by Ryan Smith)
# https://gist.github.com/25455
#
# heavily modified by Gregory Brown at this point..
def context(*args, &block)
return super unless (name = args.first) && block
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@obfuscurity
obfuscurity / gist:1409152
Created November 30, 2011 14:00
Rakefile for blog post
# Rakefile
namespace :db do
require "sequel"
namespace :migrate do
Sequel.extension :migration
DB = Sequel.connect(ENV['DATABASE_URL'])
desc "Perform migration reset (full erase and migration up)"
task :reset do
@ryanlecompte
ryanlecompte / gist:1420133
Created December 1, 2011 21:47
Alternative to modifying Proc directly
# alternative to what is explained in the article Ruby Blocks as Dynamic Callbacks:
# http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks
class Twitter
def tweet(msg, &block)
proxy = DSL[block]
publish(msg)
proxy.respond_with(:success)
rescue => e
proxy.respond_with(:failure, e.message)
@jeffreyiacono
jeffreyiacono / Rakefile
Created February 8, 2012 20:15
rake task for precompiling assets using sprockets within a sinatra app + view helpers
require 'rubygems'
require 'bundler'
Bundler.require
require './application'
namespace :assets do
desc 'compile assets'
task :compile => [:compile_js, :compile_css] do
end
@lukemelia
lukemelia / sketch.rb
Created June 23, 2012 20:01
sketch for Matt Wynne
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
class OrganizationCreator
@mattwynne
mattwynne / sketch.rb
Created June 23, 2012 22:22 — forked from lukemelia/sketch.rb
sketch for Matt Wynne
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
@adambard
adambard / errors.clj
Created May 13, 2013 05:48
An example of functional error handling in clojure.
(ns example.errors)
(defn clean-address [params]
"Ensure (params :address) is present"
(if (empty? (params :address))
[nil "Please enter your address"]
[params nil]))
(defn clean-email [params]
"Ensure (params :email) matches *@*.*"