Skip to content

Instantly share code, notes, and snippets.

View flavorjones's full-sized avatar

Mike Dalessio flavorjones

View GitHub Profile
@flavorjones
flavorjones / 539-join-across-tables.patch
Created May 13, 2011 12:56
Patch containing failing test for rails/rails issue 539.
From 641e1e0bebdea1cf5ad4e156afe0ecb6a91241c4 Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike@csa.net>
Date: Fri, 13 May 2011 08:53:49 -0400
Subject: [PATCH] Test for table join across databases (connections).
---
.../test/cases/associations/join_model_test.rb | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb
# ---------- ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux] ----------
# ---
# warnings: []
#
# ruby:
# engine: mri
# version: 1.8.7
# platform: x86_64-linux
# libxml:
user system total real
json 3.260000 0.030000 3.290000 ( 3.320897)
xml (noko-dom) 21.080000 0.040000 21.120000 ( 21.412431)
xml (via Nokogiri DOM parsing) came in at only 6.4x slower than JSON.
codes at https://github.com/flavorjones/fairy-wing-throwdown
define session-ruby
source ~/.gdb/session-ruby
end
@flavorjones
flavorjones / small_table_caching.rb
Created February 18, 2011 14:42
Cache small data sets by wrapping the table with an ActiveHash model.
#
# Tired of Rails constructing SQL queries to keep loading the same
# small set of records over and over again?
#
# Well, cache those records in memory using ActiveHash!
# * https://github.com/zilkey/active_hash
#
require 'active_record'
require 'active_hash'
@flavorjones
flavorjones / Makefile
Created November 4, 2010 16:42
demonstrates libxml2 bug in xmlSAX2StartElementNs
foo: foo.o
$(CC) foo.o -g -o foo -lxml2
foo.o: foo.c
$(CC) foo.c -g -Wall -c -o foo.o -I/usr/include/libxml2
clean:
rm -f foo foo.o
#! /usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
html = "<html><body><div>hello</div></body></html>"
doc = Nokogiri::HTML html
div = doc.at_css "div"
# String Encoding, Nokogiri and You: A Primer
## First: A Few Thing To Consider
1. It is common for HTML pages to declare
1. Without information instructing it differently, Nokogiri's core library ([libxml2][]) will
[libxml2]: http://xmlsoft.org/
[meta-bug]: https://bugzilla.gnome.org/show_bug.cgi?id=579317
#! /usr/bin/env ruby
require "rubygems"
gem "faker"
gem "sqlite3-ruby"
gem "hitimes"
require "fileutils"
require "sqlite3"
xml file:
---
<match>
<id>1053</id>
<name>Южная Африка - Мексика</name>
<start>2010-06-11 18:00:00</start>
<status>finished</status>
<stage>Групповой этап</stage>
<stadium>Соккер Сити</stadium>
<judge>Равшан Ирматов</judge>