Skip to content

Instantly share code, notes, and snippets.

my $opt_parser = OptParser->new();
$opt_parser->add_option(
name => "foo" # name used to refer to this option
short => "f" # use as -f
long => "foo" # use as --foo
depends => "bar|baz" # option only valid if bar or baz is specified. using
# an array to list depends may be simpler... or not
conflicts => "buh" # option conflicts with option buh.
use strict;
use warnings;
use feature ":5.10";
my @ar = qw( a b c d );
my $ar_ref = \@ar;
say @ar; # abcd
say @$ar_ref; # abcd - same array, so same contents
@hercynium
hercynium / anyevent_ev_fork_test.t
Created December 20, 2010 19:12
test destroying and re-initializing an EV loop in a forked child
#!/usr/bin/env perl
use strict;
use warnings;
use English qw( -no_match_vars );
use Data::Dumper;
use EV;
use AnyEvent;
use AnyEvent::Strict;
@hercynium
hercynium / resize-rrds.sh
Created August 10, 2012 13:14
create a new rrd with data from an old one and different RRA & step & heartbeat parameters
#!/bin/bash
set -e
tar czf rrds.tar.gz rrds/
find rrds/ -name '*.rrd' \
| xargs -P8 -I{} bash -c '
set -e
echo "{}"
./rrd-clone.pl "{}" "{}.new"
@hercynium
hercynium / Foo.pm
Created August 28, 2012 19:29
I am a terrible, horrible person
use feature ':5.10.0';
package Foo;
use Text::Template;
# needs to be in scope for Text::Template's processing
my %data;
sub get_metadata {
my ($tmpl) = @_;
return Bar::get_metadata($tmpl);
@hercynium
hercynium / relpath.bash
Created October 16, 2012 13:51 — forked from netj/relpath
A Bash script providing a command for computing relative path between two filesystem paths
#!/bin/bash
# relpath -- Compute relative path from a given DIR to given PATHs
# Usage: relpath DIR PATH...
#
# Example: relpath /a/b/c /a/d/e/f
# prints: ../../d/e/f
#
# Example: relpath /a/b/c /
# prints: ../../../
#
@hercynium
hercynium / gist:3908427
Created October 17, 2012 21:39
Some insane bash that might end up useful in the future
#!/bin/bash
#
# Summary:
# This script will set up your environment et al so you can run the Hive
# Query Tool. This script is intended to be sourced, but can be run without
# sourcing. The /path/to/perl argument(s) are optional.
#
# Usage:
# source setup-hqt [/path/to/perl /path/to/other/perl ...]
# setup-hqt [/path/to/perl /path/to/other/perl ...]
@hercynium
hercynium / bash-getopt-example.sh
Created November 16, 2012 17:34
declarative getopt in bash
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
source /bath/to/bash-getopt
foo_dflt="wibble"
bash-getopt "$@" <<END_OPTS
@hercynium
hercynium / opt-perl.spec
Created December 8, 2013 23:40
RPM .spec file for building a specific version of perl to install under /opt
#!/bin/bash
#
# This is a simple script to allow someone on an RPM-based
# system to build the custom opt-perl package defined by
# the RPM specfile in this same directory.
#
# @author: Stephen R. Scaffidi <sscaffidi@tripadvisor.com>
# @date: Oct. 2012
#
@hercynium
hercynium / ssl-cert-saver.sh
Last active August 29, 2015 14:12
script to save SSL/TLS certs to files
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
host="$1"
port="$2"
starttls_prot="${3:-}" # xmpp, smtp, pop3, imap, or ftp (optional)