Skip to content

Instantly share code, notes, and snippets.

View erik-megarad's full-sized avatar

Erik Peterson erik-megarad

View GitHub Profile
diff --git a/kernel/common/array.rb b/kernel/common/array.rb
index 58370be..e213ff9 100644
--- a/kernel/common/array.rb
+++ b/kernel/common/array.rb
@@ -181,179 +181,6 @@ class Array
alias_method :slice, :[]
- def set_index(index, ent, fin=undefined)
- Rubinius.primitive :array_aset
rake build
/Users/epeterson/.rvm/rubies/ruby-1.9.2-p290/bin/ruby vm/codegen/field_extract.rb vm/builtin/basicobject.hpp vm/builtin/object.hpp vm/builtin/integer.hpp vm/builtin/fixnum.hpp vm/builtin/array.hpp vm/builtin/bignum.hpp vm/builtin/executable.hpp vm/builtin/access_variable.hpp vm/builtin/alias.hpp vm/builtin/block_environment.hpp vm/builtin/block_as_method.hpp vm/builtin/bytearray.hpp vm/builtin/chararray.hpp vm/builtin/io.hpp vm/builtin/channel.hpp vm/builtin/module.hpp vm/builtin/class.hpp vm/builtin/compiledmethod.hpp vm/builtin/data.hpp vm/builtin/dir.hpp vm/builtin/exception.hpp vm/builtin/float.hpp vm/builtin/immediates.hpp vm/builtin/iseq.hpp vm/builtin/list.hpp vm/builtin/lookuptable.hpp vm/builtin/ffi_pointer.hpp vm/builtin/methodtable.hpp vm/builtin/nativefunction.hpp vm/builtin/packed_object.hpp vm/builtin/randomizer.hpp vm/builtin/regexp.hpp vm/builtin/staticscope.hpp vm/builtin/string.hpp vm/builtin/symbol.hpp vm/builtin/thread.hpp vm/builtin/tuple.hpp vm/builtin/compactlookuptable.hpp v
@erik-megarad
erik-megarad / gist:1563290
Created January 5, 2012 01:58 — forked from brow/gist:1562617
Benchmark concatenating strings with reduce(:+) vs. with join('').
require 'benchmark'
STRING = 'abc'
ITERATIONS = 500000
Benchmark.bm(10) do |bench|
for n in [2,3,4, 5]
n_strings = Array.new(n, STRING)
bench.report("add #{n}") do
@erik-megarad
erik-megarad / gist:1597477
Created January 11, 2012 23:34
For fun, run this at home
["US-ASCII", "ASCII-8BIT", "UTF-8"].each do |encoding|
Encoding.default_internal = encoding
puts "With #{encoding} default internal:"
[127, 255, 256].each do |number|
no_arg = number.chr.encoding rescue "out of range"
puts "#{number}.chr is: #{no_arg}"
with_arg = number.chr(encoding).encoding rescue "out of range"
puts "#{number}.chr('#{encoding}') is: #{with_arg}"
end
Terminal 1:
$ bundle exec spork
Using RSpec
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Running tests with args ["--color", "--fail-fast", "--failure-exit-code", "2", "--format", "progress", "--format", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--require", "/Users/epeterson/.rvm/gems/rbx-head/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb", "spec"]...
Done.
[1] 70450 killed bundle exec spork
Terminal 1:
$ bundle exec spork
Using RSpec
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Running tests with args ["--color", "--fail-fast", "--failure-exit-code", "2", "--format", "progress", "--format", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--require", "/Users/epeterson/.rvm/gems/ruby-1.9.3-p125-perf@exact/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb", "spec"]...
Done.
[1] 70757 killed bundle exec spork
@erik-megarad
erik-megarad / gist:2704272
Created May 15, 2012 19:08
Fuck you. Just... Fuck. you.
Failures:
1) Foo timestamp
Failure/Error: its(:timestamp) { should eql timestamp }
expected: Tue, 15 May 2012 19:06:00 UTC +00:00
got: Tue, 15 May 2012 19:06:00 UTC +00:00
(compared using eql?)
irb(main):001:0> "Caches".singularize
=> "Cach"
@erik-megarad
erik-megarad / gist:5265641
Created March 28, 2013 18:28
TIL: Postgres freezes now() to the start-time of the transaction while inside a transaction.
psql (9.1.3)
Type "help" for help.
dev=# select now();
now
-------------------------------
2013-03-28 14:27:28.820854-04
(1 row)
dev=# select now();
require 'spec_helper'
describe GamesController do
describe 'POST "create"' do
subject(:response) { post :create, params }
context 'valid parameters provided' do
let(:params) { { game: FactoryGirl.attributes_for(:game) } }
specify { expect { subject }.to change(Game, :count).by 1 }