Skip to content

Instantly share code, notes, and snippets.

Aaron Kromer cupakromer

Block or report user

Report or block cupakromer

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
View verbose_alternative.rb
class NotesController < ApplicationController
def index
notes = requested_notes
respond_to do |format|
format.html do
render :index, locals: { notes: notes }
end
format.json do
render :index, locals: { notes: notes } if stale? notes
end
@cupakromer
cupakromer / proc_block.rb
Created Aug 1, 2015
Symbol#to_proc vs blocks
View proc_block.rb
require 'benchmark/ips'
[10, 100, 1000, 10_000].each do |size|
range = (1..size)
puts "\nUsing Array#map size #{size}:"
Benchmark.ips do |x|
x.report('Block ') { range.map { |i| i.to_s } }
x.report('Symbol#to_proc') { range.map(&:to_s) }
x.compare!
View gist:4ba0c4bc7e0a57c93b2c
public String railways(String name, Void _ignoreError) {
return "SUCCESS";
}
public String railways(Void _ignoreName, String error) {
return "FAILURE";
}
@Test
public void workingWithEither() {
@cupakromer
cupakromer / gist:38a54595ad0ed5ec16ec
Created Jun 25, 2015
Quad Related Hash lookup benchmarks
View gist:38a54595ad0ed5ec16ec
require 'benchmark/ips'
substitutions = {
'true' => true,
'false' => false,
'null' => nil,
'' => nil
}.freeze
Benchmark.ips do |x|
View tracked_let.rb
# transaction/truncation strategies won't work when you have a
# capybara feature and you must preserve what's already in the
# database
#
# Usage:
# include TrackedLet
#
# track(:foo) { User.create }
# track!(:foo) { User.create }
# specify { expect(track(User.create)).to be_persisted }
View gist:4def805dfd5959d695f8
foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
\_/ \_______________/ \_________/ \__/ \___/ \_/ \______________________/ \__/
| | | | | | | |
| userinfo host port | | query fragment
| \________________________________/\_____________|____|/ \__/ \__/
scheme | | | | | |
name authority | | | | |
| path | | interpretable as keys
| | |
| \_______________________________________________|____|/ \____/ \_____/
View gist:5800e3cafd3c1b8beaab
module ExampleModuleFunctions
def self.use_class_method
"module singleton class method"
end
def use_normal_method
"normally included method"
end
View forking_rspec.rb
#!/usr/bin/env ruby
ENV['RAILS_ENV'] = 'test'
require 'benchmark'
rails_loading_time = Benchmark.measure { require './config/environment' }
puts "Rails env loaded in #{rails_loading_time}"
NUM_FORKS = 2
test_groups = `find ./spec -type f -iname "*foobar*"`.split("\n").in_groups(NUM_FORKS).to_a
@cupakromer
cupakromer / erb.sh
Last active Aug 29, 2015
rspec-rails issue #1331
View erb.sh
$ bin/rails g scaffold foo
invoke active_record
create db/migrate/20150305063125_create_foos.rb
create app/models/foo.rb
invoke rspec
create spec/models/foo_spec.rb
invoke resource_route
route resources :foos
invoke scaffold_controller
create app/controllers/foos_controller.rb
View README.md

TL;DR

Both methods are nearly identical in perf. Differences are due more to underlying forwarded messages' implementation than how the message forwarding is defined.

Summary

Error rates between each type, for the most part, negate any real ranking. A real stat analysis would be necessary to make a real determination.

Grouped by Command style:

You can’t perform that action at this time.