Skip to content

Instantly share code, notes, and snippets.

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

Enumerables

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
JoshCheek / sad_panda.rb
Last active August 29, 2015 13:55
Nested Rollbacks not working (guessing its a sqlite thing)
require 'active_record'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
self.verbose = false
create_table :users
end
User = Class.new ActiveRecord::Base
@JoshCheek
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.
class RandomCollectionQueue
def initialize(seed, collection)
random = ::Random.new seed
self.collection = collection
self.seed = seed
self.next_seed = random.rand
self.block_index = random.rand collection.size
p [seed, next_seed]
end
@JoshCheek
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.
# 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
is_within_board_width!
is_not_below_board!
@JoshCheek
JoshCheek / ascii-avatar.txt
Last active August 29, 2015 13:56
ascii avatar!
,.....,,::~~~~~=?II77$$Z$$ZZZ$$77I7?III???????????II??IIII?IIIIIIII77I7I77777777
,...,,.,~:::~~~~=++???I777$$$$Z$$I7I?I????+????I?I???I?I?IIII7777$77$Z$$$Z$$Z$ZZ
.....,,,:::::~==+=++?I??II777IIII7IIII?????+???I?IIIIIIIIII7II7$7$ZZZ$ZZOOOOOOZO
....,,,,:~::::~===+=++++??I77I777II??I???+++++???III?IIIIII77I$$ZZZOZZOZOO88OZOZ
....,,,:~~~~::~~=~=++++++?IIII777777I??+++==++???II?III7II777777$ZZ$$$$$$$77$Z77
,....,,:~~=~:=~~~==++???IIIIII777777$$I?+++++++??+??IIII7777$$$ZZ$$Z$$7$7$$7777$
,....,:~~~=+=~==~+++?????+?II777$$$Z777I?+++++=?++??II77$$$$ZOZZ$$Z$ZZ777777777$
:....,:~==++++??+==+++++?I777$$$$OOZ7777I++=+++++??III77$ZZZOZZZ$$$$$7777I7IIII7
~.....,:~==++===I77$Z$7Z$$ZZOO888ZZ$$7I7I??=====+??II77$$ZOZOZOOOZZZ$$7II7777777
@JoshCheek
JoshCheek / le_sigh.rb
Created February 28, 2014 21:45
FactoryGirl uses metaprogramming :(
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>>
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 }
end
class Invoice < ActiveRecord::Base
@JoshCheek
JoshCheek / whatevzs
Last active August 29, 2015 13:57
Mac Setup
Setup Mac
- Make sure you have xcode
- Install homebrew (bottom of http://brew.sh)
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
JoshCheek / day2.txt
Last active August 29, 2015 13:58
bloomberg day 2
The roster is in the back, sign in or we'll have to hunt you down!
implement scaffold
guides at guides.rubyonrails.org
docs at api.rubyonrails.org
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