Skip to content

Instantly share code, notes, and snippets.

@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 / .dir_colors
Last active January 19, 2024 08:17
Color scheme for ls
# Configuration file for the color ls utility
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.
# COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
#
COLOR all
@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 / 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 / sundaram.cr
Last active October 10, 2021 13:04
The Sieve of Sundaram (1934)
def sieve_sundaram(n : UInt64)
a = Hash(UInt64, Bool).new
s = Array(UInt64).new
m = (n/2.0).round
(1_u64..n).each do |i|
(i..n).each do |j|
p = i + j + 2_u64*i*j
if p <= n
a[p] = true
end