Skip to content

Instantly share code, notes, and snippets.

Avatar

Jorge Kalmbach kalmbach

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am kalmbach on github.
  • I am kalmbach (https://keybase.io/kalmbach) on keybase.
  • I have a public key ASB3JdjSXH24vM0HNwGt8f2Y9S_2H-HjvDTLO3sKHyTnHQo

To claim this, I am signing this object:

@kalmbach
kalmbach / flatten.rb
Created Feb 26, 2016
Flatten Exercise
View flatten.rb
#!/usr/bin/ruby
# Ruby already has a 'flatten' method in the Array class
# [[1,2,[3]],4].flatten -> [1,2,3,4]
#
# I did my own implementation as an exercise
module Code
def ruby_flatten(ary)
ary.flatten if ary.respond_to? :flatten
@kalmbach
kalmbach / gist:5385621
Last active Dec 16, 2015
Rack Middleware that implements Session Flash messages. (session values that will be available just for the request) Usage: use Rack::Session::Flash
View gist:5385621
module Rack
module Session
class Flash
def initialize(app)
@app = app
end
def call(env)
dup.call!(env)
end
@kalmbach
kalmbach / gist:4471560
Created Jan 7, 2013
Rake task sugar for Sequel Migrations (version, migrate, rollback, reset)
View gist:4471560
namespace :db do
require "sequel"
Sequel.extension :migration
DB = Sequel.connect(ENV['DATABASE_URL'])
desc "Prints current schema version"
task :version do
version = if DB.tables.include?(:schema_info)
DB[:schema_info].first[:version]
end || 0
@kalmbach
kalmbach / Date-extensions.rb
Created Oct 30, 2012
Extending Date Class. WeekDay and Next WeekDay methods.
View Date-extensions.rb
class Date
# Extend Date Class with some custom methods
# Returns the name of the week day.
#
# Date.today.weekday
# -> 'Monday'
def weekday
self.strftime("%A")