View gist:25668c47d9a05dc48cd7
1 2 3 4 5 6 7 8 9 10
require 'oga'
 
document = Oga.parse_xml <<-EOF
<pricing_information>
<cents>
10
</cents>
<currency>
EUR
</currency>
View gist:6fb4620c41783f475bb3
1 2 3 4 5 6 7 8 9 10
<link rel="shortcut icon" href="/favicon2.gif">
<html>
<body></body>
<body background="/Test_2.gif"></body>
<body onload="blink();">
 
<div align="center"></div>
 
<TITLE>Site Name</TITLE>
</body>
View 0001-Added-a-simple-Maybe-monad.patch
1 2 3 4 5 6 7 8 9 10
From a31eb2863043937881e51cffb544ef9a641a62af Mon Sep 17 00:00:00 2001
From: Yorick Peterse <SNIP>
Date: Thu, 12 Mar 2015 11:08:46 +0100
Subject: [PATCH] Added a simple Maybe monad.
 
This is a rather simple implementation of the Maybe monad [1] / Option type [2].
It only provides the absolute bare-minimum instead of providing a fully blown
functional programming library.
 
Using this class allows you to turn code such as this:
View gist:434e361be76e37fb34ac
1 2 3 4 5 6 7 8 9 10
Starting program: /home/yorickpeterse/.rubies/rbx-git/bin/ruby test.rb
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffd75ff700 (LWP 350)]
[New Thread 0x7fffd71fe700 (LWP 351)]
[New Thread 0x7ffff45bc700 (LWP 348)]
[New Thread 0x7ffff48f3700 (LWP 347)]
[New Thread 0x7ffff49f4700 (LWP 345)]
[New Thread 0x7ffff4af5700 (LWP 344)]
[New Thread 0x7ffff4bf6700 (LWP 343)]
View text.rb
1 2 3 4 5 6 7 8 9 10
class Text
def text=(value)
@raw_text = value
@text = nil
end
 
def text
unless @text
@text = Entities.decode(@raw_text)
@raw_text = nil
View mapping.rb
1 2 3 4 5 6 7 8 9 10
# Based on the JSON output as listed at
# http://www.w3.org/TR/html5/syntax.html#named-character-references
DECODE_MAPPING = {
"&Aacute;" => [193].pack('U'),
"&Aacute" => [193].pack('U'),
"&aacute;" => [225].pack('U'),
"&aacute" => [225].pack('U'),
"&Abreve;" => [258].pack('U'),
"&abreve;" => [259].pack('U'),
"&ac;" => [8766].pack('U'),
View bench_3320_each_cons.rb
1 2 3 4 5 6 7 8 9 10
require 'benchmark/ips'
 
module Enumerable
def each_cons(num)
n = Rubinius::Type.coerce_to_collection_index num
raise ArgumentError, "invalid size: #{n}" if n <= 0
 
return to_enum(:each_cons, num) {
if (enum_size = enumerator_size).nil?
nil
View gist:3835874051c0f36234f9
1 2 3 4 5 6 7 8 9 10
git clone git@github.com:YorickPeterse/oga.git
git checkout ruby-ll # if this complains, use git checkout -b ruby-ll origin/ruby-ll
bundle install
gem install oga
rake generate fixtures
 
# To benchmark the old parser, open benchmark/benchmark_helper.rb
# and replace the require_relative on line 5 with require 'oga'
 
# Then to benchmark it:
View gist:59bdb982a3afcda1a6cc
1 2 3 4 5 6 7 8 9 10
Starting program: /home/yorickpeterse/.rubies/rbx-git/bin/ruby -e Rubinius::VariableScope.new.locals
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff7f8f700 (LWP 15561)]
[New Thread 0x7ffff4cf7700 (LWP 15562)]
[New Thread 0x7ffff4bf6700 (LWP 15563)]
[New Thread 0x7ffff4af5700 (LWP 15564)]
[New Thread 0x7ffff49f4700 (LWP 15565)]
View gist:b659c906738a5ce54f66
1 2 3 4 5 6 7 8 9 10
Starting program: /home/yorickpeterse/Private/Projects/ruby/rubinius/staging/bin/rbx -e foo
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff7f8f700 (LWP 25155)]
[New Thread 0x7ffff4cf7700 (LWP 25156)]
 
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7066410 in pthread_join () from /usr/lib/libpthread.so.0
Something went wrong with that request. Please try again.