Skip to content

Instantly share code, notes, and snippets.

@fidothe
fidothe / eg.adoc
Last active April 6, 2022 19:57
Trying to generate a syntax-highlighted listing block from a macro (using AsciiDoctor)

Example

Here’s the macro in use:

rml::blah[]

And here’s the equivalent in-place listing block:

@fidothe
fidothe / README.md
Created March 30, 2021 20:13
An attempt to provide a minimal reproduction of a threading-related JRuby problem

While working on https://github.com/fidothe/saxon-rb I hit errors in production using a semi-experimental branch (https://github.com/fidothe/saxon-rb/tree/error-reporting) in a threaded XML-processing program.

The errors were the same NoMethodError: undefined method __jcreate_meta!' as in jruby/jruby#6160, and the program structure is almost identical save for some loading indirection thanks to the use of autoload.

I am running it in a CI-type environment where 20+ EC2 instances are spun up to process a large amount of data. Most, but not all, runs I'd have one instance's process crash with the error.

Creating an instance of the problem class (https://github.com/fidothe/saxon-rb/blob/error-reporting/lib/saxon/error_reporter.rb, EgClass in this reproduction case) on the main thread, rather than in the worker threads, has made the problem vanish entirely.

@fidothe
fidothe / gsub.log
Created November 11, 2019 19:41
Benchmark gsub/sub before and after https://github.com/jruby/jruby/pull/5952
BEFORE:
jruby [master] $ benchmark bench/core/string/bench_gsub.rb
Warming up --------------------------------------
gsub-string 83.418k i/100ms
gsub-regex 120.922k i/100ms
gsub-regex-block 82.905k i/100ms
gsub-string 96.724k i/100ms
gsub-regex 128.786k i/100ms
gsub-regex-block 83.732k i/100ms
gsub-string 100.446k i/100ms
@fidothe
fidothe / rake-spec_ruby_fast-1.8u131.log
Last active October 18, 2019 09:30
log from running jruby -S rake spec:ruby:fast on a fresh checkout using JDK 1.8
MSPEC: {:compile_mode=>"OFF", :format=>"d", :spec_target=>":fast", :jruby_opts=>"-I. --dev", :jit_threshold=>20, :jit_max=>-1, :objectspace_enabled=>true, :thread_pooling=>false, :reflection=>false}
rm -rf rubyspec_temp
JAVA options: {:dir=>"/work/jruby", :maxmemory=>"1024M", :resultproperty=>"spec.status.OFF", :fork=>"true", :failonerror=>"true", :classname=>"org.jruby.Main"}
$ /work/jruby/bin/jruby -J-ea -J-Djruby.launch.inproc=false -J-Djruby.compile.mode=OFF -J-Djruby.jit.threshold=20 -J-Djruby.jit.max=-1 -J-Djruby.objectspace.enabled=true -J-Djruby.thread.pool.enabled=false -J-Djruby.reflection=false -J-Demma.coverage.out.file=target/test-results/coverage.emma -J-Demma.coverage.out.merge=true -J-Demma.verbosity.level=silent -J-XX:MaxMetaspaceSize=512M /work/jruby/spec/mspec/bin/mspec-ci -f d :fast
jruby 9.2.9.0-SNAPSHOT (2.5.7) 2019-10-18 29935ad Java HotSpot(TM) 64-Bit Server VM 25.131-b11 on 1.8.0_131-b11 [darwin-x86_64]
/work/jruby/spec/ruby/core/module/attr_spec.rb:38: warning: optional boolean argum
@fidothe
fidothe / eg.rb
Last active October 14, 2019 11:08
Shows StackOverflow
require 'saxon/loader'
if ENV['ALT_SAXON_HOME']
Saxon::Loader.load!(ENV['ALT_SAXON_HOME'])
end
require 'saxon/item_type'
@fidothe
fidothe / eg.rb
Created June 27, 2016 20:11
application process
# The code smell: disjoint radio buttons reveal that some values that
# should have hung together didn't, and that there were also dependent
# fields (the data protection checkbox and the application form link)
# which were hanging around and being a little bit problematic
#
# A solution is to use one field that can hold several values, unlike the
# boolean which can only hold two.
#
# We can also introduce a VALUE OBJECT that represents this field and can
# also tell us which (if any) of the dependent fields are needed.
@fidothe
fidothe / main.rs
Last active November 29, 2015 17:01
Attempting to read a number out of an FFI struct-in-a-struct
use std::ffi::CString;
extern crate libc;
/* structs and enums-hiding-structs taken from libdvdread:
http://git.videolan.org/?p=libdvdread.git;a=blob;f=src/dvdread/dvd_reader.h;h=9c7be9d0d2dcaa7dd003b43ecc00fc791ffec657;hb=refs/heads/master
http://git.videolan.org/?p=libdvdread.git;a=blob;f=src/dvdread/ifo_read.h;h=97f4179f0ce95d00d1db0df136a0111a574e71a2;hb=refs/heads/master
http://git.videolan.org/?p=libdvdread.git;a=blob;f=src/dvdread/ifo_types.h;h=33f03467b375025ac78c0294e42c321df924ffae;hb=refs/heads/master
*/
pub enum DVDReader {}
pub enum DVDFile {}
@fidothe
fidothe / README.md
Last active July 26, 2017 20:35
How to build Torch with CUDA extensions with a Ubuntu 14.04 g2.* instance on EC2

I got Torch + CUDA working on a Ubuntu 14.04 g2.2xlarge EC2 instance using these instructions. Get the latest CUDA install package by consulting https://developer.nvidia.com/cuda-downloads#linux and grabbing the most recent. (7.0 at time of writing).

I also made a public AMI with this, plus Dan Hon's char-rnn fork pre-installed.

It's ami-9bcadbab, or dreaming-prose-public, in the us-west-2 (Oregon) region. You should be able to copy it to another region if you need to. You can launch an instance in the EC2 console at this URL: https://us-west-2.console.aws.amazon.com/ec2/v2/home?region=us-west-2#LaunchInstanceWizard:ami=ami-9bcadbab

You'll need a g2.2xlarge or g2.8xlarge instance or there'll be no CUDA for you...

@fidothe
fidothe / spec-dowser.rb
Created June 26, 2015 18:33
dowsing for spec ordering issues
# encoding: utf-8
SEED = 6514
BASE_CMD = "bundle exec rspec --fail-fast --seed #{SEED}"
all_potential_files = Dir['spec/controllers/**/*_spec.rb', 'spec/features/**/*_spec.rb']
definitely_involved = ['spec/controllers/concerns/x.rb', 'spec/features/y.rb']
potential_files = all_potential_files.to_a - definitely_involved
def attempt(files)
@fidothe
fidothe / pdfx.rb
Last active October 10, 2023 15:57
Worked example for creating a PDF/X-1a:2003 document with Prawn
require 'prawn'
require 'prawn/measurements'
# I have a small collection of links to the resources I used to figure all
# this out: http://pinboard.in/u:fidothe/t:pdfx
module PDFX
class PageBox
include Prawn::Measurements
attr_reader :bleed_mm