Skip to content

Instantly share code, notes, and snippets.

@Pistos
Pistos / Result
Created November 1, 2008 13:37 — forked from chuyeow/Result
hpricot vs. nokogiri: Parsing XML
..........
Set 1 mean: 5.368 s
Set 1 std dev: 0.052
Set 2 mean: 0.703 s
Set 2 std dev: 0.054
p.value: 1.0825088224469e-05
W: 100.0
The difference (-86.9%) IS statistically significant.
@Pistos
Pistos / Notes
Created November 7, 2008 22:57
Using better-benchmark.
I got a segfault when I tried to run this at first, and am now getting lots of
"called on terminated object" at random times (!). Wondering what to do at this
point...
hpricot 0.6.170
nokogiri 1.0.2
ruby 1.8.7 (2008-06-20 patchlevel 22) [i686-linux]
--------------------
#!/usr/bin/env ruby
require 'time'
#Dir.chdir("/project/prd/Builds/")
Dir.chdir( "/project/prd/Builds/nc/logs" )
class Capture < Regexp
def NamedMatches( string, names )
theMatches = match( string )
require 'hpricot'
require 'json'
require 'open-uri'
class Feed
def self.parse( uri )
doc = Hpricot.XML(open(uri))
feed = new(uri)
if doc.at(:item)
@Pistos
Pistos / gist:58562
Created February 5, 2009 05:38
"while true" is faster than "loop do"
require 'better-benchmark'
result = Benchmark.compare_realtime(
:iterations => 10,
:inner_iterations => 10,
:verbose => true
) {
count = 0
while true
count += 1
require 'ramaze'
require 'ramaze/spec/helper'
spec_require 'hpricot', 'sequel'
$LOAD_PATH.unshift base = __DIR__('..')
require 'start'
describe 'Wikore' do
behaves_like 'http'
@Pistos
Pistos / README
Created February 11, 2009 04:58
100% CPU with Thin and Ruby 1.9
With this code, CPU usage shoots to 100% when serving the index page.
% gem19 list -l
*** LOCAL GEMS ***
daemons (1.0.10)
diakonos (0.8.7)
#!/usr/bin/env ruby19
require 'rexml/document'
class XMLGenealogy
INDENTATION = ' '
def initialize( argv )
@namespace_uri = argv[ 0 ]
@dir_mask = argv[ 1 ]
require 'nokogiri'
doc = Nokogiri::XML( "<xml></xml>" )
doc.xpath( "//*" ).each do |element|
p = element.parent
if p
# p not nil
p.namespace # causes segfault
end
end
@Pistos
Pistos / push-to-integrity-post-receive
Created April 8, 2009 14:15
git post-receive hook script which makes Integrity rebuild. Place in hooks/ dir of receiving bare repo.
#!/usr/bin/env ruby19
require 'net/http'
require 'uri'
require 'json'
# EDIT POST_RECEIVE_URL
POST_RECEIVE_URL = 'http://hostname:8910/repository-name/push'
old_head, new_head, ref = STDIN.gets.split