Skip to content

Instantly share code, notes, and snippets.

@dakkar
dakkar / nqp::serialize.p6
Created December 19, 2018 17:01
vague idea to use nqp::serialize
use v6.d.PREVIEW;
# copied from https://github.com/FROGGS/p6-Ser/blob/master/lib/Ser.pm
sub serialize($obj is copy) {
use MONKEY-GUTS;
my Mu $sh := nqp::list_s();
my $name = 'Ser_' ~ nqp::time_n();
my Mu $sc := nqp::createsc(nqp::unbox_s($name));
@dakkar
dakkar / Makefile
Created January 30, 2019 17:27
the limits of GCC's unicode identifier support
CFLAGS=-std=c99
use-it: use-it.o symbol.o
symbol.o: symbol.c symbol.h
use-it.o: use-it.c symbol.h
@dakkar
dakkar / git-find-ref
Created May 4, 2019 14:19
getting remote name and ref from local ref
#!/bin/bash
# git find-ref $committish
#
# figure out which remote a committish comes from, and open its
# corresponding web view in a browser
#
# NOTE: doesn't work with tag names, I'm not sure if it's possible to
# know where a tag comes from
@dakkar
dakkar / splat-supply.p6
Created May 31, 2019 08:40
splat a supply inside another
use v6;
use experimental :macros;
macro splat-supply($b) { quasi { with {{{$b}}} { .tap:{ emit $_ }; .wait } } }
sub x { supply { emit 2; emit 3 } }
sub y { supply { emit 1; splat-supply x(); emit 4 } }
@dakkar
dakkar / perl-pod-indent.el
Created June 26, 2019 18:25
EMACS - indent Perl code inside POD
(defun dakkar/perl-indent (beg end)
(interactive "r")
(if (use-region-p)
(cond ((get-text-property beg 'in-pod)
(let* (
(text (buffer-substring beg end))
(indented-text (with-temp-buffer
(insert text)
(cperl-mode)
(cperl-indent-region 0 (buffer-size))
@dakkar
dakkar / vagrant-tramp-cache.el
Created June 26, 2019 18:26
EMACS - cache vagrant-tramp lookups
(require 'vagrant-tramp)
(defun dakkar-cache-vagrant (orig &rest args)
(let ((repo (pcache-repository "vagrant-tramp"))
(key 'all-boxes))
(if (pcache-has repo key)
(pcache-get repo key)
(let ((value (apply orig args)))
(pcache-put repo key value 300)
value))))
@dakkar
dakkar / accessor.pl
Created July 11, 2019 16:35
abusing perl5 subroutine signatures
#!/usr/bin/env perl
use 5.024;
use strict;
use warnings;
use experimental 'signatures';
package Foo {
sub new($class,%attrs) { bless \%attrs,$class }
sub thing($self,$value=return $self->{thing}) { $self->{thing} = $value }
};
@dakkar
dakkar / moon.pl
Created July 17, 2019 22:28
Dates of Easter according to the International Fixed Calendar
#!/usr/bin/env perl
use 5.024;
use strict;
use warnings;
use experimental 'signatures';
use Astro::MoonPhase ();
use DateTime;
use DateTime::Event::Easter;
# IFC = International Fixed Calendar
@dakkar
dakkar / match-vs-parse.p6
Last active December 27, 2019 21:28
be faster by doing more work?
feeding a 18kb email message, I get:
$ perl6 /tmp/p.p6 medium-sized-email-message.txt
slurping 0.00634555
matching 1.1612016
parsing 0.02143336
@dakkar
dakkar / Foo.rakumod
Created February 3, 2020 15:01
manual loading of Raku modules (e.g. plugins)
use v6.d;
unit class Foo;
has $.thing;