Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
hoehrmann / gist:2439564
Created April 21, 2012 20:59
Extract german noun inflections from Wiktionary (quick and dirty)
#!perl -w
use strict;
use warnings;
use encoding 'utf-8';
use MediaWiki::DumpFile::Pages;
use YAML::XS;
my $pages = MediaWiki::DumpFile::Pages
->new('dewiktionary-20120416-pages-meta-current.xml');
#!perl -w
use strict;
use warnings;
use XML::LibXML;
use XML::LibXSLT;
use autodie;
my ($html_path, $xslt_path) = @ARGV;
my $html_doc = XML::LibXML->load_html( location => $html_path, recover => 2, load_ext_dtd => 0 );
my $xslt_doc = XML::LibXML->load_xml( location => $xslt_path );
<?php
#
# Ad-hoc oblique service for ngram databases with compatible interface
#
header('Content-Type: text/plain;charset=UtF-8');
if (@!isset($_REQUEST['q']) || @!isset($_REQUEST['nick'])) {
printf("I need a q! I need a nick! Sonst functioneren ik niet.");
exit();
var ordered = [].sort.call([].slice.call(list, 0), function(a, b) {
return (a.p1 - b.p1) || (a.p2 - b.p2);
});
@hoehrmann
hoehrmann / identify-quoted-text.pl
Created February 28, 2013 01:24
Take mbox, print HTML version of contents with quoted text marked via <i> elements.
#!perl -w
use Modern::Perl;
use Algorithm::Diff::XS;
use Statistics::Basic qw/median stddev avg/;
use Mail::Mbox::MessageParser;
use MIME::Parser;
use MIME::Parser::Reader;
use Mail::Field;
use Encode;
use HTML::Entities;
use v5.16;
use strict;
use warnings;
state $f = do {
open my $f, '>:utf8', 'delme.tmp';
$f;
};
print $f "" if 0;
@hoehrmann
hoehrmann / gist:5131504
Last active December 14, 2015 18:48
Acme::IEnumerable, lazy generators for Perl.
package main;
use Modern::Perl;
use Coro::Generator;
my $even = generator {
my $x = 0;
while(1) {
$x += 2;
# use references as boxing mechanism
# yield non-reference to indicate end
@hoehrmann
hoehrmann / gist:5181285
Last active December 15, 2015 01:39
Lazy lists with state variables and $StopIteration
package Acme::IEnumerable;
use v5.16;
use strict;
use warnings;
our $StopIteration = {};
sub integers {
my ($class) = @_;
return bless sub {
@hoehrmann
hoehrmann / gist:5278590
Created March 30, 2013 22:17
Generator is a sub returning an iterator when called; an iterator is a sub returning a reference to the next element, or a non-ref value when hitting the end.
package Acme::IEnumerable::List;
use Modern::Perl;
use base qw/Acme::IEnumerable/;
1;
package Acme::IEnumerable;
use Modern::Perl;
use Carp;
package Acme::IEnumerable::IGrouping;
use Modern::Perl;
use base qw/Acme::IEnumerable/;
1;
package Acme::IEnumerable::List;
use Modern::Perl;
use base qw/Acme::IEnumerable/;