Skip to content

Instantly share code, notes, and snippets.

@sirhc
sirhc / .screenrc-build-hosts
Created August 16, 2010 16:23
screen config to ssh to multiple build hosts
# Use this screen configuration with:
# screen -O -d -R build-hosts -c ~/.screenrc-build-hosts
startup_message off
chdir
autodetach on
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
screen -t shell0 0
@sirhc
sirhc / MyConfig.pm
Created August 17, 2010 17:43
~/.cpan/CPAN/MyConfig.pm
use strict;
use Config;
my $home = ( getpwuid $< )[7];
my $cpan = "$home/.cpan";
# The .packlist and perllocal.pod files aren't useful, so remove them along
# with any directories left empty along the way.
#END {
# use File::Find;
#
@sirhc
sirhc / MyCGI.pm
Created August 27, 2010 22:01
Simple example of overriding a method in CGI.pm
package MyCGI;
use base 'CGI';
use strict;
our $ShowAll = 0; # set via $MyCGI::ShowAll
sub a {
my ( $self, @param ) = @_;
@sirhc
sirhc / getopt-example.pl
Created October 11, 2010 20:16
example of using Getopt::Long with Pod::Usage
#!/usr/bin/env perl
use strict;
use Getopt::Long qw< :config auto_version bundling no_ignore_case >;
use Pod::Usage;
my %Opt = ( # could use %ARGV if so inclined
'dry-run' => 0,
'verbose' => 0,
);
my $log_regex = qr{
^ (?<revision> \d (?: [.]\d )+ ) \n
^ log \n
^ [@]r\d+ \s+ (?<user> \w+ ) \s+ [|] \s+
(?<year> \d\d\d\d)-
(?<month> \d\d)-
(?<day> \d\d)T
(?<hour> \d\d):
(?<minute> \d\d):
(?<second> \d\d)
my $dbh = DBI->connect( $dsn,
$Opt{'user'} // '',
$Opt{'password'} // '',
{ AutoCommit => 1,
PrintError => 0,
RaiseError => 0,
HandleError => sub { warn shift },
Callbacks => {
ChildCallbacks => {
execute => sub {
@sirhc
sirhc / go.bash
Created January 7, 2011 21:12
Simple function to change to a directory given a key
#!/bin/bash
#
# Bookmarks for filesystem paths. For example,
# > go add logs /var/log
# > go logs
# > pwd
# /var/log
go () {
if [[ $# -eq 0 ]]; then
@sirhc
sirhc / placeholders.pl
Created March 2, 2011 00:05
Use a field/value hash to automatically generate placeholders for DBI
my %value_for = (
field1 => 'value1',
field2 => 'value2',
field3 => 'value3',
# ...
);
my $sth = $dbh->prepare(<<"SQL");
INSERT INTO table (@{[ join ',', keys %value_for ]})
VALUES (@{[ join ',', ('?') x scalar keys %value_for ]})
# vim: ft=muttrc
# These were taken from Fedora's configuration.
#color normal white default
color hdrdefault red default
color quoted brightblue default
color signature red default
color indicator brightyellow red
color error brightred default
@sirhc
sirhc / gist:972589
Last active September 25, 2015 19:28
Shell one liners
#!/bin/sh
# Generate a relatively secure password.
apg -n 10 -m 8 -x 8 -t -a0 -MNCl
perl -Mutf8 -MConvert::Braille -e 'print brailleUnicodeToAscii("⠚⠥⠎⠞ ⠁⠝⠕⠞⠓⠑⠗ ⠷⠃⠇⠊⠝⠙⠾ ⠏⠑⠗⠇ ⠓⠁⠉⠅⠑⠗")'
# Convert a 16:9 720p .mkv file to a 4:3 .avi file.
mencoder $file1.mkv -oac mp3lame -ovc xvid -xvidencopts pass=1 \
-vf scale=720:352 -o $file2.avi