Skip to content

Instantly share code, notes, and snippets.

View czottmann's full-sized avatar
💭
Sure.

Carlo Zottmann czottmann

💭
Sure.
View GitHub Profile
# The problem is that the Person object currently has two sub-objects:
# PersonFirstname and PersonLastname, and both have a @value attribute, which
# is suboptimal.
# Is there a way to end up with a Person object that has both @firstname and
# @lastname, without extraneous child objects?
class PersonFirstname
include HappyMapper
tag "firstname"
module HappyMapper
class Item
private
def value_from_xml_node(node, namespace=nil)
node.register_default_namespace(namespace.chop) if namespace
if element?
depth = options[:deep] ? './/' : ''
result = node.find_first("#{depth}#{namespace}#{tag}")
if tag.match(/\/@[a-z\d]+$/i)
describe "Kernel#retryable" do
it "should not affect the return value of the block given" do
retryable { 'foo' }.should == 'foo'
end
it "should not affect the return value of the block given when there is a retry" do
num_calls = 0
ret_val = retryable_deluxe do
num_calls += 1
class MyClass
attr_reader :myvar
def initialize
@myvar = "omg"
do_stuff
end
def do_stuff
#!/usr/bin/python
# Found @ http://darkreverser.wordpress.com/2008/02/13/new-blog
# Changelog
# 0.01 - Initial version
# 0.02 - Huffdic compressed books were not properly decrypted
import sys,struct,binascii
(.)(.)
class User < ActiveRecord::Base
validates_uniqueness_of :email, :case_sensitive => false
validate :valid_email?
private
def valid_email?
address = EmailVeracity::Address.new(email)
config.gem "heycarsten-email-veracity", :lib => "email_veracity"
begin
retryable( :tries => 2 ) do
Timeout::timeout(5) do |t|
xml_string = open( my_url, "User-Agent" => "Firefox/2.0" ).read
end
end
rescue Timeout::Error
LOG.error("Timeout error: #{$!} (#{my_url})")
God.watch do |w|
# ...
# Setting ENV variables for your script.
w.env = { "WORKER_ID" => "12" }
# Allow STDOUT and capture it to a log file.
w.log = "path/to/stdout/log/file.log"
# ...