Skip to content

Instantly share code, notes, and snippets.

@MadcapJake
MadcapJake / Bob.pm
Created October 28, 2015 18:22
Bob aka Robert
unit module Bob;
class Bob is export {
method hey ($input) {
given $input {
when $_.ends-with('?') { say 'Sure.' }
when $_.ends-with('!') { say 'Whoa, chill out' }
when $_ eq '' { say 'Fine. Be that way!' }
default { say 'Whatever.' }
}
@MadcapJake
MadcapJake / platin.p6
Last active November 1, 2015 16:14
Translate English to Pig Latin with ease!
given @*ARGS[0] {
when @_ eq '-p' or @_ eq '--phrase' {
say translate(@*ARGS[1]);
}
when @_ eq '-f' or @_ eq '--file' {
say translate(@*ARGS[1].IO.slurp);
}
default {
say 'You must provide either "-p"/"--phrase" and a phrase or "-f"/"--file" and a filepath.';
exit(1);
@MadcapJake
MadcapJake / fluidsynth.p6
Last active November 12, 2015 19:59
fluidsynth in perl6
use NativeCall;
sub libfluidsynth { '/usr/lib/x86_64-linux-gnu/libfluidsynth.so.1.5.2' }
class FluidSettings is repr('CPointer') {
sub new_fluid_settings() returns FluidSettings is native(&libfluidsynth) { * }
sub delete_fluid_settings(FluidSettings) is native(&libfluidsynth) { * }
sub fluid_settings_setstr(FluidSettings, Str, Str) is native(&libfluidsynth) { * }
sub fluid_settings_setnum(FluidSettings, Str, num64) is native(&libfluidsynth) { * }
@MadcapJake
MadcapJake / human.p6
Created November 25, 2015 19:21
Perl 6 Private Methods
class Human {
has $.name;
has $!age;
method age {
($!age * 0.8).round;
}
method new (:$name, :$age) { self.bless(:$name, :$age); }
}
@MadcapJake
MadcapJake / AtomExtension.py
Created November 27, 2015 19:20
Open Atom via Gnome Files
import gi
gi.require_version('Nautilus', '3.0')
from gi.repository import Nautilus, GObject
from subprocess import call
class AtomExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
# jrusso at nomad in ~/github/p6-xtest on git:master x [17:02:10]
$ perl6-debug-m --ll-exception -Ilib -e 'use X11::XTest; XTest.new.key-event("Control-Shift-t", :down)'
Circular module loading detected involving module 'Debugger::UI::CommandLine'
at gen/moar/m-CORE.setting:34736 (/home/jrusso/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm::49)
from gen/moar/m-CORE.setting:3459 (/home/jrusso/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm:sink-all:167)
from gen/moar/m-CORE.setting:11958 (/home/jrusso/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm:sink:36)
from gen/moar/m-CORE.setting:34734 (/home/jrusso/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm::115)
from gen/moar/m-CORE.setting:34729 (/home/jrusso/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm::52)
from gen/moar/m-CORE.setting:30333 (/home/jrusso/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm:protect:51)
from
@MadcapJake
MadcapJake / mockup.sh
Created December 4, 2015 16:09
mockup Perl 6 REPL intro
$ perl6
Welcome to the Perl 6 REPL - $VERSION
{$linenoise ?? '' !! 'For history and tab completion: panda install Linenoise'}
>
@MadcapJake
MadcapJake / parser.pl6
Last active December 9, 2015 20:21
Attempt at #adventofcode day 7 part 1
sub non-zero(%env) {
#| for debugging, removes wires with a value of zero
my %res;
for %env.kv -> $wire, $value {
if $value != 0 { %res.push: $wire => $value };
}
%res;
}
sub sortfile($filename) {
#| places assignments at the beginning of a sorted input file
@MadcapJake
MadcapJake / main.coffee
Last active December 11, 2015 19:51
Atom Package Error
MIDI = require 'midi'
{CompositeDisposable} = require 'atom'
module.exports = ActivateAuxiliaryControls =
subscriptions: null
activate: (state) ->
@subscriptions = new CompositeDisposable
@MadcapJake
MadcapJake / A.pm6
Created February 8, 2016 00:07
Circular Perl 6 module files
use B;
sub bar { "world"; }
say foo() ~ bar();