Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Log slow rspec examples

Just a quick monkey patch...

module Spec::Example
  module ExampleMethods
    THRESHOLD_TO_LOG = 500 # ms
    
    alias :execute_without_timing :execute
    def execute_with_timing(options)
      start_time = Time.now
      execute_without_timing(options)
      duration_ms = (Time.now - start_time) * 1000
      if (duration_ms > THRESHOLD_TO_LOG)
        print "(#{sprintf("%.3fms", duration_ms)} - #{_example.description}) "
      end
    end
    alias :execute :execute_with_timing
  end
end

Move acts_as_attachment / attachment_fu images

Use this to move files from the old directory structure (before 0000 format) to new one

Dir.new(File.dirname($PROGRAM_NAME)).each do |f|
  next if f == '0000' || f == 'move.rb' || f == '..' || f == '.'
  
  new_name = sprintf("%04d", f.to_i)
  
  puts "Moving #{f} to #{new_name}"
  puts `mv #{f} 0000/#{name}`
end
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS