Skip to content

Instantly share code, notes, and snippets.

@0racle
0racle / StrReplace.ahk
Last active December 14, 2016 22:17
StrReplace.ahk
SetKeyDelay -1 ; Makes SendRaw faster
F7::
ClipStore = %Clipboard% ; Save the current Clipboard
SendInput ^a^c ; Copy all text in current field
Output := StrReplace(Clipboard, "\", "\\") ; Replace "\" with "\\"
SendRaw %Output% ; Send the output
Clipboard = %ClipStore% : Restore original Clipboard
Return
@0racle
0racle / install.sh
Last active April 11, 2017 14:37
Perl 6 Install Script
#!/usr/bin/env sh
set -e
INSTALL_DIR=$HOME/rakudo
LATEST_TAR="rakudo-star-latest.tar.gz"
URL="http://rakudo.org/downloads/star"
echo "\033[1;33m
This script will install Rakudo Star
@0racle
0racle / csv-parse.md
Last active April 19, 2017 02:06
CSV Parse

Given that dis.csv looks like this

Name|Age|DOB|Favourite Color
John|17|12/12/1998|Blue
David|31|15/07/1985|Orange
Michael|11|02/08/2005|Red

Open the file called dis.csv and assign the filehandle to the variable csvfile

@0racle
0racle / Matplotlib.pm6
Created April 11, 2017 14:28
Matplotlib in Perl6
use Inline::Python;
my $py = Inline::Python.new();
$py.run('import matplotlib.pyplot');
class Matplotlib::Mlab {
method FALLBACK($name, |c) {
$py.call('matplotlib.mlab', $name, |c)
}
}
@0racle
0racle / sort-gotcha.md
Last active June 9, 2017 21:57
Sort Gotcha

Sort Gotcha

> <matthew mark luke john>.unique(as => *.chars).sort(by => *.chars)
(mark matthew)

Ahh good, my code works... except it's not really sorting by chars here because unlike unique, sort takes a code block not a named parameter. However there is no error to indicate this is not DWIM. It just silently sorts Naturally.

If your data happens to sort Naturally in the same order your by option would have sorted it - and you don't notice - you now have a bug laying dormant in your code that could go unnoticed indefinitely.

Sort should either handle this syntax, or otherwise throw up a warning;

@0racle
0racle / token_array.p6
Created June 14, 2017 06:44
Token Array
my %m;
my token foo { 'foo' { %m<foo> = $/ } };
my token bar { 'bar' { %m<bar> = $/ } };
my token baz { 'baz' { %m<baz> = $/ } };
my token qux { 'qux' { %m<qux> = $/ } };
my @tokens = /<foo>/, /<bar>/, /<baz>/, /<qux>/;
say 'foo bar baz qux' ~~ / ^ <{ @tokens[$++] }> ** { +@tokens } % <.ws> $ /;
@0racle
0racle / README.md
Created July 6, 2017 05:19
NativeCall strptime & strftime

I've used this in some personal code... Seems to work fine mostly provided you don't try to get it to parse timezones.

I'm no C programmer. I'm not sure if I've done anything wrong with the NativeCall.

If someone wants steal this and release to the ecosystem, it should probably be added to the already existing POSIX module rather than it's own thing.

@0racle
0racle / rotor.p6
Created July 26, 2017 11:43
Perl 6 Rotor
> (1..10).rotor(3)
((1 2 3) (4 5 6) (7 8 9))
> (1..10).rotor(3, :partial)
((1 2 3) (4 5 6) (7 8 9) (10))
> (1..10).rotor(3,2,1)
((1 2 3) (4 5) (6) (7 8 9))
> (1..10).rotor(3,2,1, :partial)
@0racle
0racle / hanoi.p6
Created September 19, 2017 03:27
Hanoi
sub hanoi(\n, \a = 1, \b = 2, \c = 3) {
return unless n;
hanoi n - 1, a, c, b;
#say "Move disk {n} from peg {a} to peg {c}";
hanoi n - 1, c, b, a;
}
hanoi(20);
say now - INIT now
@0racle
0racle / Readline.md
Last active November 9, 2017 13:51
Readline / NativeCall encoding error

Readline / NativeCall encoding error

Issue occurs the first time I type any expression.

# perl6
To exit type 'exit' or '^D'
> []
Internal error: unhandled encoding
  in method CALL-ME at ... (NativeCall) line 587