Skip to content

Instantly share code, notes, and snippets.

@timbunce
timbunce / gist:085f810cc7ce24d7b6e9
Created February 17, 2015 23:50
DBIx::RetryConnection to add DBI connection retry logic
Typical usage:
use DBIx::RetryConnection qw(Pg);
or:
use DBIx::RetryConnection Pg => { ... }; # options for Type::Tiny::Retry
DBI->connect('dbi:Pg:...', $user, $pass, { private_dbix_retry_connection_delay_exp => [...] });
@timbunce
timbunce / keybase.md
Created October 30, 2014 22:02
keybase.md

Keybase proof

I hereby claim:

  • I am timbunce on github.
  • I am timbunce (https://keybase.io/timbunce) on keybase.
  • I have a public key whose fingerprint is 27B2 2751 AF56 A665 AE9E 93E2 356E FE07 F4AD 7187

To claim this, I am signing this object:

{
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"term": {
"path": "cpanfile"
}

logstash queries graphed with graphite.

Operation: Decouple whisper from graphite.

Method: Create a graphite function that does a date histogram facet query against elasticsearch for a given query string for the time period viewed in the current graph.

Reason: graphite has some awesome math functions. Wouldn't it be cool if we could use those on logstash results?

The screenshot below is using logstash to watch the twitter stream of keywords "iphone" "apple" and "samsung" - then I graph them each, so we get an idea of popularity. As a bonus, I also do a movingAverage() on the iphone curve to show you why this is awesome.

@timbunce
timbunce / gist:7560988
Created November 20, 2013 10:31
Postgis GeoJSON silent massive loss of precision with coordinates specified as string values
This works as expected:
corp=> SELECT ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-48.23456,20.12345]}')) As wkt;
wkt
---------------------------
POINT(-48.23456 20.12345)
but this doesn't:
corp=> SELECT ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":["-48.23456","20.12345"]}')) As wkt;
@timbunce
timbunce / gist:5780999
Created June 14, 2013 10:53
Concurrent non-blocking connections in perl
use strict;
use Data::Dumper;
my @hosts = (
'74.125.24.101:80', # google
'74.125.24.101:9999', # google but bad port
'17.172.224.47:80', # apple
'117.53.170.202:80', # www.gov.au
);
@timbunce
timbunce / perl -V
Created May 3, 2013 22:12
warn("%p %s\n", basecop->cop_file, basecop->cop_file);
600c00020180 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020360 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c000204e0 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020540 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c000205a0 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020480 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020600 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c000206c0 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020780 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020300 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
@timbunce
timbunce / gist:5514563
Created May 3, 2013 22:07
warn("%p %s\n", basecop->cop_file, basecop->cop_file); while traversing the op tree of blib::import
600c00020180 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020360 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c000204e0 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020540 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c000205a0 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020480 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020600 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c000206c0 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020780 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
600c00020300 /usr/local/perl5-blead-deb-thr-asan/lib/5.17.11/blib.pm
@timbunce
timbunce / pr.md
Created April 1, 2013 09:25 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@xyz»++ # increment all elements of @xyz
@x = @a »min« @b # @x is smallest of @a and @b
$mean = ([+] @a) / @a # calculate mean of @a
$sumsq = [+] (@x »**» 2) # sum of squares of @x
$fact = [*] 1..$n # $n factorial