Skip to content

Instantly share code, notes, and snippets.

@bernardeli
bernardeli / call_from_url_helpers.rb
Created March 22, 2012 01:22
include url_helpers
class Foo
def do_something
...
Rails.application.routes.url_helpers.my_awesome_routing_path
Rails.application.routes.url_helpers.my_awesome_routing_url(:host => 'http://your-domain.com')
...
end
end
@bernardeli
bernardeli / caller.js
Created March 19, 2012 01:36
konami code js
$(window).konami(function(){
$(".goku").show();
$(".goku").delay(2000).fadeOut();
});
@bernardeli
bernardeli / build.rb
Created February 16, 2012 03:28
rake build
desc "Run all tests"
task :build do
system "rm rerun.txt"
raise 'Error on rspec. Fix it, bro' unless system "bundle exec rspec spec"
raise 'Error on cucumber plain. Fix it, bro' unless system "bundle exec cucumber"
end
@bernardeli
bernardeli / .zshrc
Created October 20, 2011 17:03
highlighting code for keynote with highlight
first: brew install highlight
second: add to your .zshrc (or .bashrc)
function hlr {
filename=`echo $1 | cut -d . -f 1`
highlight --syntax ruby -k Menlo -K 20 -O rtf -s edit-xcode $1 > $filename.rtf
}
third: it will generate a .rtf file. just open and copy the highlighted code and add to your Keynote talk.
text = "7,3,s,1,1,2,y,4,2,r,2,4,1,o,2,3, ,1,R,1,1,1,b,5,3,c,5,4,k,2,u"
decoded = []
text.split(",").inject(0) do |sum, char|
unless char.to_i.zero?
sum + char.to_i
else
decoded[sum] = char
sum = 0
@bernardeli
bernardeli / callback.rb
Created August 17, 2011 02:59
facebook + devise
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model
@user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.facebook_data"] = env["omniauth.auth"]
@bernardeli
bernardeli / benchmark.rb
Created April 23, 2011 17:12
benchmark for named queues
require 'spec/spec_helper'
require 'logger'
require 'benchmark'
# Delayed::Worker.logger = Logger.new('/dev/null')
Benchmark.bm(10) do |x|
Delayed::Job.delete_all
n = 3000*3
n.times { "foo".delay.length }
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
sudo a2enmod rewrite
in public/.htaccess
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{DOCUMENT_ROOT}/cache/$1.html -f
RewriteRule ^(.*)$ /cache/$1.html
function git () {
case "$PWD"; in
/path/to/work/repos/*)
command git -c user.email=you@work.com "$@"
;;
*)
command git "$@"
;;
esac
}