Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/perl
use strict;
use warnings;
use Parallel::ForkManager;
my $pm = Parallel::ForkManager->new(8);
for my $file (glob "/usr/local/backup/*") {
my $pid = $pm->start and next;
@pmakholm
pmakholm / gist:5821490
Created June 20, 2013 09:35
Benchmark of listing files in directory in perl: ls vs glob vs readdir
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
qx(ls -1U); # Populate dir cache
cmpthese(1000, {
@pmakholm
pmakholm / ppi.pl
Created April 11, 2013 10:15
Simple command line interface for PPI (Perl Parsing Interface)
#!/usr/bin/env perl
use v5.12.0;
use Getopt::Long;
use File::Next;
use PPI;
my ($match, $content) = qw(Element content);
my ($count, $verbose);
#!/usr/bin/env perl
use v5.12.0;
use File::Next;
use PPI;
my $basedir = shift // '.';
my $elements = shift // 'Token::Regexp';
use Plack::Builder;
my $access_log = ...;
builder {
open my $logfh, ">>", $access_log
or die "Couldn't open $access_log: $!";
enable "AccessLog::Timed",
format => "%v %h %l %u %t \"%r\" %>s %b %D",
package PlackX::Util::Middelware;
use Plack::Util;
sub handle_response {
my ($res, %callback) = @_;
$callback{on_chunk} = sub { 1 };
$callback{on_close} = sub { 1 };
@pmakholm
pmakholm / gist:2575267
Created May 2, 2012 08:55
Finding files in git
#!/bin/sh
for commit in $( git log --format=format:%H ) ; do
git ls-tree -r $commit | while read line ; do
echo $commit $line
done
done | grep $( git hash-object $1 )
@pmakholm
pmakholm / gist:2214090
Created March 27, 2012 08:47
Udtræk af §20-spørgsmål (XML)
<?xml version="1.0" encoding="utf-8"?>
<!--
2011-07-28: Tilføjet RSS
2009-08-05: Helt nyt view og parfil. OBS parameter minister daekker over ministerArea
2009-04-18: PEP Rediget til optimering (udkommentering spørgsmåltyper)
2009-03-26: Redigeret til samrådsspm.
2009-03-19: SYNKRONISERET til alle servere
2008-05-11: denne configuration er OK PEP
2010-04-06: rettet sortering på nr. JOKR
@pmakholm
pmakholm / gist:2214047
Created March 27, 2012 08:38
Udtræk af §20-spørgsmål
WITH MT AS ( SELECT row_number() over ( ORDER BY CASE WHEN
ftcn_casenumber.ftcn_casetypedesc in ('B ', 'S ', 'L ', 'Aktstk.', 'US') THEN
UPPER(ftcn_casenumber.ftcn_casetypedesc + ' ' + REPLICATE('0', 50 -
len(ftcn_casenumber.ftcn_casenumber)) + ftcn_casenumber.ftcn_casenumber + ' ' +
IsNull(ftcn_casenumber.ftcn_casenosuffix, '') + ' ' + REPLICATE('0', 50 -
len(convert(varchar(10),IsNull(documentParagraphNumber,0)))) +
convert(varchar(10),IsNull(documentParagraphNumber,0))) ELSE ( CASE WHEN
caseTypeRecno=100012 then 'UM-DEL' WHEN caseTypeRecno=100001 THEN 'ALM. DEL ' +
committeeAbbreviation + ' ' + REPLICATE('0', 50 -
len(convert(varchar(10),IsNull(documentParagraphNumber,0)))) +
@pmakholm
pmakholm / abstract.txt
Created January 24, 2012 19:53
Suggested talk for OpenSourceDays 2012
Title: Modern Web Programming in Perl
Duration: 45 minutes
In year 1997 dynamic web pages often consisted of HTML forms you could
submit to the server and get a full HTML page back. The standard
language for writing the server code was Perl and it is quite probable
that the worst code ever written in any language is written in Perl
about 15 years ago to handle some HTML form processing.
Since then different languages has been hyped as *the* language for