Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Dalessio flavorjones

View GitHub Profile
@flavorjones
flavorjones / rdeps.rb
Last active Jul 14, 2021
Find transitive dependencies of a gem, sort by number of downloads
View rdeps.rb
#! /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 Jun 19, 2021
reproduce Ruby memory usage error in `iseq_peephole_optimize`
View _README.md

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 / 2021-03-06_stats.md
Last active Mar 6, 2021
Nokogiri downloads by architecture
View 2021-03-06_stats.md

v1.0 45,557 / 2008-10-30

  • ruby: 31,817 (69.84%)
  • x86-mswin32: 13,740 (30.16%)

v1.1 15,989 / 2008-12-21

  • ruby: 8,547 (53.46%)
  • x86-mswin32: 4,616 (28.87%)
  • java: 2,826 (17.67%)

v1.2 40,968 / 2009-02-22

@flavorjones
flavorjones / foo.rb
Created Nov 5, 2020
Nokogiri::XML::Node serialization
View foo.rb
#! /usr/bin/env ruby
# related to https://groups.google.com/g/nokogiri-talk/c/XoKIzgbcBpU/m/9o3tbD6WCQAJ
require "nokogiri"
html = <<~EOF
<html>
<body>
<div>123 Fake St.<br>City, State&nbsp;65432</div>
@flavorjones
flavorjones / .gitignore
Last active Oct 10, 2020
Reproduce parse failure in `xmlParseCharData`
View .gitignore
ok.xml
fail.xml
run-me.o
run-me
@flavorjones
flavorjones / foo.rb
Created Aug 29, 2020
nokogiri support 2020-08-29
View foo.rb
#! /usr/bin/env ruby
require 'nokogiri'
input = <<EOF
<title> The journey </title>
</head>
<body>
<h1> The <index class = "estimate"> Trip </index> </h1>
<p> Our scavenger hunt consists of several stages, starting with the <index class = "treasure"> crossing </index> & mdash; how do we actually get to those islands. The nice thing about an intellectual quest is that we can be in all kinds of places at the same time. If we ever want to revisit a previous episode, all we have to do is click there, and even though we haven't finished a particular stage yet, we can already look ahead to the next. We can also keep in touch with fellow travelers who are in completely different places in the world of thought.
View process_kml.rb
#! /usr/bin/env ruby
require "nokogiri"
xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Document.kml</name>
<Placemark>
View Dockerfile
FROM ruby:2-alpine3.10
RUN apk add build-base imagemagick6-dev bash
WORKDIR /app
@flavorjones
flavorjones / Makefile
Last active Jan 18, 2019
nokogiri-1861-exponential-search-time
View Makefile
CFLAGS=$(shell pkg-config libxml-2.0 --cflags)
LDFLAGS=$(shell pkg-config libxml-2.0 --libs)
foo: foo.o
$(CC) -o foo foo.o $(LDFLAGS)
foo.o: foo.c
$(CC) $(CFLAGS) -c -o foo.o foo.c