Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / admin.out
Last active September 13, 2016 15:35
Mojolicious 'extends' feature
$ perl extends get /admin
[Tue Sep 13 10:19:23 2016] [debug] GET "/admin"
[Tue Sep 13 10:19:23 2016] [debug] Rendering template "admin.html.ep" from DATA section
[Tue Sep 13 10:19:23 2016] [debug] Rendering template "logged_in.html.ep" from DATA section
[Tue Sep 13 10:19:23 2016] [debug] Rendering template "layouts/default.html.ep" from DATA section
[Tue Sep 13 10:19:23 2016] [debug] 200 OK (0.002844s, 351.617/s)
<!DOCTYPE html>
<html>
<head>
<title>Admin</title>
@s1037989
s1037989 / tiny
Last active June 12, 2017 18:36
Tiny URL clone built with Mojolicious in 1 hour
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::Pg;
use List::Util qw(shuffle);
# tiny.conf
# { pg => 'postgresql://a:b@c/d', };
# Get a quick and free tiny hosted Postgresql database at
@s1037989
s1037989 / ws
Created August 9, 2016 04:14
[Mojolicious] websocket route that polls a database
use Mojolicious::Lite;
use 5.20.0;
use experimental 'signatures';
use Mojo::IOLoop;
Mojo::IOLoop->recurring(1 => sub { warn scalar localtime });
# Render template "index.html.ep" from the DATA section
get '/' => {template => 'index'};
package TimeClock::Model::OAuth2;
use Mojo::Base -base;
use UUID::Tiny ':std';
has 'pg';
sub store {
my $self = shift;
if ( $#_ == 1 ) {
use Mojolicious::Lite;
use lib '../Mojolicious-Plugin-OAuth2-Fetch/lib';
use lib 'lib';
use Mojo::Pg;
use TimeClock::Model::Pg::Users;
use TimeClock::Model::Pg::Timeclock;
my $config = plugin 'Config';
14252 ? S 0:00 /home/ubuntu/workspace/ForkAndGo/eg/minion.pl
14258 ? S 0:00 \_ /home/ubuntu/workspace/ForkAndGo/eg/minion.pl
14261 ? Ss 0:00 | \_ /home/ubuntu/workspace/ForkAndGo/eg/minion.pl
14267 ? S 0:00 | | \_ /usr/bin/perl /home/ubuntu/workspace/ForkAndGo/eg/minion.pl minion worker
14277 ? S 0:00 | | \_ /usr/bin/perl /home/ubuntu/workspace/ForkAndGo/eg/minion.pl minion worker
14263 ? Ss 0:00 | \_ /home/ubuntu/workspace/ForkAndGo/eg/minion.pl
14265 ? S 0:00 | | \_ /usr/bin/perl /home/ubuntu/workspace/ForkAndGo/eg/minion.pl minion worker
14270 ? S 0:00 | | \_ /usr/bin/perl /home/ubuntu/workspace/ForkAndGo/eg/minion.pl minion worker
14264 ? Ss 0:00 | \_ /home/ubuntu/workspace/ForkAndGo/eg/minion.pl
14268 ? S 0:00 | | \_ /usr/bin/perl /home/ubuntu/workspace/ForkAndGo/eg/minion.pl minion worker
@s1037989
s1037989 / deskws
Created March 29, 2016 03:22
sortbench
$ for i in $(seq 1 5); do echo "$i - $(date)"; perl sortbench.pl; done
1 - Mon Mar 28 22:18:24 CDT 2016
timethis for 10: 11 wallclock secs (10.42 usr + 0.02 sys = 10.44 CPU) @ 35.63/s (n=372)
timethis for 10: 11 wallclock secs (10.56 usr + 0.00 sys = 10.56 CPU) @ 34.94/s (n=369)
2 - Mon Mar 28 22:18:49 CDT 2016
timethis for 10: 10 wallclock secs (10.33 usr + 0.04 sys = 10.37 CPU) @ 35.58/s (n=369)
timethis for 10: 11 wallclock secs (10.67 usr + 0.01 sys = 10.68 CPU) @ 34.55/s (n=369)
3 - Mon Mar 28 22:19:13 CDT 2016
timethis for 10: 11 wallclock secs (10.58 usr + 0.02 sys = 10.60 CPU) @ 35.47/s (n=376)
timethis for 10: 11 wallclock secs (10.57 usr + 0.01 sys = 10.58 CPU) @ 34.59/s (n=366)
@s1037989
s1037989 / Mojo::Sendgrid.pm
Last active March 23, 2016 22:03
Sendgrid API implementation for Mojo framework
package Mojo::Sendgrid;
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::Sendgrid::Mail;
has config => sub { {} };
has apikey => sub { $ENV{SENDGRID_APIKEY} || shift->config->{apikey} or die "config apikey missing" };
has apiurl => sub { $ENV{SENDGRID_APIURL} || shift->config->{apiurl} || 'https://api.sendgrid.com/api/mail.send.json' };
sub mail { Mojo::Sendgrid::Mail->new(sendgrid => shift, @_) }
@s1037989
s1037989 / gist:835469a14fd164cc6161
Created March 8, 2016 16:40
helpers in Mojo::Template
use 5.022;
use lib 'lib';
use B;
say B->new->render('a.txt');
package A;
use Mojo::Base -base;
use Mojo::Loader 'data_section';
stefan@deskws:/tmp/convos$ git pull
Updating bbb9f29..ccfa6be
Fast-forward
script/convos | 42 ++++++++++++++++++++++++++++++------------
1 file changed, 30 insertions(+), 12 deletions(-)
stefan@deskws:/tmp/convos$ ./script/convos
---