Skip to content

Instantly share code, notes, and snippets.

View dwarring's full-sized avatar

David Warring dwarring

  • The C Peoples
  • New Zealand
View GitHub Profile
use LibXML::Raw;
use LibXML::Parser::Context;
my $raw = xmlMemoryParserCtxt.new: :string<foo>;
my LibXML::Parser::Context $*XML-CONTEXT .= new: :$raw;
sub structured-error-cb($ctx, xmlError:D $err) {
$*XML-CONTEXT.structured-error($err);
}
$*XML-CONTEXT.raw.SetStructuredErrorFunc: &structured-error-cb;
for 1..250 {
$raw.ParseDocument;
#!/usr/bin/env raku
use PDF::IO::Reader;
#| strip non-deterministic data from ps2pdf output.
#| Ensure multiple runs produce exactly the same binary output
#| see https://www.mail-archive.com/debian-user@lists.debian.org/msg763682.html
sub MAIN(
Str $file-in, #= input PDF
Str $file-out = $file-in, #= output PDF (optional)
Str :$id = "wôBÚ¦Ø峧\x[9D]¡tõpÍ\x[16]",
use JSON::Fast;
sub MAIN(Str $meta6 = 'META6.json') {
## rename modules
my Hash $meta = from-json($meta6.IO.slurp);
my $module-updates = 0;
my $script-updates = 0;
for $meta<provides>.sort {
my $old = .value;
@dwarring
dwarring / rr.p6
Last active April 9, 2019 22:12
Unicode Russian Roulette
# The Following has about 1/6 chance of failing:
buf8.new((^134).pick xx 4).decode;
CATCH { default {die "BANG!"} }
note "click";
use PDF;
use PDF::API6;
my PDF::API6 $pdf .= open: "/tmp/idaho.pdf";
my PDF $fdf .= open: "/tmp/flds.fdf";
my @pdf-fields = $pdf.fields.map: *.key;
my @fdf-fields = $fdf<Root><FDF><Fields>.map: *.<T>;
.say for @fdf-fields (-) @pdf-fields;
use v6;
enum MyEnum <zero one two three>;
my $a = 3;
given $a {
when one {say "one"}
when two {say "two"}
when three {say "three"}
npm http 304 https://registry.npmjs.org/sha1
npm http GET https://registry.npmjs.org/nqp-js-io
npm http 404 https://registry.npmjs.org/nqp-js-io
npm ERR! TypeError: Object.keys called on non-object
npm ERR! at Function.keys (native)
npm ERR! at installTargetsError (/usr/lib/node_modules/npm/lib/cache.js:708:24)
npm ERR! at /usr/lib/node_modules/npm/lib/cache.js:638:10
npm ERR! at saved (/usr/lib/node_modules/npm-registry-client/lib/get.js:148:7)
npm ERR! at /usr/lib/node_modules/graceful-fs/polyfills.js:133:7
npm ERR! at Object.oncomplete (fs.js:108:15)
@dwarring
dwarring / prof6.sql
Last active April 27, 2018 08:14
Pastable Rakudo profile routines query (https://docs.perl6.org/language/performance)
.mode columns
.headers on
.width 80
select
case when r.name = "" then "<anon>" else r.name end || " / " || r.file as "name/file",
r.line as "line",
sum(entries) as entries,
sum(case when rec_depth = 0 then inclusive_time else 0 end)/1000.0 as "inclusive(s)",
sum(exclusive_time)/1000.0 as "exclusive(s)"
from
@dwarring
dwarring / gist:8e11f55207990944c0c9
Last active October 31, 2015 18:34
Perl6 Proxys getting hammered
class C {
has $!foo;
method foo is rw {
say "foo";
$!foo;
}
has $!bar;
method bar is rw {
Proxy.new(
sub repeat(Str $input --> Rat) {
my $phrase := :36($input);
my $l := (36 ** $input.chars) - 1;
$phrase/$l;
}
say (repeat('sixrocks') * 36 ** 40).base(36);