Skip to content

Instantly share code, notes, and snippets.

View beppu's full-sized avatar

John Beppu beppu

View GitHub Profile
@beppu
beppu / results
Created February 11, 2015 20:29
benchmark_template_engines
--- Starting Benchmarks --------------------------------------------------------
ETA: 30 benchmarks to run = 300 seconds minimum.
--- Template Benchmark @Wed Feb 11 12:11:15 2015 -------------------------------
HT - HTML::Template (2.95)
HTE - HTML::Template::Expr (0.07)
MoTe - Mojo::Template ()
TAHT - Template::Alloy (1.020) in HTML::Template mode
TATT - Template::Alloy (1.020) in Template::Toolkit mode
TATT_P - Template::Alloy (1.020) in Template::Toolkit mode (compile to
perl)
@beppu
beppu / random-replace
Created February 27, 2015 19:16
for educational purposes
#!/usr/bin/perl
use strict;
use warnings;
sub slurp {
my $file = shift;
open my $fh, '<', $file or die;
my @lines = <$fh>;
close $fh;
\@lines;
@beppu
beppu / emit-error-catch.ls
Created April 21, 2015 22:25
my most recent take on taming EventEmitter
events = require \events
EventEmitter = events.EventEmitter
P = require \bluebird
fifo = require \./app/shared/fifo
q = fifo.make!
ee = new EventEmitter
chain = P.resolve(true)
set-timeout (-> ee.emit \error, { +aaaa }), 500ms
@beppu
beppu / shell
Created July 4, 2015 19:34
an example of how to control a subprocess and communicate with it through stdin/stdout/stderr
#!/usr/bin/env perl
use strict;
use warnings;
use IPC::Open3;
use IO::Select;
use Symbol qw(gensym);
use POSIX qw(:sys_wait_h);
# Read as much as possible from a file handle and return the result.
#
#!/usr/bin/env perl
use strict;
use warnings;
use JSON;
while (<>) {
my $relay = decode_json $_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(int($relay->{coldTimestamp} / 1000));
my $date = sprintf('%d-%02d-%02d', $year+1900, $mon+1, $mday);
print "$date $_"
package WhatIf;
use base 'Squatting';
# Data in %state persists between requests.
our %state;
sub service {
my ($app, $c, @args) = @_;
my $cr = $c->cr;
my $sid = $cr->{session_id};
if (defined $sid) {
package JGirl; # jgirl.com (after being liberated from domain squatters)
#
use strict; # Oh, the irony!
use warnings; #'
use base 'Squatting'; # <-----------------------------------'
use Encode;
our %CONFIG = (
dbconnect => 'dbi:SQLite:dbname=jgirl.db',
function (doc) {
// subset that doesn't contain current
var others = function(tags, current, length) {
var notCurrent = function(x) { return x != current; };
if (length == 2) {
return tags.filter(notCurrent).map(function(n){ return [n] });
} else {
var _others = [];
var list = tags.filter(notCurrent);
var size = length - 1;
package CouchWiki;
use strict;
use warnings;
use base 'Squatting';
use Coro::AnyEvent;
our %CONFIG = (
db => 'couchwiki'
);
package UTF8;
use base 'Squatting';
# == How to Run This App ==
#
# squatting UTF8
# squatting UTF8 -c view=raw
# squatting UTF8 -c view=as_subs
#