Skip to content

Instantly share code, notes, and snippets.

View heycarsten's full-sized avatar

Carsten Nielsen heycarsten

View GitHub Profile
# I was thinking about it, and thought if you were going to do "mixins" in Haml
# then they ought to work in a predictable way. In ERB you can simply define a
# method and place more ERB inside of it. This does not work in Haml, but maybe
# it should.
require 'sinatra'
require 'haml'
get '/erb' do
erb :test_erb
Wed Jun 9 16:44:08 Assertion: 10338:Invalid use of reserved field name
0x10005fd97 0x100032db5 0x1000388be 0x100021884 0x100034660 0x100031769 0x100038a0d 0x100021884 0x100034660 0x100021884 0x10001e025 0x100229a10 0x10022afc1 0x100224fa0 0x100229777 0x100000f94
0 mongoimport 0x000000010005fd97 _ZN5mongo11msgassertedEiPKc + 487
1 mongoimport 0x0000000100032db5 _ZNK5boost6spirit4impl15concrete_parserINS0_11alternativeINS3_INS0_6actionINS0_4ruleINS0_7scannerIPKcNS0_16scanner_policiesINS0_24skipper_iteration_policyINS0_16iteration_policyEEENS0_12match_policyENS0_13action_policyEEEEENS0_5nil_tESH_EEN5mongo12fieldNameEndEEESL_EENS4_ISI_NSJ_20unquotedFieldNameEndEEEEESG_SH_E16do_parse_virtualERKSG_ + 261
2 mongoimport 0x00000001000388be _ZNK5boost6spirit4impl15concrete_parserINS0_11list_parserINS0_8sequenceINS4_INS0_4ruleINS0_7scannerIPKcNS0_16scanner_policiesINS0_24skipper_iteration_policyINS0_16iteration_policyEEENS0_12match_polic
@heycarsten
heycarsten / unit_test_report_thing.rb
Created June 3, 2010 04:47
Just a quickie I did to tell me what my (n) slowest and fastest tests are. Uses output that you can get when you pass TESTOPT="-v" to Rake::TestTask
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)
+-----------------------------------------------------------+
| |
| 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 |
<!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();
module LCBO
class SearchSuggest
STOP_WORDS = %w[ woods ]
require 'amatch'
require 'stringex'
def initialize(db)
@db = db
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)
# 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
# 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 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?