Skip to content

Instantly share code, notes, and snippets.

View mcfiredrill's full-sized avatar
💭
working on datafruits

Tony Miller mcfiredrill

💭
working on datafruits
View GitHub Profile
[20] pry(main)> wat = -> hey {
[20] pry(main)* hey + " wat"
[20] pry(main)* }
=> #<Proc:0x007fafda2f4568@(pry):19 (lambda)>
[21] pry(main)> wat['derp']
=> "derp wat"
def do_the_thing blahblah
case blahblah
when blahblah.is_a? ThingDoer
ThingDoer.do_your_thing
when blahblah.is_a? OtherThingDoer
OtherThingDoer.do_your_thing
end
end
@mcfiredrill
mcfiredrill / OtherThingDoer.rb
Last active August 29, 2015 14:09
now its classes
class OtherThingDoer
def do_your_thing
"THAT THING"
end
end
@mcfiredrill
mcfiredrill / gist:ae2645b7563bbd0e4ec2
Created December 19, 2014 09:14
can't connect to docker after boot2docker upgrade
🍒tony@moguya ~$ boot2docker upgrade
2014/12/19 18:13:44 Downloading boot2docker ISO image...
2014/12/19 18:13:45 Latest release is v1.4.1
2014/12/19 18:13:51 Success: downloaded https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso
to /Users/tony/.boot2docker/boot2docker.iso
2014/12/19 18:13:52 Waiting for VM to be started...
.......
2014/12/19 18:14:13 Started.
2014/12/19 18:14:13 Your DOCKER_HOST env variable is already set correctly.
🍒tony@moguya ~$ docker ps

I was trying to get my tests as fast as possible like in gary bernhardts videos. I noticed even running the rspec command with no test at all took about 500 ms.

I know there is weird stuff in my .bashrc that takes awhile to load the first shell. But does that slow down every command as well?

🍒tony@moguya ~$ time ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]

real    0m0.504s
user 0m0.041s
class SoundcloudSharesImporter
def self.fetch user
token = user.soundcloud_token
sc_client = Soundcloud.new(access_token: token)
favorites = sc_client.get("/me/favorites")
provider = 'Soundcloud'
favorites.each do |favorite|
url = favorite.permalink_url
shared_at = favorite.created_at
share = Share.find_or_create_by url: url, user_id: user.id, provider: provider
@mcfiredrill
mcfiredrill / create_track_share.rb
Last active August 29, 2015 14:12
separated into three classes
class CreateTrackShare
def self.create url, shared_at, user_id, provider
share = Share.find_or_create_by url: url, user_id: user_id, provider: provider
track = Track.find_or_create_by url: url
track.shares << share
share.shared_at = shared_at
share.save
end
end
class SharesImporter
def self.import user
[SoundcloudFetcher.fetch(user),FacebookFetcher.fetch(user),TwitterFetcher.fetch(user)].flatten.map{|m| CreateTrackShare(m)}
end
end
class RegistrationsController < Devise::RegistrationsController
end
@mcfiredrill
mcfiredrill / boot_container.rb
Created January 24, 2015 08:48
ExtraHosts is null
> container = Docker::Container.create('Image' => 'mcfiredrill/icecast', 'name' => radio, 'HostConfig' => { 'Links' => ["redis:redis"], 'ExtraHosts' => ["hostmachine:192.168.1.4"] })
> container.json["HostConfig"]["ExtraHosts"]
["hostmachine:192.168.1.4"]
> container.start("PublishAllPorts" => "true")
> container.json["HostConfig"]["ExtraHosts"]
nil