Skip to content

Instantly share code, notes, and snippets.

View zakame's full-sized avatar

Zak B. Elep zakame

View GitHub Profile
@zakame
zakame / Dockerfile
Last active March 6, 2021 22:18
mojo-envoy
FROM perl:5.32-slim-buster
RUN cpanm -nq Mojolicious
COPY app.pl /
CMD ["/usr/local/bin/perl", "/app.pl", "daemon", "-l", "http://*:8080"]
@zakame
zakame / app.pl
Last active March 6, 2021 22:20
Tail a logfile with Mojolicious (for example /var/log/messages)
#!/usr/bin/env perl
use Mojolicious::Lite;
package Model::FileWatch {
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::Promise;
use IO::File;
has 'file';
#!/usr/bin/env perl
# Perl 5 version of https://gist.github.com/benjchristensen/4671081
# Using IO::Async and Future
use strict;
use warnings;
use feature 'say';
use curry;
use Future;
use IO::Async::Function;
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::JSON qw(encode_json);
use Mojo::UserAgent;
use Mojo::Util qw(md5_sum steady_time);
my $ua = Mojo::UserAgent->new->tap( sub {
shift->transactor->add_generator(
jsonrpc => sub {
my ( $t, $tx, $method, $params ) = @_;
[zakame@yorozuya:~] 130 % reply -Mversion
0> version->parse('0.2')->normal
$res[0] = 'v0.200.0'
1> version->parse('0.2.1')->normal
$res[1] = 'v0.2.1'
2> version->parse('v0.2')->normal
$res[2] = 'v0.2.0'
@zakame
zakame / bench_hash.pl
Created August 30, 2013 08:34
Benchmarking a few ways of splitting some lines and inserting into a hash
#!/usr/bin/env perl
use warnings;
use strict;
use Benchmark qw(:all);
use Text::CSV_XS;
# file with 1_000_000 entries of 'test|N,xxxN|noob' where N = number
my $file = '/tmp/test.txt';
@zakame
zakame / .gitignore
Last active December 20, 2015 03:29
Just some spike for me to pick up a few skills at once (Amon2::Lite, HTML5, Bootstrap, ParsleyJS, and Post/Redirect/Get)
.carton
local
@zakame
zakame / emacs-perlbrew.el
Created April 20, 2013 15:50
Fragment from my .emacs to get perlbrew working under it.
;; If perlbrew is used, get PERLBREW_PATH to be used in exec-path and PATH
;; Adapted from https://gist.github.com/960214
(require 'cl)
(let ((perlbrew-init "~/.perlbrew/init"))
(if (file-readable-p perlbrew-init)
(dolist (line (with-temp-buffer
(insert-file-contents perlbrew-init)
(split-string (buffer-string) "\n" t)))
(with-temp-buffer
(insert line)
@zakame
zakame / spike-oauth2
Created September 30, 2011 11:00
Wrapping my head around Google OAuth2 (for Google::Plus)
#!/usr/bin/env perl
use Mojolicious::Lite;
plugin 'OAuth2',
google => {
key => $ENV{GOOGLE_OAUTH2_CLIENT_ID},
secret => $ENV{GOOGLE_OAUTH2_CLIENT_SECRET},
};
my $service = 'https://www.googleapis.com';
@zakame
zakame / dotemacs.el
Created August 22, 2011 07:01
my .emacs (part of upcoming dotfiles repos)
;;; zakame.emacs --- My Emacs customizations
;; Copyright (C) 2005-2011 Zak B. Elep
;;;_* Package description
;; Author : Zak B. Elep ( [email protected] )
;; Date Created : Thu Sep 29 12:29:42 UTC 2005
;; Purpose : Set my personal customizations for the One True Editor.
;; Keywords : environment, customization
;; License : GNU General Public License (GPL), version 2