Skip to content

Instantly share code, notes, and snippets.

def foo
end
# This is my gist
import org.apache.http.client._
import org.apache.http.client.methods._
import org.apache.http.impl.client._
import scala.xml._
object S {
def main(args : Array[String]) : Unit = {
val root = scala.xml.XML.load((new DefaultHttpClient).execute (
new HttpGet("http://whoismyrepresentative.com/getall_sens_bystate.php?state="+args.head)
).getEntity.getContent)
class MorseEncoder
TRANSLATIONS = {
:a => "._",
:b => "_...",
:c => "_._.",
:d => "_..",
:e => "."
}
def method_missing(m, *args)
# use .each (or each_with_index) and iteration to implement these
array_of_numbers = [1,2,3,4,5]
number_to_add = 2
puts array_of_numbers.add_a_number_to_each_of_these_numbers(number_to_add)
# => [3, 4, 5, 6, 7]
list = [:name, 'Chad', :place, 'Virginia']
list.turn_into_hash
#https://gist.github.com/786350
module Names
def self.included(klass)
klass.extend ClassLevelMethods
klass.send(:attr_reader, :displayed_attribute_info)
end
def to_s
"<#{self.class.name} " +
self.class.displayed_attribute_info.map do |attr_name, label|
module Names
# TODO
end
Object.send(:include, Names)
class Person
displayed_attribute :name
displayed_attribute :age
displayed_attribute :ssn, :label => "Social Security Number"
class LoggerClass
def self.attr_logger(attribute_name)
class_eval "def #{attribute_name}; @#{attribute_name}; end"
class_eval "def #{attribute_name}=(val); @#{attribute_name} = val; end"
end
end
class Person < LoggerClass
attr_logger :age
attr_logger :name
class LoggerClass
def self.attr_logger(attribute_name)
iv_name = "@#{attribute_name}"
define_method(attribute_name) do
instance_variable_get(iv_name)
end
define_method("#{attribute_name}=") do |value|
STDERR.puts "setting #{attribute_name} to #{value}"
instance_variable_set(iv_name, value)
end
module Vocal
def speak
puts "#{self} says hello"
end
end
class Object
def ekstend(mod)
class << self
self