Skip to content

Instantly share code, notes, and snippets.

@gregspurrier
gregspurrier / Enumerable#reorder_by
Created November 7, 2010 21:03
Exploring performance characteristics of implementations of Enumerable#reorder_by
# Example code and benchmark harness for http://blog.gregspurrier.com/articles/arbitrary-reordering-of-ruby-arrays
require 'rubygems'
require 'rspec'
module Enumerable
def reorder_by1(order, &key_proc)
order.map do |x|
find {|obj| key_proc.call(obj) == x}
end
@gregspurrier
gregspurrier / to_proc_bench.rb
Created November 16, 2010 16:12
Benchmark for Symbol#to_proc and results from various Ruby implementations
# Benchmark code an results for:
# http://blog.gregspurrier.com/articles/relative-performance-of-symbol-to-proc-in-popular-ruby-implementations
require 'benchmark'
class Dummy
def one
1
end
end
@gregspurrier
gregspurrier / gist:916727
Created April 13, 2011 00:16
ree-1.8.6 install failure
gspurrie-mn:~% rvm --version
rvm 1.6.2 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]
gspurrie-mn:~% rvm install ree-1.8.6
Installing Ruby Enterprise Edition from source to: /Users/gspurrie/.rvm/rubies/ree-1.8.6-20090610
ree-1.8.6-20090610 - #fetching (ruby-enterprise-1.8.6-20090610)
ree-1.8.6-20090610 - #extracting ruby-enterprise-1.8.6-20090610 to /Users/gspurrie/.rvm/src/ree-1.8.6-20090610
ree-1.8.6-20090610 - #installing
Removing old Rubygems files...
@gregspurrier
gregspurrier / gist:1264972
Created October 5, 2011 16:47
Anonymous controller bug?
gspurrie-mn:proj% rvm use ruby-1.8.7@rspec_bug --create
Using /Users/gspurrie/.rvm/gems/ruby-1.8.7-p352 with gemset rspec_bug
gspurrie-mn:proj% gem install bundler
Fetching: bundler-1.0.21.gem (100%)1.0.21.gem
Successfully installed bundler-1.0.21
1 gem installed
Installing ri documentation for bundler-1.0.21...
Installing RDoc documentation for bundler-1.0.21...
gspurrie-mn:proj% gem install rails
@gregspurrier
gregspurrier / gist:1515426
Created December 23, 2011 21:39
Hash#without
class Hash
# Returns a new hash that does not contain the specified keys
#
# {:a => 1, :b => 2, :c =>3, :d => 4}.without(:a, :b)
# => {:c=>3, :d=>4}
def without(*keys)
dup.tap { |h| keys.each { |k| h.delete(k) } }
end
end
@gregspurrier
gregspurrier / k_lambda_spec.txt
Last active March 13, 2020 15:10
ShenRuby's K Lambda Spec (work in progress)
Atoms:
a string
is self-evaluating
a symbol
is self-evaluating
may include any of the legal characters for symbol
may begin with any legal character other than a digit
may not begin with a digit
numbers
@gregspurrier
gregspurrier / gist:5659105
Created May 27, 2013 21:10
specdoc output of KLaSC as of May 27, 2013.
Testing KLamba specification compliance of:
Shen 2010, copyright (C) 2010 Mark Tarver
released under the Shen license
www.shenlanguage.org, version 11
running under Common Lisp, implementation: CLisp
port 1.5 ported by Mark Tarver
@gregspurrier
gregspurrier / foo.txt
Created July 1, 2013 02:50
Example that is crashing emacs when used with mmm-mode on OS X
= Some document
== Huzzah
[source,ruby]
----
# This should be ruby code
1.times do
puts "hello world"
end
@gregspurrier
gregspurrier / sequence.scala
Last active December 29, 2015 23:49
Sequence wildcards and sequence arguments in Scala
import scala.collection.immutable.Queue
val q = Queue(1, 2, 3)
// When pattern matching against a sequence, the sequence wildcard _*
// can be used as the last pattern and will match an arbitrary number of
// elements. To bind the matched sequence to a variable, use the form
// `x @ _*`:
val restSeq = q match { case Queue(x, xs @ _*) => xs }
// --> rest: Seq[Int] = Queue(2, 3)
@gregspurrier
gregspurrier / gist:9414181
Created March 7, 2014 15:58
A tmux binding for opening the URL or path contained in the paste buffer in OS X
# Send the paste-buffer to the open command
bind u run-shell "tmux show-buffer | xargs open"