Skip to content

Instantly share code, notes, and snippets.

@dakkar
dakkar / add-irpc
Created July 10, 2011 16:13
micro-patch for gas-preprocessor
# first way: in pre-processing
# before calling «parse_line($_)» from the «while» loop
if (/\.irpc\s+([\d\w.]+)\s*(.*)/) {
my ($id,$vals)=($1,$2);
my @vals = split //,$vals;
$_ = ".irp $id @vals";
}
# second way: in «parse_line»
@dakkar
dakkar / spamdyke-cleaner
Created January 9, 2012 14:29
cronjob to clean spamdyke graylisting dir
#!/bin/bash
CONF=/etc/spamdyke/spamdyke.conf
graylist_dir=$(grep graylist-dir "$CONF");graylist_dir=${graylist_dir##*=}
graylist_max_secs=$(grep graylist-max-secs "$CONF");graylist_max_secs=${graylist_max_secs##*=}
find ${graylist_dir} -type f -mmin +$[ ${graylist_max_secs} / 60 ] -print0 | xargs -0 rm -f
@dakkar
dakkar / .gitignore
Created August 15, 2012 11:43 — forked from chizmw/.gitignore
MooseX::Types::Structured validation example
*.sw?
@dakkar
dakkar / arrays.sh
Created June 11, 2014 16:38
Dealing with arrays in bash
#!/bin/bash
# this is *complicated*
#
# we want to be able to set an array to the value of another
# array. this is harder than it should be
#
# The call:
# _set_array foo 1 "2 3" "4 5 6"
# should execute:
@dakkar
dakkar / gist:33257b8508507b3c47f9
Created August 1, 2014 15:48
Bread::Board deferred injections & generational lifecycle
#!/usr/bin/env perl
use strict;
use warnings;
use 5.018;
package App {
use Moose;
has model1 => ( is => 'ro', isa => 'Model1', );
has model2 => ( is => 'ro', isa => 'Model2', );
@dakkar
dakkar / app.psgi
Created February 11, 2015 10:12
Test case for Plack::Middleware::Session issue #29
#!perl
use strict;
use warnings;
package ForceSessionSave {
use parent 'Plack::Middleware';
sub call {
my ($self,$env) = @_;
my $res = $self->app->($env);
@dakkar
dakkar / portage-scan
Created April 16, 2015 10:33
Gentoo: find all files Portage can't re-create for you
#!/usr/bin/env perl
use strict;
use warnings;
use 5.020;
use autodie;
use Try::Tiny;
use File::Find::Rule;
use File::stat;
use Digest::MD5;
@dakkar
dakkar / fetch-and-list-tlds.pl
Created November 13, 2015 19:23
Fetch and list all TLDs
#!/usr/bin/env perl
use strict;
use warnings;
use 5.018;
use open ':std',':locale';
use LWP::Simple;
use URI::_punycode;
my $root_zone = get('https://www.internic.net/domain/root.zone');
my @root_records = split /\n/,$root_zone;
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark;
use List::Util;
my @keys = List::Util::shuffle( (1..500) x 1000, 600..800 );
Benchmark::cmpthese(-5, {
with_test => 'my %h; for my $k (@keys) { $h{$k}=1 unless exists $h{$k} }',
@dakkar
dakkar / Trace.pm
Created June 14, 2016 20:31
PerlIO layer to trace all reads / writes
package PerlIO::via::Trace;
use strict;
use warnings;
use Fcntl;
use Devel::StackTrace;
my $log_fh;
sub _trace {
my $fh = shift;
local $@;local $!;