Skip to content

Instantly share code, notes, and snippets.

View tene's full-sized avatar

Stephen Weeks tene

  • Sunnyvale, CA
View GitHub Profile
@tene
tene / macro.pl
Created March 6, 2011 12:13
p5 macro declarative
# Macro definition, like, Perl 6 grammars, will use () for capturing subgroup
# and [] for noncapturing grouping, and <...> to generate named parsing rules
macro manip_select
{
'select' (
'*' |
[ [ <ident> '(' <ident> ')' | <ident> ] ** ',' ]
) 'from' <term>
('where' (
@tene
tene / f.pl
Created March 3, 2011 09:21
demo of devel declare prototype
use fn;
use 5.010;
fn foo ($f, $a; $extra) {
say "going to call with ($a)";
$f->($a);
if (defined($extra)) {
say "got extra: $extra";
}
say "done with call";
@tene
tene / 3.p6
Created February 23, 2011 20:20
treed's 3.p6 using Math::Prime
# Solved in 16.5s
use Math::Prime;
sub factor_one($number) {
my @primes := primes();
for @primes ... * > sqrt $number -> $n {
return $n if $number %% $n;
}
}
knowhow RubyClassHOW {
has $!parent;
has $!parent_set;
has $!name;
has %!methods;
has %!attributes;
has $!virtual;
method new(:$name, :$virtual) {
my $obj := pir::repr_instance_of__PP(self);
grammar eria::Grammar is HLL::Grammar;
token TOP {
<statementlist>
}
rule statementlist { <affectation>+ }
rule affectation {
0 -> 1
1 -> 2
2 -> 0
0 -> 3
3 -> 2
2 -> 7
7 -> 1
1 -> 5
5 -> 0
0 -> 4
[sweeks@sweeks-laptop ~]$ perl /tmp/config.pl
$VAR1 = {
'bar' => '2',
'omg' => '29',
'lol' => '3',
'foo' => '1'
};
@tene
tene / Log.pm
Created December 13, 2010 09:31
use MooseX::Declare;
use feature ':5.10';
class Log {
use Moose::Util::TypeConstraints;
our $foo;
BEGIN {
enum 'RGB' => qw/red green blue/;
$foo = "lol ohai";
}
use Logger;
@tene
tene / Lol.pm
Created December 9, 2010 19:33
package Lol;
use Exception::Class (
'Foo',
);
sub import {
print "before throwing\n";
throw Foo("OHAI");
print "after throwing\n";
}
[sweeks@sweeks-laptop ~]$ exec 3>/tmp/lolcats
[sweeks@sweeks-laptop ~]$ exec 4>/tmp/walrus
[sweeks@sweeks-laptop ~]$ ls -l /proc/self/fd/{3,4}
l-wx------. 1 sweeks sweeks 64 Dec 7 16:51 /proc/self/fd/3 -> /tmp/lolcats
l-wx------. 1 sweeks sweeks 64 Dec 7 16:51 /proc/self/fd/4 -> /tmp/walrus
[sweeks@sweeks-laptop ~]$ exec 4>&3
[sweeks@sweeks-laptop ~]$ ls -l /proc/self/fd/{3,4}
l-wx------. 1 sweeks sweeks 64 Dec 7 16:51 /proc/self/fd/3 -> /tmp/lolcats
l-wx------. 1 sweeks sweeks 64 Dec 7 16:51 /proc/self/fd/4 -> /tmp/lolcats