Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
@mattyoho
mattyoho / gist:1982760
Created March 6, 2012 01:35 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p0
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1982760)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p125 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@mattyoho
mattyoho / object_methods.clj
Created February 16, 2012 21:47
Reflect on an object's methods in Clojure
(use '[clojure.reflect :only [reflect]])
(use '[clojure.string :only [join]])
(defn inspect [obj]
"nicer output for reflecting on an object's methods"
(let [reflection (reflect obj)
members (sort-by :name (:members reflection))]
(println "Class:" (.getClass obj))
(println "Bases:" (:bases reflection))
(println "---------------------\nConstructors:")
@mattyoho
mattyoho / gist:1838553
Created February 15, 2012 19:57 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p0
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1333785)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@mattyoho
mattyoho / lithp.rb
Created February 6, 2012 03:47 — forked from fogus/lithp.rb
class Lisp
def initialize
@env = {
:label => lambda { |(name,val), _| @env[name] = val },
:quote => lambda { |sexpr, _| sexpr[0] },
:car => lambda { |(list), _| list[0] },
:cdr => lambda { |(list), _| list.drop 1 },
:cons => lambda { |(e,cell), _| [e] + cell },
:eq => lambda { |(l,r), _| l == r },
:if => lambda { |(cond, thn, els), ctx| eval(cond, ctx) ? eval(thn, ctx) : eval(els, ctx) },
@mattyoho
mattyoho / Action Mailer
Created February 2, 2012 20:43 — forked from fxn/Action Mailer
Ruby on Rails v3.2.0 CHANGELOGs
## Rails 3.2.0 (January 20, 2012) ##
* Upgrade mail version to 2.4.0 *ML*
* Remove Old ActionMailer API *Josh Kalderimis*
@mattyoho
mattyoho / lithp.rb
Created January 26, 2012 01:31 — forked from fogus/lithp.rb
class Lisp
def initialize
@env = {
:label => lambda { |(name,val), _| @env[name] = val },
:quote => lambda { |sexpr, _| sexpr[0] },
:car => lambda { |(list), _| list[0] },
:cdr => lambda { |(list), _| list.drop 1 },
:cons => lambda { |(e,cell), _| [e] + cell },
:eq => lambda { |(l,r), _| l == r },
:if => lambda { |(cond, thn, els), ctx| eval(cond, ctx) ? eval(thn, ctx) : eval(els, ctx) },
@mattyoho
mattyoho / action_endpoint.rb
Created January 6, 2012 03:13
Random fever-dream sketch of possible alternative to ActionController
endpoints do
resources :widgets
end
# map "/widgets/:id", :to => WidgetEndpointFactory.new(:show), :as => :widget_path
# ...
# etc.
module ActionEndpoint::Endpoint
def view(object)
@mattyoho
mattyoho / music_library.rb
Created December 20, 2011 16:49 — forked from stevenharman/music_library.rb
When wrapping AR behind an intentional interface, go explicit or generic/idiomatic?
# This is a record, as in a vinyl.
class Record < ActiveRecord::Base
belongs_to :user
belongs_to :album
# explicitly stating what is needed
def from_library_for_album(collector, album)
where(user_id: collector).where(album_id: album)
end
@mattyoho
mattyoho / array_initializer.rb
Created December 19, 2011 21:33
Interesting Array.new construction example
# Example pulled from https://github.com/raggi/typhoeus/blob/c683b7d2f0ba3fd01f962b9eb3e0a0307bd0f0f6/benchmarks/vs_nethttp.rb
q = Queue.new
threads = Array.new(calls) { Thread.new { q.pop.call } }
benchmark do |t|
t.report("net/http") do
responses = []
calls.times do |i|
@mattyoho
mattyoho / public_repos.rb
Created December 13, 2011 16:00
Get list of public repos for list of users
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'open-uri'
require 'rdiscount'
file_name = ARGV.shift
output = ''