This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'benchmark' | |
| N = 1000000 | |
| class TestingObjectTap | |
| def ugly | |
| results = {} | |
| [:x, :y, :z].each do |letter| | |
| results[letter] = rand(100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| class Foo | |
| def initialize | |
| @bar = rand(100) # for caching | |
| end | |
| def bar | |
| @bar ||= rand(100) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Not override -E option or LANG and apply only for ruby > 1.9 | |
| if Object.const_defined?(:Encoding) && !ENV['LANG'] && !ENV['RUBYOPT'].include?('-E') | |
| Encoding.default_internal = 'utf-8' | |
| Encoding.default_external = 'utf-8' | |
| end | |
| require ::File.expand_path('../config/environment', __FILE__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| N = 70000 | |
| Benchmark.bmbm do |x| | |
| x.report('foo + bar') { N.times { | |
| 'foo' + 'bar' | |
| } } | |
| x.report('#{foo}#{bar})') { N.times { | |
| "#{'foo'}#{'bar'}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://guides.rubygems.org/make-your-own-gem/ | |
| rvm use ruby-1.9.3-p0@lorem --create | |
| echo "rvm use ruby-1.9.3-p0@lorem --create" >> lorem/.rvmrc | |
| bundle gem lorem | |
| gem build lorem.gemspec | |
| git tag -a v0.0.1 -m 'version 0.0.1' | |
| git push --tags | |
| gem push lorem-0.0.1.gem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| My gist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| N = 10000 | |
| ARRAY = begin | |
| [].tap do |array| | |
| (1..1000).to_a.each do |entry| | |
| array << '' if rand(5) == 0 | |
| array << entry.to_s | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| # Set up gems listed in the Gemfile. | |
| ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __FILE__) | |
| require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) | |
| require 'rails/all' | |
| N = 10000000 | |
| EMPTY_STRING = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # mate ~/.irbrc | |
| #!/usr/bin/env ruby | |
| if defined? Rails | |
| begin | |
| require 'factory_girl' | |
| Dir[Rails.root.join("spec/factories/**/*.rb")].each { |f| require f } | |
| rescue LoadError | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| class CleaningHomeBrew | |
| # Your binaries unlinked | |
| BINARIES = ['cmake', 'imagemagick', 'jasper', 'jpeg', 'libevent', 'libtiff', 'little-cms','memcached','mysql','ossp-uuid','pidof','postgresql','redis','sphinx','wget'] | |
| class << self | |
| def clean |
NewerOlder