Skip to content

Instantly share code, notes, and snippets.

use v6.d;
use NativeCall;
class winsize is repr('CStruct') {
has uint16 $.rows;
has uint16 $.cols;
has uint16 $.xpixels;
has uint16 $.ypixels;
method gist() {
#ifdef _WIN32
#include <windows.h>
#endif
#define MAX_PATH_LENGTH 260
void transform_path(char *path) {
#ifdef _WIN32
// Check if path is already a long path
if (strlen(path) >= 7 && strncmp(path, "\\\\?\\", 4) == 0) {
@ugexe
ugexe / gist:b1b72ed0fd57069ff5533dfc03a95532
Last active December 8, 2021 02:16
Don't include e.g. home or root directories as a module path
C:\Users\ugexe>raku --ll-exception -e "use lib '.'; use Test;"
read from dirhandle failed: 123
at SETTING::src/core.c/Rakudo/Internals.pm6:1345 (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.c.setting.moarvm:next)
from SETTING::src/core.c/Rakudo/Internals.pm6:1374 (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.c.setting.moarvm:pull-one)
from SETTING::src/core.c/Any-iterable-methods.pm6:326 (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.c.setting.moarvm:pull-one)
from SETTING::src/core.c/Any-iterable-methods.pm6:335 (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.c.setting.moarvm:pull-one)
from SETTING::src/core.c/CompUnit/Repository/FileSystem.pm6:283 (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.c.setting.moarvm:dist-from-ls)
from SETTING::src/core.c/CompUnit/Repository/FileSystem.pm6:238 (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.
@ugexe
ugexe / words.pl
Last active April 18, 2019 01:48
Polyglot Perl5/6 print words that can be spelled from given input letters
# perl|perl6 words.pl word_list.txt f o o b a r b a z
my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
sub polyslurp ($_) { "0" and (return "{$_.IO.slurp}") or (return do { open(my $fh, $_[0]); join("", <$fh>); }) };
my $filename = shift(@ARGV);
my @words = split("\n", polyslurp($filename));
my $input_letters = {};
$input_letters{lc($_)} += 1 for @ARGV;
@ugexe
ugexe / pi.pl
Last active April 18, 2019 01:35
Polyglot Perl5/6 print pi digits based on script size
sub eval($_) { &EVAL($_) };
sub polyint($_) { "0" and (return Int($_[0])) or (return int($_[0])) };
sub script_size { "0" and (return 0+eval('$*PROGRAM.IO.s')) or (return 0+eval('-s $0')) };
#`() use isms; sub infix:«<<»($a,$b) { $a +< $b };
my $digits = script_size() + 1;
my (@out, @a);
my ($b, $c, $d, $e, $f, $g, $i, $d4, $d3, $d2, $d1);
$b = $d = $e = $g = $i = 0;
@ugexe
ugexe / hamming.pl
Created April 11, 2019 02:56
Polyglot Perl5/6 hamming numbers
my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
my $numbers_tried = 0;
my $numbers_found = 0;
NUMBERS: while ($numbers_found != @ARGV[0]) {
$numbers_tried++;
my $state = $numbers_tried;
while ($state != 1) {
@ugexe
ugexe / pascal.pl
Last active April 11, 2019 02:55
Polyglot Perl 5/6 pascals triangle
my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
my @state = (1,);
for (1 .. @ARGV[0]) {
print(join(" ", @state), "\n");
my @row = map &{ sub ($_) { @state[$_] + (@state[$_ + 1] // 0) } }.(), (0 .. ($_ - 2));
@state = ();
push(@state, 1);
push(@state, $_) for @row;
push(@state, 1);
}
@ugexe
ugexe / dld.pl
Last active April 6, 2019 07:02
Polyglot Perl 5/6 levenshtein damerau algorithm implementation
sub polymin (*@_) { (@_[0] > @_[1]) and (return @_[1]) or (return @_[0]) }
sub polymax (*@_) { (@_[0] > @_[1]) and (return @_[0]) or (return @_[1]) }
sub polychars (*@_) { 0+grep &{ sub ($_) { $_ ne "" } }.(), split("", @_[0]) }
sub polytern (*@_) { (@_[0]) and (return @_[1]) or (return @_[2]) }
sub dld (*@_) {
my $source = @_[0];
my $target = @_[1];
my $max = @_[2];
my $sourceLength = polychars($source);
@ugexe
ugexe / InstallationWithHook.pm6
Last active July 7, 2018 01:14
Perl6 post-install hook
# PERL6LIB="/Users/ugexe/repos/CompUnit-Repository-InstallationWithHook/lib"\
# perl6 -I /Users/ugexe/repos/zef /Users/ugexe/repos/zef/bin/zef\
# -to="CompUnit::Repository::InstallationWithHook#/Users/ugexe/.rakudobrew/moar-blead-master/install/share/perl6/site"\
# install /Users/ugexe/repos/zef
class CompUnit::Repository::InstallationWithHook is CompUnit::Repository::Installation {
method short-id { 'inst-with-hook' }
method path-spec { $.short-id ~ '#' }
multi method install(Distribution $dist) {
return unless my $result = callsame();
@ugexe
ugexe / zef-web-api-poc-gql.pl6
Created October 15, 2017 06:10
Perl 6 module metadata microservice that uses installed modules as the data source to both RESTful-ish and GraphQL APIs
#!/usr/bin/env perl6
use v6;
use Cro::HTTP::Server;
use Cro::HTTP::Router;
use Cro::HTTP::BodyParser;
use GraphQL;
require GraphQL::GraphiQL;
# THE DATABASE/MODEL READS/INDEXES DIRECTLY FROM THE MODULES INSTALLED ON YOUR SYSTEM