Skip to content

Instantly share code, notes, and snippets.

View benhamill's full-sized avatar
💖

Ben Hamill benhamill

💖
View GitHub Profile
@benhamill
benhamill / rant.md
Created February 2, 2013 04:29
How I Want Ruby's `Object#method` To Work

How I Want Ruby's Object#method To Work

The simple case, is this guy:

> m = SecureRandom.method(:hex)
=> #<Method: SecureRandom.hex>
> m.call
=> "5928aab178404945fb560a249b67a000"
> m.call
MIME-Version: 1.0
Received: by 10.50.16.79 with HTTP; Mon, 28 Jan 2013 08:20:01 -0800 (PST)
Date: Mon, 28 Jan 2013 10:20:01 -0600
Delivered-To: benhamill@otherinbox.com
Message-ID: <CAC3jhfzy+m8u5_hDKMnXCn2A2K9jK1o4Y=NBj0narA4=L7bbjQ@mail.gmail.com>
Subject: Test
From: Ben Hamill <benhamill@otherinbox.com>
To: Ben Hamill <benhamill@otherinbox.com>
Content-Type: multipart/alternative; boundary=e89a8f234cd728710704d45ba6e3
package main
import (
"log"
"flag"
"time"
"net"
"fmt"
"bufio"
)
require 'foo'
class Bar
attr_reader :foo
def make_foo
@foo = Foo.new(self)
end
end
@benhamill
benhamill / option_3.rb
Created November 13, 2012 20:34 — forked from kerinin/gist:4068172
Conditional organization
# Option 1
if eea_exists?
if eea_uses_something?
if eea_ever_used_application?
if eea_currently_uses_application?
recreate_eea; reactivate_application_for_eea; create_session; #13S
else
recreate_eea; reactivate_application_for_eea; create_session; #13S
end
else
describe User do
describe "#serialize_comments" do
before do
subject.stub(:read_comment_count).and_return(3)
subject.stub(:unread_comment_count).and_return(5)
end
it "does something when there are 5 unread comments"
end
end
@benhamill
benhamill / code.rb
Created August 10, 2012 21:11
Define method has helpful stack traces, compared to other meta-programming stuff.
class Foo
%w(bar baz).each do |m|
define_method("say_#{m}") do
raise m.to_s
end
end
end
f = Foo.new
Problem Employee
Servers Bob
Background Jobs Brad
Database Ben
JavaScript Isaac
CSS Andy
Translations Ryan
Bad Smells Marcos
Dumb Words Brian
@benhamill
benhamill / foo.rb
Created March 23, 2012 03:25
How do all those variable-types work in different scopes?
class Foo
def self.bar
@bar ||= :self_bar
end
def self.bar=(b)
@bar = b
end
def bar
OmniAuth.config.on_failure do |env|
exception = env['omniauth.error']
error_type = env['omniauth.error.type']
strategy = env['omniauth.error.strategy']
Rails.logger.error("OmniAuth Error (#{error_type}): #{exception.inspect}")
ErrorNotifier.exception(exception, :strategy => strategy.inspect, :error_type => error_type)
new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{error_type}"