Skip to content

Instantly share code, notes, and snippets.

module MyAccessor
def method_missing(method_id, *args)
@storage ||= {}
m = method_id.to_s
missing_accessor = m[/get_(.*)/, 1]
return @storage[missing_accessor] if missing_accessor
missing_setter = m[/set_(.*)/, 1]
class ClassWithAttr
def self.my_attr_accessor(attr_name)
define_method("#{attr_name.to_s}=") do |arg|
instance_variable_set("@#{attr_name}", arg)
end
define_method("#{attr_name.to_s}") do
instance_variable_get("@#{attr_name}")
end
end
class EmployeeData
attr_accessor :first_name, :last_name
attr_accessor :dates
end
var record = EmployeeData.new("Dan", "Wellman", {
Date.new("1/1/2001") => 38.5 # hours actually worked on that day
})
data = [record]
@danielwellman
danielwellman / easypaymetrocard_charges.rb
Created July 20, 2012 19:29
Scrape Payment Receipts from the EasyPayMetroCard website
#! /usr/bin/env ruby
# Downloads "Payment Received" transactions from the EasyPayMetrocard
# website (www.easypaymetrocard.com").
#
# Requires capybara and capybara-webkit for headless JavaScript execution -
# the EasyPayMetroCard site requires JavaScript to obtain account activity.
#
# To install capybara-webkit, you must first install Qt, a cross-platform
# development kit. For instructions, see
@danielwellman
danielwellman / full_listen_queue.rb
Last active December 18, 2015 20:39
Spike to create a Bane behavior with a full listen queue.
require 'socket'
# This Behavior implements the same interface as BehaviorServer since we must set up our connection
# differently than GServer (the base class of BehaviorServer) does. This means we won't be able to define
# this behavior in the same was as other behaviors. Something will have to change to unify these.
class FullListenQueue
def initialize(port)
@port = port
end