Skip to content

Instantly share code, notes, and snippets.

View softmoth's full-sized avatar

Tim Siegel softmoth

View GitHub Profile
@softmoth
softmoth / pairs.pl
Created September 7, 2012 06:38
Equivalent Pair literals in list context
# These are all equivalent: a list of three Pairs
@foo = 'one' => 1, 'two' => 'ii', 'one' => { say "ॐ" }
@foo = one => 1, two => 'ii', one => { say "ॐ" }
@foo = :one(1), :two<ii>, :one({ say "ॐ" })
@softmoth
softmoth / tumblr-gist.js
Created September 7, 2012 05:25 — forked from slezica/tumblr-gist.js
tumblr gist embedder
var real_docwrite = document.write,
body = $('body');
(function insertGists(a_tags) {
if (a_tags.length > 0) {
a_tag = a_tags.shift()
document.write = function(stylesheet) {
$('head').append(stylesheet);
@softmoth
softmoth / if-block-arg.pl
Created September 7, 2012 05:17
Implicit argument in if block
if %attrs<about> { say "\n", $^it }
if %attrs<about> -> $it { say "\n", $it } # Same thing
@softmoth
softmoth / using-events.pl
Created September 7, 2012 05:15
Registering event listeners
submethod BUILD (:$events!) {
$events.listen:
'EOF' => {
# Safety to prevent infinite loop, in case
# the quit-on-undef logic fails
unless $*IN.eof {
my $input = prompt("\n> ");
$events.emit('command', :$input);
}
},
@softmoth
softmoth / gist:3508824
Created August 29, 2012 09:00
Backtrace elems
my $x = 0;
sub foo {
my $bt = Backtrace.new;
note $x, +@$bt, $bt.end;
note $bt[*-1];
note $bt.full();
foo() if ++$x < 10;
}
@softmoth
softmoth / gist:3427205
Created August 22, 2012 16:27
nom infinite loop during compile
class Foo {
has $.foo;
method foo {
# Change this to $!foo, and compilation errors appropriately:
# "Cannot assign to a readonly variable or a value"
return $.foo;
}
}
@softmoth
softmoth / gist:3427178
Created August 22, 2012 16:21
OS X sample of nom in infinite loop (97-99% CPU, 1 thread)
Sampling process 55493 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling perl6 (pid 55493) every 1 millisecond
Process: perl6 [55493]
Path: /Users/tim/g/code/p6/rakudo/install/bin/perl6
Load Address: 0x100000000
Identifier: perl6
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: sh [55492]
@softmoth
softmoth / gist:3351102
Created August 14, 2012 17:37
Code block with interesting indentation is parsed as 4 separate blocks
=begin pod
In other words, C<.WHY> and C<.WHEREFORE> are inverse operations:
.WHY
----------------------------
| |
| v
----------------- -----------------
| Declared code | | Documentation |
@softmoth
softmoth / pod-dump.pl6
Created August 14, 2012 17:02
Somewhat improved pod-dump
#! /usr/bin/env perl6
# vim:set ft=perl6:
sub print-pod(Pod::Block $pod, $level = 0) {
my $leading = ' ' x $level;
my %confs;
for <config name level caption type headers> {
my $thing = $pod.?"$_"();
if $thing {
%confs{$_} = $thing ~~ Iterable ?? $thing.perl !! $thing.Str;
@softmoth
softmoth / gist:3350812
Created August 14, 2012 16:51
Table cells should be parsed as para
=begin table :caption('The Other Guys')
Secret
Superhero Identity Superpower
============= =============== ===================
B<The Shoveller> Eddie Stevens King Arthur's
singing shovel
Blue Raja Geoffrey Smith Master of cutlery
=end table