Skip to content

Instantly share code, notes, and snippets.

JoshCheek / play_movie.rb
Created August 26, 2015 08:03
Play a clip from a movie in the terminal
View play_movie.rb
Dir.chdir "/Users/josh/Desktop"
require 'streamio-ffmpeg'
path = ARGV[0]
movie =
width = 128
height = 80
start_time = 2.0
end_time = 3.0
frame_rate = movie.frame_rate
JoshCheek /
Last active August 27, 2015 16:47
Discovering Enumerable


What are they?

"Enumerable", in Ruby, is a set of methods for collections. They are used in all the common collection classes. This command will tell you which classes. Try to guess a few before you run it:

$ ruby -e 'p ObjectSpace.each_object(Class).select { |c| c < Enumerable }'
JoshCheek / sad_panda.rb
Last active August 29, 2015 13:55
Nested Rollbacks not working (guessing its a sqlite thing)
View sad_panda.rb
require 'active_record'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
self.verbose = false
create_table :users
User = ActiveRecord::Base
JoshCheek / i_dont_understand_random.rb
Last active August 29, 2015 13:56
Keep getting the same value for next_seed as I get for seed.
View i_dont_understand_random.rb
class RandomCollectionQueue
def initialize(seed, collection)
random = seed
self.collection = collection
self.seed = seed
self.next_seed = random.rand
self.block_index = random.rand collection.size
p [seed, next_seed]
JoshCheek / 1_with_nested_methods.rb
Created February 11, 2014 00:59
Hypothetical example of nested methods in Ruby. Really just intended to be an example, the actual syntax and implications would need more thought than I've put into it.
View 1_with_nested_methods.rb
# hypothetical implementation of nested methods
module Tetris
extend self
def add_block(board, block_definition, x, y=nil)
block_height = block_definition.height_for_rotation(0)
y ||= board.height + block_height
JoshCheek / ascii-avatar.txt
Last active August 29, 2015 13:56
ascii avatar!
View ascii-avatar.txt
JoshCheek / le_sigh.rb
Created February 28, 2014 21:45
FactoryGirl uses metaprogramming :(
View le_sigh.rb
require 'factory_girl' # => true
FactoryGirl::VERSION # => "4.4.0"
what_the_fuck_is_self = nil # => nil
FactoryGirl.define do factory(:qhatev) { what_the_fuck_is_self = self } end # => []
what_the_fuck_is_self.class # => #<FactoryGirl::Declaration::Implicit:0x007fa19bb8c6a0 @name=:class, @ignored=false, @factory=#<FactoryGirl::Definition:0x007fa19bb8da28 @declarations=#<FactoryGirl::DeclarationList:0x007fa19bb8d9d8 @declarations=[#<FactoryGirl::Declaration::Implicit:0x007fa19bb8c6a0 ...>], @name=:qhatev, @overridable=false>, @callbacks=[], @defined_traits=#<Set: {}>, @to_create=nil, @base_traits=[], @additional_traits=[], @constructor=nil, @attributes=nil, @compiled=false>>
View Invoice.total_outstanding.spec.rb
require 'active_record'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
self.verbose = false
create_table(:invoices) { |t| t.float :amount }
class Invoice < ActiveRecord::Base
JoshCheek / whatevzs
Last active August 29, 2015 13:57
Mac Setup
View whatevzs
Setup Mac
- Make sure you have xcode
- Install homebrew (bottom of
password: bbuser
- $ brew install git rbenv ruby-build
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
new terminal window
$ rbenv install 2.1.1
$ rbenv global 2.1.1
$ ruby -v
JoshCheek / day2.txt
Last active August 29, 2015 13:58
bloomberg day 2
View day2.txt
The roster is in the back, sign in or we'll have to hunt you down!
implement scaffold
guides at
docs at
new rails project
looking around ($ rails server)
generate the scaffold (articles with a title, body, and timestamps)
show how it works
go over the request to response flow