Skip to content

Instantly share code, notes, and snippets.

@earino
earino / gist:3630620
Created September 5, 2012 04:44
json
#!/usr/bin/env perl
use warnings;
use strict;
use FindBin;
use File::Slurp;
use JSON;
use Time::HiRes;
@earino
earino / first_attempt.pl
Created September 16, 2012 17:28
First attempt at winner take all parallelism
#!/usr/bin/env perl
use 5.16.0;
use warnings;
use strict;
use Parallel::ForkManager;
my @sites = qw/ www.google.com
4.2.2.2
@earino
earino / gist:4034030
Created November 7, 2012 20:04
Daemon::Daemonize and Server::Starter
58 my $exec = ['plackup', '-s', 'Starman', @options, $app];
59 daemonize(
60 run => sub{
61 start_server(
62 port => $port,
63 pid_file => $pid_file,
64 status_file => $status_file,
65 exec => $exec,
66 );
67 },
@earino
earino / script.js
Created November 23, 2012 22:42
Poor Man's Nagios
/**
* This function fetches a url and gets some of the instrumentation data.
*
* @param url the Url to fetch and instrument
* @return an object which contains the status code, latency, and contentLength.
*/
function fetchUrl(url) {
try {
var start = new Date().getTime();
var resp = UrlFetchApp.fetch(url);
@earino
earino / tee.go
Created November 26, 2012 00:25
Tee not quite right
package main
import (
"io"
"bufio"
"os"
"flag"
"log"
)
@earino
earino / constant.pl
Created February 27, 2013 21:40
This is why 'use constant' is bad.
#!/usr/bin/env perl
#
use warnings;
use strict;
use Data::Dumper;
use constant MY_CONSTANT => 13;
my %foo = (MY_CONSTANT => 'dingle');
@earino
earino / readonly.pl
Created February 27, 2013 23:24
Use Readonly instead of constant
#!/usr/bin/env perl
#
use warnings;
use strict;
use Data::Dumper;
use Readonly;
Readonly my $MY_CONSTANT => 13;
@earino
earino / constant_shootout.pl
Created February 28, 2013 19:47
Constant Shootout
#!/usr/bin/env perl
use warnings;
use strict;
use Dumbbench;
use Readonly;
use Const::Fast;
use Data::Dumper;
$Data::Dumper::Deparse = 1;
@earino
earino / results.pl
Created February 28, 2013 19:53
Results of the run
$VAR1 = {
'readonly' => sub {
use warnings;
use strict 'refs';
my $i = 0;
if (defined $test_hash{$READONLY_KEY}) {
if ($test_hash{$READONLY_KEY} eq $READONLY_VALUE) {
$i++;
}
}
@earino
earino / constant.rb
Created February 28, 2013 22:57
constant in ruby
require 'pp'
CONSTANT="value";
foo = { };
foo[CONSTANT] = CONSTANT;
pp foo;