This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model < ActiveRecord::Base | |
STATES = %w[ inactive active processing ] | |
validates_inclusion_of :state, :in => STATES | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
li { color: #f00; } | |
li span { color: #0f0; } | |
/* Like a Christmas tree! */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is just a naive tree implementation, I couldn't find anything on Google | |
# that was instantly helpful, so I figured it out on my own. Turns out it was | |
# not too bad. | |
class Node | |
def initialize(name = nil, &block) | |
@name = name | |
@children = [] | |
yield self if block_given? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Now all I have to do is make it work :-/ | |
scraper do |doc| | |
doc.css('.user-details', :on_missing => :halt) do |n| | |
n.css('.name') do |nn| | |
nn.emit do |content| | |
first, last = *content.split | |
{ :first_name => first, :last_name => last } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some more pondering for my ScrapeKit normalizer builder. I keep throwing | |
# different use-cases at it which keeps causing me to change my design. I think | |
# I am starting to get to a happy place. | |
normalizer do |doc| | |
doc.collect :inventories, 'table[width="66%"] tr', :exclude => [0, -1, 'UNKNOWN QUANTITY'], :missing => :halt do |tr| | |
tr.all 'td[width="25%"]', :include => [1..3] do |(name, _, quantity)| | |
name.select(:name, :format => [:titlecase]) | |
quantity.select(:quantity, :format => [:to_i]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'benchmark' | |
require 'amatch' | |
def levenshtein(a, b) | |
return b.length if a.empty? | |
return a.length if b.empty? | |
asub = a[1..-1] | |
bsub = b[1..-1] | |
offset = (a[0] == b[0] ? 0 : 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LCBO | |
class SearchSuggest | |
STOP_WORDS = %w[ woods ] | |
require 'amatch' | |
require 'stringex' | |
def initialize(db) | |
@db = db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'> | |
<head> | |
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> | |
<title>LCBO API Examples</title> | |
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js' type='text/javascript'></script> | |
<script type='text/javascript'> | |
$(document).ready(function() { | |
$('form').submit(function(event) { | |
event.preventDefault(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-----------------------------------------------------------+ | |
| | | |
| Kieran Huggins r e f a c t o r y | | |
| Important Businessman | | |
| 123 Fake St. M4R 2G4 | | |
| 1 (416) 943-4483 | | |
| | | |
| | | |
| Surf to us on the information super-highway! | | |
| HTTP://REFACTORY.ON.CA | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rainbow' | |
@tests = File.readlines('test_unit.out'). | |
map { |line| line.strip }. | |
map { |line| line.sub(/ s: (\.|F)\Z/, '') }. | |
map { |line| line.split(' : ') }. | |
map { |test| { :name => test.first, :time => test.last.to_f } } | |
def report(name, color, limit = 10, &filter) | |
puts "\n#{limit} #{name} tests:".bright.foreground(color) |