Skip to content

Instantly share code, notes, and snippets.

View flori's full-sized avatar

Florian Frank flori

View GitHub Profile
@flori
flori / beware.rb
Created August 8, 2012 21:28
What does foo return?
def foo
some_function_computing_integer_value
+ some_other_function_computing_integer_value
+ the_last_function_computing_integer_value
end
@flori
flori / db.rake
Created August 2, 2012 08:06
List migrations in a rails project
def list_migrations
Dir['db/migrate/[0-9]*.rb'].sort_by { |f| File.basename(f).to_i }
end
namespace :db do
namespace :migrate do
namespace :list do
desc 'List all paths to migration files starting with the last one'
task :paths do
puts list_migrations
@flori
flori / y.rb
Created May 15, 2012 19:33
Y, oh Y in Ruby 1.9
Y = -> f { -> g { g[g] }[ -> h { -> *x { f[h[h]][*x] } } ] }
Y[ -> f { -> n { n < 1 ? 1 : n * f[n-1] } } ][23]
@flori
flori / gist:1399957
Created November 28, 2011 10:49 — forked from evanphx/gist:1373994
require 'rubygems'
require 'benchmark'
require 'json'
A = (0..1_000).map { rand }
org_array = []
json_array = []
0.upto(20000) do |i|
require 'permutation' # gem install permutation
>> Permutation.for((1..4).to_a.reverse).map(&:project).map(&:reverse)
# => [[1, 2, 3, 4], [2, 1, 3, 4], [1, 3, 2, 4], [3, 1, 2, 4], [2, 3, 1, 4], [3, 2, 1, 4], [1, 2, 4, 3], [2, 1, 4, 3], [1, 4, 2, 3], [4, 1, 2, 3], [2, 4, 1, 3], [4, 2, 1, 3], [1, 3, 4, 2], [3, 1, 4, 2], [1, 4, 3, 2], [4, 1, 3, 2], [3, 4, 1, 2], [4, 3, 1, 2], [2, 3, 4, 1], [3, 2, 4, 1], [2, 4, 3, 1], [4, 2, 3, 1], [3, 4, 2, 1], [4, 3, 2, 1]]
# vim: ts=2 sw=2 et ft=ruby
# Call with two strings of ones on the tape:
# $ turing.rb ones_difference.stm 1111 11
1. right goto: 2
2. cond if: '1', then: 1, else: 3
3. right goto: 4
4. cond if: '1', then: 5, else: 17
5. right goto: 6
6. cond if: '1', then: 5, else: 7
# vim: ts=2 sw=2 et ft=ruby
# Call with two strings of ones on the tape:
# $ turing.rb ones_difference.stm 1111 11
1. right :goto => 2
2. cond :if => '1', :then => 1, :else => 3
3. right :goto => 4
4. cond :if => '1', :then => 5, :else => 17
5. right :goto => 6
6. cond :if => '1', :then => 5, :else => 7