Skip to content

Instantly share code, notes, and snippets.

View guilleiguaran's full-sized avatar
💭

Guillermo Iguaran guilleiguaran

💭
View GitHub Profile
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
/* This is when a refactoring really pays off.
*
* In order to make your code more modular, avoid hard-coding assumptions (or refactor them away).
* The most fundamental, anti-modular assumption in Object-Oriented software is the concrete type of objects.
* Any time you write "new MyClass" in your code (or in Ruby MyClass.new) you've hardcoded
* an assumption about the concrete class of the object you're allocating. These makes it impossible, for example,
* for someone to later add logging around method invocations of that object, or timeouts, or whatever.
*
* In a very dynamic language like Ruby, open classes and method aliasing mitigate this problem, but
* they don't solve it. If you manipulate a class to add logging, all instances of that class will have
@defunkt
defunkt / installing-mustache.vim.md
Created March 6, 2010 10:21
Installing mustache.vim

mustache.vim

In your shell:

cd ~/.vim
git clone git://github.com/juvenn/mustache.vim.git
mv mustache.vim/syntax/* syntax/
mv mustache.vim/indent/* indent/
mv mustache.vim/ftdetect/* ftdetect/

rm -rf mustache.vim

# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# This works with steak 0.3.x and rspec 1.x
# For steak --pre and rspec 2 see this fork: http://gist.github.com/448487
# Put this code in acceptance_helper.rb or better in a new file spec/acceptance/support/javascript.rb
Spec::Runner.configure do |config|
config.before(:each) do
Capybara.current_driver = :selenium if options[:js]
end
@luisuribe
luisuribe / Postgresl hints
Created May 24, 2010 04:35
Postgresql snippets
-- select size of tables and indices in random order
SELECT relname, reltuples, relpages FROM pg_class ;
-- select size of tables and indices in descending order of size
SELECT relname, reltuples, relpages FROM pg_class ORDER BY relpages DESC ;
-- select size of tables and indices in descending order of tuple- / recordcount
SELECT relname, reltuples, relpages FROM pg_class ORDER BY reltuples DESC ;
-- Change admin password
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
# Adapted for Rspec2. This won't work in RSpec 1.
# Put this code in acceptance_helper.rb or better in a new file spec/acceptance/support/javascript.rb
Rspec.configure do |config|
config.before(:each) do
Capybara.current_driver = :selenium if example.metadata[:js]
end
config.after(:each) do
@raggi
raggi / eventmachine_is_web_scale.rb
Created September 1, 2010 01:34
the secrets of the web scale sauce
require 'eventmachine'
EM.run do
SEKRET_SAUCE = EM.attach(
open(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null', 'w')
)
EM.start_server('0.0.0.0', 80, Module.new do
def post_init; proxy_incoming_to(SEKRET_SAUCE); end
end)
end
@adrianpike
adrianpike / rumble_stats
Created October 21, 2010 03:52
Simple word count of Rumble resource_used stats. make it bettar!
require 'rubygems'
require 'activeresource'
class Team < ActiveResource::Base; self.site = "http://railsrumble.com/"; self.format = :json; end
teams = []
counts = Hash.new(0)
(1..6).each {|n| teams += Team.find(:all, :params => {:page => n}).collect(&:team) }
teams.collect(&:entry).collect(&:resources_used).collect(&:split).flatten.each{|rn| counts[rn] += 1 }
counts.sort {|a,b| b[1]<=>a[1]}.each {|k,v|