Skip to content

Instantly share code, notes, and snippets.

@timbunce
timbunce / gist:085f810cc7ce24d7b6e9
Created Feb 17, 2015
DBIx::RetryConnection to add DBI connection retry logic
View gist:085f810cc7ce24d7b6e9
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 => [...] });
View 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:

View body.json
{
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"term": {
"path": "cpanfile"
}
View RESULTS.md

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 Nov 20, 2013
Postgis GeoJSON silent massive loss of precision with coordinates specified as string values
View gist:7560988
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 Jun 14, 2013
Concurrent non-blocking connections in perl
View gist:5780999
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
warn("%p %s\n", basecop->cop_file, basecop->cop_file);
View perl -V
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
warn("%p %s\n", basecop->cop_file, basecop->cop_file); while traversing the op tree of blib::import
View gist:5514563
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
View 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:

View gist:3846125
@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