Skip to content

Instantly share code, notes, and snippets.

View kalmbach's full-sized avatar
💻
programming

Jorge kalmbach

💻
programming
View GitHub Profile
@kalmbach
kalmbach / Date-extensions.rb
Created October 30, 2012 19:38
Extending Date Class. WeekDay and Next WeekDay methods.
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")
@kalmbach
kalmbach / gist:5385621
Last active December 16, 2015 05:38
Rack Middleware that implements Session Flash messages. (session values that will be available just for the request) Usage: use Rack::Session::Flash
module Rack
module Session
class Flash
def initialize(app)
@app = app
end
def call(env)
dup.call!(env)
end
@kalmbach
kalmbach / flatten.rb
Created February 26, 2016 16:13
Flatten Exercise
#!/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

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 / gist:4471560
Created January 7, 2013 01:27
Rake task sugar for Sequel Migrations (version, migrate, rollback, reset)
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