Skip to content

Instantly share code, notes, and snippets.

View flavorjones's full-sized avatar

Mike Dalessio flavorjones

View GitHub Profile
An example of what default valgrind output looks like for MRI Ruby interpreter.
valgrind ruby hello-world.rb
@flavorjones
flavorjones / Makefile
Created July 27, 2009 06:33
Reproducing an apparent memory leak under JRuby FFI
libfoo.so:
$(CC) -shared -o libfoo.so foo.c
@flavorjones
flavorjones / README.markdown
Created August 19, 2009 05:46
Comparison of Loofah against other Ruby HTML sanitization libraries

Overview of the Benchmark

The following benchmark output was generated from the codes at http://github.com/flavorjones/loofah/tree/master/benchmark

These results show the performance of Loofah scrubbing methods against comparable methods from other common open-source libraries:

  • ActionView sanitize() and strip_tags()
  • Sanitize sanitize()
#! /usr/bin/ruby
# in response to ruby-talk email of 2010-01-12 from Anandh Kumar
xml = <<EOX
<root>
<row>
<column>Business Strategy</column>
<column>bus1</column>
</row>
<row>
#
# My options when writing a gem containing non-Ruby code
#
| Your support burden | MRI? | Rubinius? | MacRuby? | JRuby? | Google App Engine? |
|-------------------------+------+-----------+----------+--------+--------------------|
| Two branches: FFI and C | YES | YES | YES | YES* | NO |
| Two branches: JVM and C | YES | YES | YES | YES | YES |
| One branch: FFI | YES* | NO-ish | NO | YES* | NO |
| One branch: C | YES | YES | YES | NO | NO |
#! /usr/bin/env ruby
require 'benchmark'
N = 100_000
puts "Pessimistic:"
Benchmark.bm(50) do |bm|
array = []
1.upto(N) do
INCLUDE_PATH=/home/mike/.multixml2/install/libxml2-2.7.3/include/libxml2
LIBRARY_PATH=/home/mike/.multixml2/install/libxml2-2.7.3/lib
replace-bug: replace-bug.c
gcc replace-bug.c -o replace-bug -I$(INCLUDE_PATH) -Bstatic -L$(LIBRARY_PATH) -lxml2
#!/usr/bin/env ruby
require 'nokogiri'
md = "<p>hello</p> <h1>goodbye</h1> <p>kiss it</p> <p>hello</p> <h1>goodbye</h1> <p>kiss it</p>"
loop {
frag = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new, md)
GC.start
STDERR.putc "."
def test_auto_closing_tags
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
<xml><city>Paris</city><state/></xml>
eoxml
assert_equal [false, false, nil, nil, true, nil],
reader.map{|node| node.empty_element? if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE}
end
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>