Skip to content

Instantly share code, notes, and snippets.

@pmakholm
pmakholm / gist:1106536
Created July 26, 2011 11:30
Streaming PSGI with IO::AIO
my $app = sub {
return sub {
my $response = shift;
my $writer = $response->( [ 200, [] ] );
my $buffer = "a" x 1024;
$writer->write( $buffer );
$buffer =~ y/a/b/;
}
@pmakholm
pmakholm / dkhm-update-ds
Created October 8, 2010 16:16
Script for updating DS records for .dk domains
#!/usr/bin/perl
# Script for updating DS records for .dk domains
#
# The following argument must be provided:
# --ns - You authorative nameserver you trust
# --zone - The zone you want to update DS records for
# --handle - Your DKHM handle
# --pasword - Your DKHM password
#
@pmakholm
pmakholm / tweet-get.pl
Created September 18, 2010 14:17
Getting OAuth enabled RSS feeds from twitter.com
#!/usr/bin/perl
# Usage:
# - Get you own consumer_key and consumer_secret at http://dev.twitter.com/
# - Add them to $HOME/.get-tweets.json
# - Run this script and follows the directions
# - Run this script with the rss feed url as argument
use feature ':5.10';
use JSON::XS;
#!/bin/sh
for control in *.control ; do
equivs-build $control
done
#!/usr/bin/perl;
use strict;
use warnings;
# Simple 'head -n N' implementation:
use Getopt::Long;
my $lines = 10;
GetOptions(
"lines|n=i" => \$lines,
@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
@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 / 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 / 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
# 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