Skip to content

Instantly share code, notes, and snippets.

@grondilu
grondilu / dynzoom.py
Created June 1, 2010 09:40 — forked from ekohl/dynzoom.py
a fork for european locales, and with a rounded zoom
#!/usr/bin/env python
# dynzoom.py - dynamic zooming for uzbl, based on dynzoom.js
# Usage:
# @on_event GEOMETRY_CHANGED spawn /path/to/dynzoom.py \@geometry 1024 768
# Where 1024x768 is the resolution where we start to zoom out
import sys, re
" Parses WxH+X+Y into a 4-tuple of ints "
@grondilu
grondilu / newick.p6
Created November 20, 2012 17:55
Newick Perl 6 grammar test
use v6;
grammar Newick {
rule TOP { <node> ';' }
rule node {
<name> |
'(' (<neighbor=node>+)+ % ',' ')' <name>?
}
token name { [ <.alpha> | <.digit> ]+ }
}
@grondilu
grondilu / Modular.p6
Created December 3, 2012 01:17
modular integer Perl6 module
class Modular does Real {
has ($.n, $.modulo);
multi method new($n, :$modulo where * > 1) {
self.new: :n($n % $modulo), :$modulo
}
method Bridge { $.n % $.modulo }
multi method gist { "{self.Bridge} 「mod $.modulo」" }
method succ { self.Bridge.succ % $.modulo }
multi method Inverse {
my ($c, $d, $uc, $vc, $ud, $vd) = ($.n, $.modulo, 1, 0, 0, 1);
@grondilu
grondilu / newick.p6
Created December 6, 2012 10:16
Newick Perl 6 grammar test
use v6;
my $sample = q :to 'STOP';
(cat)dog;
dog cat
(dog,cat);
dog cat
STOP
==> Testing panda
t/panda/builder.t .... ok
t/panda/common.t ..... ok
t/panda/ecosystem.t .. ok
t/panda/fetcher.t .... ok
t/panda/installer.t .. ok
t/panda/tester.t ..... ok
t/stubs.t ............ ok
All tests successful.
Files=7, Tests=49, 36 wallclock secs ( 0.16 usr 0.02 sys + 31.56 cusr 1.80 csys = 33.54 CPU)
@grondilu
grondilu / newick.p6
Created December 7, 2012 06:24
parsing a newick tree
use v6;
my $sample = "((((((((((((((Odobenus_clarus)Opheodrys_nippon)Seokia_dignus,((Megaloperdix_coloratovillosum,(Ceratophrys_perrotetii)Cuora_boa)Meles_subminiatus,Megaloperdix_terrestris,(Boiga_lobatus)Caiman_brevirostris)Scolopendra_kopsteini)Thecla_temminskii,Nyctaalus_schrencki)Tupinambus_krueperi)Uncia_ornata,Trapelus_monorhis,(((Melanocoryhpa_australis,(Chelydra_mystacinus)Crotaphytus_mitratus)Streptopelia_mutabilis,Pterocles_caucasicus,(((Aegialifes_colombianus)Castor_ferox)Coenobita_glaucescens)Hyperoodon_hardwickii,Equus_relictus)Streptopelia_similis,((Eurynorhynchus_serricollis)Salvelinus_clypeatus,Pyrgilauda_glaucescens,(Aplopeltura_venulosa)Machetes_trianguligerus,Coleonyx_nupta)Spalerosophis_indicus)Thymallus_stellio,((Eucratoscelus_iguana)Machetes_penelope,Ahaetulla_melanoleucus)Sitta_quadriocellata,(Ameiva_crassidens)Oenanthe_longipennis)Ursus_himalayensis,((Acanthosaura_rusticolus)Thymallus_olivacea,Phrynohyas_dominicus)Tiliqua_cavimanus,(Limosa_glacialis,Eryx_guttata,Bubulcus_altaica)Myot
@grondilu
grondilu / seto-rosalind.p6
Created December 7, 2012 08:45
perl6 Set operators
use v6;
my @data = '10', '{1, 2, 3, 4, 5}', '{2, 8, 5, 10}';
my Set $N .= new: 1 .. @data.shift.Int;
my Set $A .= new: eval @data.shift.subst(/<[{}]>/, '', :g);
my Set $B .= new: eval @data.shift.subst(/<[{}]>/, '', :g);
sub infix:<∩>(Set \A, Set \B) { Set.new: B.list.grep: * eq any A.list }
sub infix:<∪>(Set \A, Set \B) { Set.new: |$A.list, |$B.list }
@grondilu
grondilu / debrujin.pl
Created December 8, 2012 18:33
Rosalind: de brujin graph
use strict;
use warnings;
my @sample = map { chomp; $_ } <>; #qw{TGAT CATG TCAT ATGC CATC CATC};
sub revc { my $_ = join '', reverse split //, shift; tr/ACGT/TGCA/; $_ }
my %SSrc; $SSrc{$_}++ for @sample, map { revc($_) } @sample;
for (keys %SSrc) {
printf "(%s, %s)\n", substr($_, 0, -1), substr($_, 1);
@grondilu
grondilu / Modular.pm
Created December 12, 2012 22:29
modular integers in Perl6
class Modular does Real {
our $.Modulus;
has ($.residue, $.modulus);
multi method new($residue, :$modulus where * > 1) { self.new: :residue($residue % $modulus), :$modulus }
method Bridge { $.residue % $.modulus }
multi method gist { "{self.Bridge} 「mod $.modulus」" }
method succ { self.Bridge.succ % $.modulus }
multi method Inverse {
return Mu unless $.residue gcd $.modulus == 1;
my ($c, $d, $uc, $vc, $ud, $vd) = ($.residue, $.modulus, 1, 0, 0, 1);
sub infix:<o>(&f, &g) { -> $x { &f(&g($x)) } }
sub continued-fraction(@a, @b)
{
gather for [\o] (@a.shift + @b.shift / *) xx * {
take .(Inf)
}
}
say continued-fraction((1, 2 xx *).list, (1 xx *).list)[3];