Skip to content

Instantly share code, notes, and snippets.

View ootoovak's full-sized avatar

Juna Ootoovak ootoovak

View GitHub Profile
require 'pry'
require 'pry-byebug'
def get_even_numbers_from_zero_to(number)
numbers = []
(0..9).each do |number|
numbers << number if (number % 2 == 0)
end
@ootoovak
ootoovak / _gitignore_rails.sh
Last active August 29, 2015 14:15
Starter Git Ignore files (rename to .gitignore and add to the root of your project directory).
.DS_Store
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/test/tmp/
/test/version_tmp/
@ootoovak
ootoovak / introrx.md
Last active September 16, 2015 00:35 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@ootoovak
ootoovak / gem_leaderboard.rb
Created November 23, 2011 04:04
Place in your a directory with Bundler projects and run to create a leaderboard of your Gems.
#!/usr/bin/ruby -w
puts "Counting your gems ..."
gems = {}
project_folders = Dir.entries(".").select{ |d| d !~ /^\..*/ && !File.file?(d) }
project_folders.each do |folder|
Dir.chdir(folder) do
if File.exists?('Gemfile') && File.file?('Gemfile')
@ootoovak
ootoovak / carousel.rb
Created May 17, 2012 23:08
1D Packing Problem - Recursive Solution
@ootoovak
ootoovak / buckybackup
Created June 6, 2012 23:04
backup bucky
#!/bin/sh
BACKUPDIR=/Users/developer/backup/bucky/production/
DAYSTAMP=`date "+%d"`
HOURSTAMP=`date "+%H"`
DAYFILE="daily_$DAYSTAMP.dump"
HOURFILE="hourly_$HOURSTAMP.dump"
DAYPATH=$BACKUPDIR$DAYFILE
HOURPATH=$BACKUPDIR$HOURFILE
@ootoovak
ootoovak / tb_fluid_inside_static.haml
Created September 1, 2012 07:11
Twitter Bootstrap Fluid Inside Static
%body
.container
.row
.span2
.span10
.container-fluid
.row-fluid
.span3
.span3
.row-fluid
@ootoovak
ootoovak / fast_spec_helper.rb
Last active December 13, 2015 17:48
Something I'm working with at the moment. WIP
require 'active_attr'
RELATIVE_APP_PATH = File.expand_path("../../app", __FILE__)
def construct_require_path(middle_path, name)
"#{RELATIVE_APP_PATH}/#{middle_path}/#{name}.rb"
end
def require_model(name)
require construct_require_path('models', name)
@ootoovak
ootoovak / example_usage.rb
Created May 21, 2013 00:02
Helper methods to load as few files as possible to get tests to run. Some create require paths to load files and others to init required constants.
require 'fast_spec_helper'
require 'date'
require_model 'generate_required_daily_lists'
required_constants %w(Distributor PackingList DeliveryList)
---- OR ----
require 'fast_spec_helper'
require_model 'exporter', sub_dir: 'sales_csv'
require_model 'delivery_exporter', sub_dir: 'sales_csv'
@ootoovak
ootoovak / Problem.rb
Last active December 18, 2015 16:29
Don't recreate another object if you don't need to.
# Want to pass in a hash or instance of object. Was hoping to avoid is_a? or creating a new object but
# think that can only be done with is_a? or overriding new. Also, I might be missing the point as
# avoiding is_a? should mean I am using Duck Typing but if I'm using Duck Typing then I shouldn't be
# checking object equality anyway. See RSpec test for details.
describe MyClass do
let(:hash) { { name: 'Duck Type', description: 'Quacks like a duck?' } }
before do
@my_instance_1 = MyClass.new(hash)