Skip to content

Instantly share code, notes, and snippets.

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 / .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.
@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 / caller.js
Created March 19, 2012 01:36
konami code js
$(window).konami(function(){
$(".goku").show();
$(".goku").delay(2000).fadeOut();
});
@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 / gist:2295266
Created April 3, 2012 20:25
sed to replace FactoryGirl old style to the new one on OS X
sed -i.bkp s/Factory\(\:/FactoryGirl.create\(\:/g spec/**/*.rb
sed -i.bkp s/Factory\ \:/FactoryGirl.create\ \:/g spec/**/*.rb
sed -i.bkp s/Factory\.build\ \:/FactoryGirl.build\ \:/g spec/**/*.rb
sed -i.bkp s/Factory\.build\(\:/FactoryGirl.build\(\:/g spec/**/*.rb
sed -i.bkp s/Factory\.next/FactoryGirl\.generate/g spec/**/*.rb
rm -rf spec/**/*.bkp
RSpec.configure do |config|
config.before(:suite) do
ActiveRecord::Base.observers.disable :all
end
end
click_on "Add new person"
last_nested_fields = all('.fields').last
within(last_nested_fields) do
fill_in "Name", with: "Ricardo"
fill_in "Age", with: 27
end
class Foo
end
Foo.class_eval do
def bar
"Bar from class eval"
end
end
Foo.instance_eval do
#!/usr/bin/env ruby
# pingpongninja_expected_results -- simulate a series of games on pingpongninja
#
# algorithm extracted from
# https://github.com/jdennes/pingpongapp/blob/master/pingpong/rankings.py
def new_ranks(rank1, rank2, points1, points2)
decay_factor = 10
game_ranking_points = (rank1 + rank2) / 2
ranking_change1 = game_ranking_points + (points1 - points2) * 100 / [points1, points2].max
ranking_change2 = game_ranking_points + (points2 - points1) * 100 / [points1, points2].max