Skip to content

Instantly share code, notes, and snippets.

@dakkar
dakkar / matching-with-macros.raku
Last active February 22, 2024 16:18
role to execute a matching sub in raku
use v6.d;
use experimental :macros;
role mmm {
method ACCEPTS(Code:D: |c) {
dd self;dd c; # debugging!
return False unless c ~~ self.signature;
self.(|c);
return True;
}
@dakkar
dakkar / winsize.raku
Last active March 7, 2023 17:27
winsize ioctl in Raku
use v6.d;
use NativeCall;
class winsize is repr('CStruct') {
has uint16 $.rows;
has uint16 $.cols;
has uint16 $.xpixels;
has uint16 $.ypixels;
method gist() {
#!/usr/bin/env perl
use v5.26;
use strict;
use warnings;
package My::Thing {
use Moo;
has value => ( is => 'ro', required => 1 );
};
@dakkar
dakkar / obj.sh
Created July 10, 2020 11:47
I seem to have build a perl-like OO system in bash
#!/bin/bash
set -e
function class() {
current_class="$1"
}
declare -A _inheritance
function extends() {
_inheritance[$current_class]="$*"
@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;
@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 / 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 / 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 / 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 / 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))