Skip to content

Instantly share code, notes, and snippets.

@pmakholm
pmakholm / udpcat.pl
Created April 15, 2009 17:00
Simple script to 'cat' an UDP port
#!/usr/bin/perl
# quick and dirty: Read from a udp socket and print to STDOUT
# usage: udpcat.pl <host> <port>
# or: udpcat.pl <host>:<port>
use strict;
use warnings;
use IO::Socket::INET;
@pmakholm
pmakholm / worktime.pl
Created May 18, 2009 13:53
Script to summarize working time based om utmp entries
#!/usr/bin/perl
=license
"THE BEER-WARE LICENSE" (Revision 42):
<peter@makholm.net> wrote this file. As long as you retain this notice
you can do whatever you want with this stuff. If we meet some day, and
you think this stuff is worth it, you can buy me a beer in return
Peter Makholm
#!/usr/bin/perl
#
# An evil form of perl DESTROY-method
use strict;
use warnings;
{
package Evil;
our @DESTROYED;
@pmakholm
pmakholm / serialize.pl
Created June 15, 2009 08:11
Benchmark of serialization modules
#!/usr/bin/perl
# Originaly at:
# http://idisk.mac.com/christian.hansen/Public/perl/serialize.pl
# Updated by Peter Makholm, June 2009
# http://gist.github.com/130005
# - Added Data::Dumper and a current set of YAML/JSON modules
# - added tags for the -b option: :core, :yaml, :json
# Updated by Peter Makholm, October 2009
# - Moved main logic into Benchmark::Serialize
# Have easily editable functions in bash
#
# Usage: Place this script in $FUNCTIONS and call it from you .bashrc.
# Rerun the script each time you add new functions.
FUNCTIONS=$HOME/.lib.sh
eval $(
find $FUNCTIONS -type f | \
while read file ; do echo function $(basename $file)\(\) { source $file\; }\; ; done
@pmakholm
pmakholm / gist:142267
Created July 7, 2009 18:29
Handle multiple Perl local::lib paths
# Defaults:
PERL_LOCAL_LIB="home"
DIR=$HOME/.perl
if [ -n "$1" ]; then
PERL_LOCAL_LIB=$1
fi
export PERL_LOCAL_LIB
@pmakholm
pmakholm / gist:142660
Created July 8, 2009 07:33
Handle multiple ssh-agents
# Shell snipet to handle multiple ssh-agents
#
# By default I use an ssh-agent with a lot of keys added with the -c option to
# ssh-add and this agent is forwarded trough most of my connections.
# But for some taske this confirmation step is a hassle, so I create new
# agents without confirmation with a minimal set of keys.
#
# You have to source this "script" to work or use the hack described at
# http://peter.makholm.net/2009/07/07/shell-hacks-bash-functions-in-files/
@pmakholm
pmakholm / valid_date.pl
Created July 29, 2009 17:50
Regular expression to validate dates on the forms
#!/usr/bin/perl -ln
# Regular expression to validate dates on the forms 'YYYY-MM-DD' or 'YYYYMMDD'
$re = qr/(((0[48]|[2468][048]|[13579][26])00| \d\d(0[48]|[2468][048]|[13579][26]
))|(( [02468] [1235679]| [13579] [01345789])00 |\d\d([02468] [1235679]|
[13579][01345789]))(?!(-|)02\g{-1}29)) (?<sep>-|)(02(?!\g{sep}3)|0[469]
(?!\g{sep}31)|11(?!\g{sep} 31)|0[13578]|1[02])\g{sep}(0[1-9]|[12][0-9]|
3[01])/x;
print ($_=~ $re ? "Valid date" : "Invalid date");
@pmakholm
pmakholm / rc.lua
Created August 12, 2009 07:48
My Awesome3 configuration
-- Standard awesome library
require("awful")
require("awful.rules")
require("awful.autofocus")
-- Theme handling library
require("beautiful")
-- Notification library
require("naughty")
-- Load Debian menu entries
#!/usr/bin/perl;
use strict;
use warnings;
# Simple 'head -n N' implementation:
use Getopt::Long;
my $lines = 10;
GetOptions(
"lines|n=i" => \$lines,