The following code came up during a code review:
def self.account_for(email)
@account_for ||= {}
return @account_for[email] if @account_for.include?(email)
@account_for[email] = Account.find(email)
end
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
require "celluloid" | |
class BustedActor | |
include Celluloid | |
include Celluloid::Logger | |
def works_great; 42 end | |
def broken; raise "hell" end | |
end |
The following code came up during a code review:
def self.account_for(email)
@account_for ||= {}
return @account_for[email] if @account_for.include?(email)
@account_for[email] = Account.find(email)
end
#!/usr/bin/env ruby | |
# copied from https://gist.github.com/939696, and | |
# edited to add redis (which is where I was experiencing the issue) | |
require 'rubygems' | |
require 'net/http' | |
require 'hiredis' | |
require "redis/connection/hiredis" | |
require 'redis' |
# I have a new feature that primarily deals with a single class. It's a | |
# relatively small and self contained feature; I don't expect that other | |
# features will ever develop dependencies on it, but it will be highly | |
# dependant on the single class that it deals with. For various reasons, it | |
# isn't appropriate to make an Observer class. I'd like to keep all of the | |
# code pertaining to this feature highly cohesive (localized, in one file if | |
# possible). But it does make some specific demands of the class that it's | |
# coupled with. | |
module FooTask |
# See http://tools.ietf.org/html/rfc3501#section-9 | |
# INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1 - Formal Syntax | |
module IMAP | |
grammar Astring | |
# astring = 1*ASTRING-CHAR / string | |
rule astring | |
ASTRING_CHAR+ / string | |
end |
module SugaredResqueJob | |
def self.new(queue, resque=Resque, &perform) | |
Module.new do | |
extend self | |
define_method :queue do queue end | |
define_method :enqueue do |*args| resque.enqueue(self, *args) end | |
define_method :perform do |*args| perform.call( *args) end | |
end | |
end | |
end |
# in response to https://twitter.com/#!/avdi/status/138513455622791168 | |
# Yes, resque's enqueue API is wacky, but in practice it's not a problem, | |
# because it's trivial to route around. | |
# This is untested, and skips any resque enqueue hooks you might have setup. | |
# but those aren't major hurdles to fix. | |
class ResqueQueueWrapper | |
def initialize(queue, resque=Resque) | |
@queue = queue |
irb(main):031:0> start = Time.now; 10_000_000.times { 'foo' }; puts Time.now - start
=> 2.154165
irb(main):032:0> start = Time.now; 10_000_000.times { "foo" }; puts Time.now - start
=> 2.177029
Remind me again, why do I care about 23 milliseconds for every 10 million string loads? Methinks that just one instance of needing to change single quotes to double quotes so you can do some interpolation that you hadn't originally
#!/usr/bin/env ruby | |
module TopLevel | |
CONST_D = :d_from_top_level | |
module MiddleLevel | |
class BottomLevel | |
CONST_A = :foo | |
CONST_B = :bar | |
CONST_C = :c_from_bottom_level |
#!/usr/bin/env ruby | |
module M | |
extend self | |
def foo | |
"hello world" | |
end | |
private |