Skip to content

Instantly share code, notes, and snippets.

Notes for Rails Meetup - Jan 2013

Rerun/Reload app

  • hot-key
  • hook on save
  • watch
  • Rack::Reloader
  • guard/autotest/shotgun/etc
Rails.application.config.database_configuration
Rails.application.load_generators
Rails.application.load_seed
Rails.application.paths['db/migrate'].to_a
Rails.application.railties.all
Rails::Engine.find(ENGINE_PATH)
Rails.env
Rails.env.development?
Rails::Generators::SessionMigrationGenerator.start [ ENV['MIGRATION'] || 'add_sessions_table' ]
Rails.root
@cutalion
cutalion / notes_for_rails_meetup_feb_2013.md
Created January 28, 2013 13:29
Notes for Rails Meetup - Feb 2013

Nice gems

  • racksh - console for Rack apps, like rails c or merb -i
def empty?(s)
return s.size == 0
end
class B
def ==(s)
"not boolean"
end
end

-[ ] one

-[ ] two

-[ ] three

require 'open3'
Open3.popen2e("wget", "http://dumps.wikimedia.org/ruwiki/latest/ruwiki-latest-templatelinks.sql.gz", "-O wiki.sql.gz") do |i, oe, wait_thr|
oe.each do |line|
puts line[/\d+%/]
end
end
@cutalion
cutalion / README.md
Last active December 23, 2015 23:59
Temporary turn VCR off

I often use VCR gem. And I always configure it to use rspec metadata to turn it on with just :vcr symbol.

When I know that some module will always hit the external service, I turn VCR on at the very top describe.

describe "Something", :vcr do
  it "should make coffee" do
  end
@cutalion
cutalion / README.md
Last active December 24, 2015 07:19
Make all files in S3 "directory" private or public

Once I've got a task to make a lot of files stored on S3 private. In my project I used carrierwave and fog.
All files were public by default.

In order not to make many requests to AWS, I've decided to change bucket policy instead of ACL of each file.

@cutalion
cutalion / README.md
Last active August 29, 2015 13:56
Thumbnail creation with ffmpeg

Processor: Intel Core i3

time ./m_ffmpeg.sh dinner.m4v
./m_ffmpeg.sh dinner.m4v 48,54s user 5,34s system 142% cpu 37,897 total

time ./m_thumbnailer.sh dinner.m4v ./m_thumbnailer.sh dinner.m4v 66,21s user 5,61s system 156% cpu 45,918 total

require 'active_support/testing/time_helpers'
RSpec.configure do |config|
config.include ActiveSupport::Testing::TimeHelpers
config.after do
travel_back
Timecop.return
end