This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
class Mediator < BasicObject | |
def initialize(hash, *syms) | |
@h = hash | |
@syms = syms | |
end | |
def method_missing(name, *args) | |
@h.has_key?(name) ? @h[name] : super | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'curses' | |
class GameOfLife | |
LIVE_CHAR = "0" | |
DEAD_CHAR = '.' | |
def initialize(nrows, ncols, opts={}, &block) | |
@nrows, @ncols = nrows, ncols | |
@opts = opts | |
@rows = (0..@nrows).each_with_object([]) { |i, acc| @ncols.times { (acc[i] ||= []) << DEAD_CHAR } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
class ThreadPool | |
def self.run(numthreads, &block) | |
tp = new(numthreads) | |
block.call(tp) | |
ensure | |
tp.shutdown | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RedisHelper | |
def redis | |
@redis ||= Redis.new.tap do | |
@redis_available = true | |
end | |
end | |
def ns_key(k) | |
"enfo_sm:#{k}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
email = [email protected] | |
name = Edvard Majakari | |
[alias] | |
bl = blame | |
br = branch | |
ci = commit | |
cl = clone | |
co = checkout | |
cp = cherry-pick |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x () { | |
if [ -f $1 ] | |
then | |
case $1 in | |
(*.tar.bz2) tar xvjf $1 ;; | |
(*.tar.gz) tar xvzf $1 ;; | |
(*.bz2) bunzip2 $1 ;; | |
(*.rar) unrar x $1 ;; | |
(*.gz) gunzip $1 ;; | |
(*.tar) tar xvf $1 ;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# initializers/fix_relative_root_cells.rb | |
fail unless ActionDispatch::Routing::RouteSet | |
module ActionDispatch | |
module Routing | |
class RouteSet | |
alias url_for__ptsroot__ url_for | |
def url_for(options = {}) | |
options[:script_name] = ENV['RAILS_RELATIVE_URL_ROOT'] if options.kind_of?(Hash) | |
options = Base.relative_url_root.to_s + options if options.kind_of?(String) and options.starts_with?('/') | |
url_for__ptsroot__(options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
require 'tmpdir' | |
require 'open-uri' | |
require 'digest' | |
require 'ri_cal' | |
class HolidayCalendar | |
DEFAULT_CAL_URI = 'https://www.google.com/calendar/ical/fi.finnish%23holiday%40group.v.calendar.google.com/public/basic.ics' | |
CACHE_MAX_DAYS = 360 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t0 = Time.local(2012, 12, 19) | |
time_in_days = 180 | |
cur_w = 90.7 | |
w_delta = 6*2.0 | |
DAY = 86400 | |
target_date = t0 + time_in_days*DAY | |
target_weight = cur_w - w_delta | |
daily_loss = w_delta / time_in_days |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FunctionalArrayExtension | |
def head | |
_split_it | |
raise StandardError, "cannot take head of an empty array" if empty? | |
@head | |
end | |
def tail | |
_split_it | |
raise StandardError, "cannot take tail of an empty array" if empty? |