Skip to content

Instantly share code, notes, and snippets.

Josh Cheek JoshCheek

Block or report user

Report or block JoshCheek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JoshCheek
JoshCheek / play_movie.rb
Created Aug 26, 2015
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 = 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 Aug 27, 2015
Discovering Enumerable
View DiscoveringEnumerable.md

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 Aug 29, 2015
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
end
User = Class.new ActiveRecord::Base
@JoshCheek
JoshCheek / i_dont_understand_random.rb
Last active Aug 29, 2015
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 = ::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 Feb 11, 2014
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
is_within_board_width!
is_not_below_board!
View ascii-avatar.txt
,.....,,::~~~~~=?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 Feb 28, 2014
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 }
end
class Invoice < ActiveRecord::Base
View whatevzs
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 Aug 29, 2015
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 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
You can’t perform that action at this time.