Skip to content

Instantly share code, notes, and snippets.

View jonathanstowe's full-sized avatar

Jonathan Stowe jonathanstowe

View GitHub Profile
@jonathanstowe
jonathanstowe / euclid
Created January 18, 2015 15:13
Euclidean algorithm calculating a "bitmap"
#!/usr/bin/perl
use strict;
use warnings;
my ( @count, @remainder );
sub build_string
{
@jonathanstowe
jonathanstowe / termcap value
Last active August 29, 2015 14:17
Termcap string value grammar attempt
#!perl6
use v6;
=begin code
Original perl 5
s/\\E/\033/g;
s/\\(\d\d\d)/pack('c',oct($1) & 0177)/eg;
{
"file-count" : 107,
"dist-count" : 7,
"dists" : [
{
"id" : 0,
"name" : "File::Find",
"auth" : null,
"ver" : "*",
"description" : "Bla bla",
@jonathanstowe
jonathanstowe / euclid.p6
Created March 29, 2015 00:06
Euclidean / Björlund / Toussaint algorith in Perl 6
#!perl6
use v6;
# From Björklund via http://cgm.cs.mcgill.ca/~godfried/publications/banff.pdf
class Euclid
{
method build_string(Int $level, @count, @remainder )
{
#!perl6
use v6;
class Foo {
has $!foo_str;
method foo is rw {
Proxy.new(
FETCH => {
@jonathanstowe
jonathanstowe / uname
Created April 8, 2015 10:21
native uname
use v6;
use NativeCall;
class Utsname is repr('CStruct') {
has Str $.sysname;
has Str $.nodename;
has Str $.release;
has Str $.version;
has Str $.machine;
@jonathanstowe
jonathanstowe / gist:fe573758f3490a529f68
Created April 28, 2015 08:44
Channel.list go boom!
my $c = Channel.new;
await (^10).map: {
start {
my $r = rand;
sleep $r;
$c.send($r);
}
}
$c.close;
@jonathanstowe
jonathanstowe / gist:2eb6801204edbd877ef5
Created May 25, 2015 08:51
Package resolution infelicity
Given:
lib/Pack.pm:
class Pack {
use Pack::Util::Collection;
our $collection;
(
gather {
my $c = Channel.new;
my @ps = do for ^10 { start { sleep rand; $c.send($_) } };
my $p = Promise.allof(@ps);
loop {
earliest $c {
more * {
take $_;
}
@jonathanstowe
jonathanstowe / gist:98025c6b0df7a6f992dc
Last active August 29, 2015 14:23
CArray weirdness
use v6;
use NativeCall;
my @buff := CArray[num64].new;
my @in = (^100).map({Num($_)});
for ^100 -> $i {
@buff[$i] = @in[$i];