Skip to content

Instantly share code, notes, and snippets.

@MadcapJake
MadcapJake / channel.pl6
Last active May 7, 2016 22:14
Shakespeare Counter
my $text = open 'test.txt';
constant CHUNK_SIZE = 5;
constant Vowels = <a e i o u A E I O U>.Set;
constant Consonants = <B C D F G H J K L M N P Q R S T V W X Y Z b c d f g h j k l m n p q r s t v w x y z>.Set;
sub channeled {
my ($read, $parsed) = Channel.new xx 2;
reader($text, $read);
@MadcapJake
MadcapJake / gen-bindings.pl6
Last active May 4, 2016 22:44
Generate FluidSynth synth.h bindings
my IO::Path $headers =
$*CWD.child('vendor').child('fluidsynth').child('fluidsynth').child('include').child('fluidsynth');
my Str:D $synth-header = $headers.child('synth.h').slurp;
my %types =
char_star => 'Str',
constchar_star => 'Blob',
constint_star => 'Pointer[int64]',
constdouble_star => 'Pointer[num64]',
# No need for new/BUILD if you accept a longer instantiation
class FuzzyNum {
has Num $.i;
method gist { $!i.gist }
};
# Must be multi, otherwise overwrites all + operators
multi sub infix:<+>(FuzzyNum $a, FuzzyNum $b) {
FuzzyNum.new(i => $a.i + $b.i + rand ** rand)
}
@MadcapJake
MadcapJake / get-title.pl6
Created April 21, 2016 03:47
High-Level HTML::MyHTML Interface RFC
use HTML::MyHTML
# basic init
my HTML::MyHTML $parser .= new;
# gather some html
my $website = qx{curl -s http://www.example.com};
# parse html
$parser.parse($website);
@MadcapJake
MadcapJake / pm6.fish
Last active April 7, 2016 21:22
A Perl 6 module scaffold generator
function pm6 --argument-names name --description="A Perl 6 module scaffolder"
set path "$HOME/github/$name"
git init -q -- $path
mkdir -- "$path/lib"; and touch -- "$path/lib/$name.pm6"
mkdir -- "$path/t"; and mkdir -- "$path/eg"
echo ".precomp" > "$path/.gitignore"
echo "# $name" > "$path/README.md"
echo "{
\"name\" : \"$name\",
\"version\" : \"0.1.0\",
@MadcapJake
MadcapJake / chemical.pl6
Created April 4, 2016 16:10
Chemical programming in Perl 6
sub prime-reaction(@ (Int $a, Int $b)) {
$a > $b && $a %% $b ?? [($a div $b), $b] !! [$a, $b]
}
my @molecules = 2..101;
sub mix-and-react(@mols is raw) {
my @mixed = (@mols.pick: *).rotor(2);
@mols = @mixed.map(&prime-reaction).flat;
}
@MadcapJake
MadcapJake / refresh-tickets.pl6
Created March 30, 2016 12:48
Refresh RT Perl 6 tickets
use v6;
use Net::Curl::NativeCall;
constant RTURL = 'https://rt.perl.org/REST/1.0/';
my Hash @tickets;
with curl_easy_init() {
my Str $body;
@MadcapJake
MadcapJake / create-ticket.pl6
Created March 30, 2016 06:04
Create RT ticket in Perl 6 with Net::Curl
use v6;
use Net::Curl::NativeCall;
with curl_easy_init() {
# curl_easy_setopt($_, CURLOPT_COOKIESESSION, +True);
my Str $body;
my $login = 'user=guest&pass=guest';
@MadcapJake
MadcapJake / send-email.pl6
Last active March 29, 2016 16:05
Sending emails with Net::Curl
use NativeCall;
use Net::Curl::NativeCall;
use Email::Simple;
constant EmailPassword = %*ENV<P6BUG_EMAIL_PW>;
constant FROM = 'perl6bug@gmail.com';
constant TO = 'madcap.russo@gmail.com';
constant CC = 'jake.russo@zoho.com';
constant Email = Email::Simple.new(
[['To', TO], ['FROM', FROM], ['CC', CC], ['Subject', 'Testing']],
@MadcapJake
MadcapJake / GLFW.pl6
Last active May 15, 2019 21:54
GLFW/OpenGL with Perl 6
use v6;
use NativeCall;
sub lib { '/usr/lib/x86_64-linux-gnu/libglfw.so.3.1' }
=head1 GLFW/OpenGL in Perl 6
=head2 Bindings
class Window is repr('CPointer') {}
class Monitor is repr('CPointer') {}