Skip to content

Instantly share code, notes, and snippets.

@ggl
ggl / serializer-benchmark.pl
Last active September 14, 2018 08:44
Benchmark six Perl serializers
#!/usr/bin/env perl
use Benchmark;
use CBOR::XS ();
use Cpanel::JSON::XS ();
use Data::MessagePack;
use JSON::XS ();
use Sereal::Encoder;
use Sereal::Decoder;
@ggl
ggl / fib.d
Last active April 10, 2017 19:06
Fibonacci numbers in D
import std.stdio;
import std.bigint;
import core.checkedint;
void main() {
writefln("%d", fib_iter(72));
writefln("%d", fib_binet(72));
}
auto fib_iter (int n) {
@ggl
ggl / poi_sqlite.pl
Last active September 10, 2016 08:02
Create a POI SQLite database from a Garmin CSV
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
use Data::Dumper;
use Geohash;
use Text::CSV;
@ggl
ggl / ro-utf8-replace.pl
Last active September 10, 2016 07:47
Replace Turkish UTF-8 glyphs with Romanian ones
#!/usr/bin/env perl
use strict;
use warnings;
if (@ARGV < 1) {
print "usage: $0 <file>\n";
exit 0;
};
@ggl
ggl / www-get-links.pl
Last active September 10, 2016 07:44
Get href links from an URL using Mojo::UserAgent
@ggl
ggl / aliases.sh
Last active September 10, 2016 07:44
Bash/zsh shell alaiases
#!/bin/sh
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i
alias plack-app-dir="plackup -MPlack::App::Directory -e 'my \$app = Plack::App::Directory->new({ root => \"\$ENV{HOME}/public\" })->to_app;'"
@ggl
ggl / mojo-ioloop-time.pl
Last active September 10, 2016 07:39
Tell the time using a recurring Mojo::IOLoop timer
#!/usr/bin/env perl
use Mojo::IOLoop;
use POSIX;
# Start at sec % 5 == 0
Mojo::IOLoop->timer((5 - (localtime)[0] % 5) => sub {
# Perform operation every 5 seconds
Mojo::IOLoop->recurring(5 => sub {
my $loop = shift;
@ggl
ggl / sereal-child.pl
Last active September 10, 2016 07:36
Start a child process and feed it Sereal encoded data
#!/usr/bin/env perl
use strict;
use warnings;
use Child;
use Data::Dumper;
use Sereal::Encoder;
use Sereal::Decoder;
@ggl
ggl / histogram.pl
Last active September 10, 2016 07:36
Generate a histogram from a list of numbers
#!/usr/bin/end perl
use strict;
use warnings;
use Data::Dumper;
my $hist = sub {
my $input = shift;
if ($input and $input =~ /^\d+$/) {
@ggl
ggl / date_comp.pl
Created December 4, 2013 13:15
Time::Piece and Class::Date benchmarked
#!/usr/bin/env perl
#
# Time::Piece and Class::Date benchmarked
#
use strict;
use warnings;
use Benchmark qw(cmpthese);
use Time::Piece;