Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / nomatch.pl
Created June 12, 2018 14:49
how to check what caused a negative lookahead to fail a regex (i.e. what it did match)
#!/usr/bin/env perl
use strict;
use warnings;
use 5.020;
use experimental 'signatures';
my @span=(-1,-1);
our $start=-1;
# this regex matches a series of -, some non-dashes that do not match
# 'some.{0,3}thing', and more dashes
@dakkar
dakkar / foo.pl
Created May 22, 2018 15:14
alternative to FindBin::libs
#!/usr/bin/perl
use strict;
use warnings;
use File::Spec;
my $libdir;
BEGIN {
my ($vol,$dirs,$file) = File::Spec->splitpath(__FILE__);
my @dirs = File::Spec->splitdir($dirs);
my $lib_dirs = File::Spec->catdir(@dirs,'lib');
$libdir = File::Spec->catpath($vol,$lib_dirs,'');
my @fizzes = (['','','Fizz'] xx *).flat;
my @buzzes = (['','','','','Buzz'] xx *).flat;
my @words = (@fizzes Z~ @buzzes);
my @numbers = 1 .. *;
my @fizzbuzz = (@numbers Z @words).map( *.max );
.say for @fizzbuzz[^20];
@dakkar
dakkar / tf.pl
Created May 9, 2018 15:12
weird interaction between `fork` and threads in perl 5 24.0
#!/usr/bin/env perl
use strict;
use warnings;
use 5.020;
use threads;
sub run_child {
my ($value) = @_;
my $tid = threads->tid;
@dakkar
dakkar / auth-toy.p6
Created December 8, 2017 12:48
Simple authentication+authorisation example with Cro
use v6.d.PREVIEW;
use Cro::HTTP::Router;
use Cro::HTTP::Middleware;
use Cro::HTTP::Response;
use Cro::HTTP::Server;
use Cro::Transform;
# mixin for requests, carrying authentication info
role AuthToy::Request::Authed {
has Str $.user;
@dakkar
dakkar / HelperThing.pm
Created October 26, 2017 09:38
Example of method traits in Moose
package HelperThing;
use strict;
use warnings;
use Moose::Exporter;
use 5.024;
use experimental 'signatures';
use MethodMetaRole;
sub my_method($meta,$name,@args) {
my $body = pop @args;