Author: Ezekiel Templin
Date: February 06, 2011
Summary: Comparing Nokogiri's parsers
Operating System: Mac OS X 10.6.6 (10J567)
CPU: Intel Core i7 2.66 GHz
| class Page < Ohm::Model | |
| attribute :name | |
| attribute :html | |
| list :blocks, BlockContent | |
| index :name | |
| def validate | |
| assert_present :name | |
| end |
| result_objects = Google.search("something") do |results| | |
| results.map do |link| | |
| obj = build_object ... | |
| obj.title = link.content | |
| obj.url = link.href | |
| get(link.href) do |doc| | |
| obj.description = doc['div#desc'].content | |
| ... | |
| end |
| package_error() | |
| { | |
| local _message=$1 | |
| if [[ -z "${_message}" ]] | |
| then | |
| fail "Cannot print a package error as no message was provided." | |
| fi | |
| local _log=$2 | |
| if [[ -n ${_log} ]] && file_exists ${_log} |
| class Result | |
| # Possible attributes: | |
| # seller_name: String, nil | |
| # title : String, nil | |
| # description: String | |
| # price : Decimal | |
| def human_readable_on_base | |
| str = if self.title | |
| "#{self.title} " |
| class String | |
| def levenshtein other | |
| # .. left as exercise for the reader | |
| end | |
| class Object | |
| def method_missing meth, *args, &block | |
| meth_str = meth.to_s | |
| new_meth = self.methods.map do |m| | |
| [meth_str.levenshtein(m.to_s), m] |
| rvm use ruby-1.9.2 | |
| gem install open_gem | |
| gem sandbox install flog |
| def self.make_year(year, bias) | |
| # Check for year > 2 digits, etc | |
| # ... | |
| start_year = Chronic.time_class.now.year - bias | |
| century = (start_year / 100) * 100 | |
| full_year = century + year | |
| if full_year < start_year | |
| full_year + 100 | |
| else | |
| full_year |
| module MyMod | |
| class << self | |
| attr_reader :my_reader | |
| end | |
| attr_reader :my_other_reader | |
| module_function :my_other_reader | |
| end |
| #!/usr/bin/env bash | |
| if [[ -s "/Users/chaos/.rvm/environments/ruby-1.9.2-p180@global" ]] | |
| then | |
| source "/Users/chaos/.rvm/environments/ruby-1.9.2-p180@global" | |
| exec ruby "$@" | |
| else | |
| echo "ERROR: Missing RVM environment file: '/Users/chaos/.rvm/environments/ruby-1.9.2-p180@global'" >&2 | |
| exit 1 | |
| fi |