Skip to content

Instantly share code, notes, and snippets.

@preaction
preaction / broker.pl
Last active November 20, 2021 08:10
A simple message broker using Mojolicious WebSockets
#!/usr/bin/env perl
# ABSTRACT: A simple message broker using Mojolicious WebSockets
# USAGE: ./socket.pl daemon
#
# Try the demo and read the explanation on the page before reading the code.
#
# Copyright 2015 Doug Bell (<[email protected]>)
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
foo = [ [ 1, 2, 3 ], [ 2, 4, 6 ], [ 3, 6, 9 ] ]
for [ a, b, c ] in foo:
print a
print b
print c
print "---"
@preaction
preaction / TestDeep.pm
Created August 4, 2015 01:34
Add Test::Deep to Test::Mojo
package Test::Mojo::Role::TestDeep;
# ABSTRACT: Add Test::Deep methods to Test::Mojo::WithRoles
use Role::Tiny;
use Test::Deep qw( cmp_deeply );
sub json_deeply {
my ( $t, $test, $desc ) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
return cmp_deeply( $t->tx->res->json, $test, $desc );
@preaction
preaction / outlier.pl
Last active August 29, 2015 14:16
Basic time series outlier analysis using PDL and TAlib
use strict;
use warnings;
use feature qw( :5.16 );
use PDL;
use PDL::Finance::TA;
my $threshold = 4;
my $limit = 100;
my $period = 30;
@preaction
preaction / Config.pod
Last active August 29, 2015 14:16
New Beam-Wire docs

DESCRIPTION

This is tutorial for Beam::Wire, starting with simple use as a configuration file, to complex dependency injection.

SIMPLE CONFIGURATION

The basic Beam::Wire configuration is a hash of hashes describing how to create objects (which, in a dependency injection context, are called "services"). The top-level keys are the name of the

@preaction
preaction / blog.md
Created February 25, 2015 03:51
Statocles release announcement

Static site generators are popular these days. For small sites, the ability to quickly author content using simple tools is key. The ability to use lower-cost (even free) hosting, often without any dynamic capabilities, is good for trying to maintain a budget. For larger sites, the ability to serve content quickly and cheaply is beneficial, and since most pages are read far more often than it is written, generating a full web page to store on the filesystem can improve performance (and lower costs).

For me, I like the convenience of using Github Pages to host project-oriented websites. The project itself is already on Github, so why not keep the website closely tied to it so it doesn't get out-of-date? For an organization like the Chicago Perl Mongers, Github can even host custom domains, allowing easy collaboration on websites.

It's through the Chicago.PM website that I was introduced to Octopress, a blogging engine buil

@preaction
preaction / gist:a5acc624da4abd9b88b4
Created February 20, 2015 19:34
Devel::Peek from MongoDB and Hash literal with "use utf8"
### From MongoDB
SV = IV(0x40dbef8) at 0x40dbf08
REFCNT = 1
FLAGS = (ROK)
RV = 0x40dbea8
SV = PVHV(0x40d2fb0) at 0x40dbea8
REFCNT = 1
FLAGS = (OOK,SHAREKEYS,HASKFLAGS)
ARRAY = 0x40554f0 (0:5, 1:3)
hash quality = 150.0%
package DbLibTry;
use Mojo::Base '-strict';
use DBI;
has dbh => sub {
DBI->connect( "DBI:SQLite:dbname=songdb.sqlite3", q{}, q{}, {RaiseError => 1} )
or die $DBI::errstr;
};
@preaction
preaction / git-leader.sh
Last active August 29, 2015 14:14
leaderboard for git
git log --shortstat | awk '/Author|changed/' | perl -lne'if ( /^Author: (.+)/ ) { $author = $1 } else { while ( /(?:(\d+) (?:insertions|deletions))/g ) { $changes{ $author } += $1 } } END { print "$changes{$_} $_" for keys %changes }'
# 2674 Doug Bell <[email protected]>
# 18332 Doug Bell <[email protected]>
@preaction
preaction / uniqpersec.sh
Last active August 29, 2015 14:13
Measure unique lines per second
FILE=/tmp/whatever
while ; do;
LINES=$(sort $FILE | uniq | wc -l | awk '{ print $1 }' );
echo $LINES;
echo $OLD_LINES;
echo $( dc -e"$LINES $OLD_LINES - p" );
OLD_LINES=$LINES;
sleep 1;
done;