View gist:17e8dd8ee421e74b1197
1 2 3 4 5 6 7 8 9
from_date = Date.new(2015, 02, 1)
to_date = Date.civil(2015, 02, -1)
 
attendance_lines_by_date = File.open(ATTENDANCE_LINES_FILE)
.readlines
.map { |line_text| AttendanceLine.new line_text, ROSTER }
.select { |line| line.date >= from_date and line.date <= to_date }
.reject { |line| line.date.weekend? }
.group_by { |line| line.date }
View why_i_<3.rb
1 2 3 4 5 6 7 8 9 10
require 'csv'
 
module Roster
# Example of each row is: [1,Pac,Sivabudh Umpudh,nil,nil,nil,nil,nil,nil]
def self.parse_from_csv filename
CSV.read(filename)
.drop(1) # remove the first row of CSV which is a header
.map(&:compact) # remove all `nil`
.map { |line_array| [line_array[0], "#{line_array[1]} - #{line_array[2]}"] } # convert ["1", "Pac", "Sivabudh Umpudh"] to ["1", "Pac - Sivabudh Umpudh"]
.to_h # convert array to hash: voila, I now got a hash with key as the ID, and value as my name!
View imperative_vs_functional.rb
1 2 3 4 5 6 7 8 9 10
puts "Hello. Welcome to the Functional World!"
 
#
# This is how to do it imperative style (aka: Stupid Java programmer)
#
array = [1,2,3,4]
new_array = []
array.each do |n|
if n % 2 == 0
new_array.push n
View functional_vs_imperative
1 2 3 4 5 6 7 8 9
puts "Hello. Welcome to the Functional World!"
 
# This is how to do it imperative style (Stupid Java programmer)
array = [1,2,3,4]
new_array = []
array.each do |n|
if n % 2 == 0
new_array.push n
end
View gist:f4d170fd817b1ffc97e2
1 2 3 4 5 6 7 8 9 10
$DICTIONARY_FILE = "Main.old.strings"
$FILE_TO_TRANSLATE = "Main.strings"
$TRANSLATED_FILE = "Main.new.strings"
 
module StringsExtraction
def self.extract_english_phrase line
cleaned_up_line = line.delete "/*\n"
tokens = cleaned_up_line.split(";")
token_with_english_phrase = tokens[1]
english_phrase = token_with_english_phrase.split(" = ")[1]
View 0_reuse_code.js
1 2
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View gist:c1ed325628eb17cb4c78
1 2 3 4 5 6 7 8 9
require 'sinatra'
 
get '/hi' do
"Hello World!"
end
 
get '/' do
erb :form
end
View gist:4a289028ea917a4b9bfd
1 2 3 4 5 6 7 8 9 10
require "spec_helper"
require "largest" # name of the class we have just created
 
describe Largest do
describe "#find_largest" do
it "finds the largest number in the array" do
largest_number = Largest.find_largest([1,4,2])
expect(largest_number).to eq(4)
end
end
View Gemfile
1 2 3 4 5
source 'https://rubygems.org'
 
group :test do
gem 'rspec'
end
Something went wrong with that request. Please try again.