Skip to content

Instantly share code, notes, and snippets.

View flavorjones's full-sized avatar

Mike Dalessio flavorjones

View GitHub Profile
@flavorjones
flavorjones / Makefile
Last active August 11, 2023 21:10
2023-08-11 reproduction of libxml2 encoding behavior changes
CFLAGS=$(shell ./local/bin/xml2-config --cflags)
LDFLAGS=$(shell ./local/bin/xml2-config --libs)
foo: foo.o
$(CC) -o foo foo.o $(LDFLAGS)
foo.o: foo.c
$(CC) $(CFLAGS) -c -o foo.o foo.c
clean:
#! /usr/bin/env ruby
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "builder"
gem "nokogiri"
gem "benchmark-ips"
end
@flavorjones
flavorjones / Makefile
Last active April 30, 2023 13:05
repro of libxml2 memory leak in v2.11.0
CFLAGS=$(shell ./local/bin/xml2-config --cflags)
LDFLAGS=$(shell ./local/bin/xml2-config --libs)
foo: foo.o
$(CC) -o foo foo.o $(LDFLAGS)
foo.o: foo.c
$(CC) $(CFLAGS) -c -o foo.o foo.c
clean:
@flavorjones
flavorjones / README.md
Created November 22, 2022 18:27
patch of mkdocs-material search plugin to support rdoc

I should really make this into a real plugin when I get time. But for now it will do.

@flavorjones
flavorjones / redos-radar.rb
Created May 9, 2022 12:36
rough script to examine Ruby regexp literals with https://makenowjust-labs.github.io/recheck/
#! /usr/bin/env ruby
# coding: utf-8
# Copyright 2022 Mike Dalessio
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
CFLAGS = -std=c89
default: run
benchmark-O0.o: benchmark.c
$(CC) -O0 $(CFLAGS) -c -o benchmark-O0.o benchmark.c
lib-O0.o: lib.c
$(CC) -O0 $(CFLAGS) -c -o lib-O0.o lib.c
# 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
@flavorjones
flavorjones / rdeps.rb
Last active July 14, 2021 14:59
Find transitive dependencies of a gem, sort by number of downloads
#! /usr/bin/env ruby
#
# find transitive reverse dependencies of nokogiri with more than a million downloads: "rdeps.rb nokogiri 1000000"
#
require "bundler/inline"
gemfile do
gem "json"
gem "ruby-progressbar"
end
@flavorjones
flavorjones / _README.md
Last active June 19, 2021 16:14
reproduce Ruby memory usage error in `iseq_peephole_optimize`

This gist reproduces a memory usage error in Ruby's iseq_peephole_optimize.

  1. Compile Ruby with ASan (using CFLAGS="-fsanitize=address -ggdb")
  2. Turn off memory leak detection (which is not relevant)export ASAN_OPTIONS=detect_leaks=0
  3. Run ruby ./repro.rb

You should see something like:

before require
@flavorjones
flavorjones / Result
Created November 13, 2008 20:29 — forked from tenderlove/Result
XML Document parsing benchmark
user system total real
hpricot:xml:doc 10.160000 0.950000 11.110000 ( 11.144462)
hpricot2:xml:doc 0.950000 0.000000 0.950000 ( 0.953266)
nokogiri:compat:doc 0.220000 0.020000 0.240000 ( 0.238401)
nokogiri:xml:doc 0.170000 0.030000 0.200000 ( 0.200283)
XML XPath benchmarks (//status/text, //user/name)
user system total real
hpricot:xml:xpath 7.580000 1.150000 8.730000 ( 8.728314)