Skip to content

Instantly share code, notes, and snippets.

View chrisvanhill's full-sized avatar

Christoph Ambichl chrisvanhill

View GitHub Profile
@patmaddox
patmaddox / shoulda_just_wrote_the_code_spec.rb
Created July 14, 2011 20:31
A goofy bit of code that takes your shoulda-style macro validations and generates a model class from it
# A goofy bit of code that takes your shoulda-style macro validations and generates a model class from it
require 'rspec'
require 'active_model'
module ActiveRecordTranslator
def it_should_validate_presence_of(field)
klass = Class.new do
include ActiveModel::Validations
@Bregor
Bregor / spec__requests__history_items_spec.rb
Created June 29, 2011 09:09
Capybara request helpers for devise
require 'spec_helper'
describe "HistoryItems" do
before(:each) {login_as :user}
describe "GET /history_items" do
it "works!" do
visit history_items_path
response.should be_success
end
end
@gvarela
gvarela / Gemfile
Created May 5, 2011 16:30
web sockets with eventmachine and redis pub/sub
# A sample Gemfile
source "http://rubygems.org"
gem "redis"
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
gem "em-hiredis"
# gem "em-synchrony"
gem "em-websocket"
@cooperq
cooperq / sinatracrud.rb
Created May 3, 2011 19:28
crud in sinatra
#here is app.rb:
get '/admin' do
protected!
@posters = Poster.all
@category_1_posters = @posters.all :category => 1
@category_2_posters = @posters.all :category => 2
@category_3_posters = @posters.all :category => 3
haml :'admin/index'
end
@chrisvanhill
chrisvanhill / gist:874130
Created March 17, 2011 10:30
Ruby date and time formats
Letter Output Example
%A full day of week
%a abbrev day of week
%B full month name
%b abbrev month name
%C century (first two digits of year)
%c Day, month, time. year Thu Mar 17 11:20:10 2011
%D western format with slashes mm/dd/yy
%d day of month (zero-padded) 02
%e day of month (space-padded) _2
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