Skip to content

Instantly share code, notes, and snippets.

View jberger's full-sized avatar

Joel Berger jberger

View GitHub Profile
@jberger
jberger / graphite
Last active September 26, 2023 15:05
A little graphite CLI tool
#!/usr/bin/env perl
use Mojo::Base -strict;
use Getopt::Long qw(:config gnu_getopt no_auto_abbrev no_ignore_case);
use Mojo::Date;
use Mojo::URL;
use Mojo::UserAgent;
use Mojo::Util 'tablify';
@kraih
kraih / Auth.pm
Last active September 25, 2018 18:34
Bits and pieces that will hopefully some day become an OpenID plugin for Mojolicious (with alternative dummy backend for testing and token backend for API users)
package MyApp::Controller::Auth;
use Mojo::Base 'Mojolicious::Controller';
sub check {
my $self = shift;
my $role = $self->stash('role');
my $user = $self->current_user;
# User needs to log in or a different role
(function(w) {
/*
* Allow multiple clients share the same connection, but send/receive data on a topic they want
*
* var ws = WebSocketChannel("wss://example.com/mux", "testTopic");
* var ws = WebSocketChannel("wss://example.com/mux", {topic: "..", protocols: ...});
* var ws = WebSocketChannel({url: "wss://example.com/mux", topic: "..", protocols: ...});
* ws.onopen = function(e) { this.send({some: data}) };
*/
w.WebSocketChannel = function(url, params) {
@Ovid
Ovid / .perldb
Last active July 5, 2022 15:50
My debugger file
package Ovids::Debugger;
# vim: syntax=perl
=head1 NAME
.perldb - Customize your Perl debugger
=head1 USAGE
{
"_source" : "module",
"aggregations" : {
"count" : {
"terms" : {
"field" : "distribution",
"size" : 999
}
}
},
@exodist
exodist / test.pl
Created May 30, 2016 14:50
minimal inline testing
sub ok($;$) {$_[0] || $T::FAIL++; print( ($_[0] ? "ok " : "not ok ") . ++$T::NUM . ($_[1] ? " - $_[1]\n" : "\n"))}
sub done_testing { print "1..$T::NUM\n" }
END { $? ||= $T::FAIL; $? = 255 if $? > 255 }
@plicease
plicease / gist:b51c70df4c516a89912d
Last active August 29, 2015 14:22
extract_uv_handle_type.pl
use strict;
use warnings;
use 5.010;
use Convert::Binary::C;
my $c = Convert::Binary::C->new;
$c->Include(qw(
/usr/include
/usr/include/x86_64-linux-gnu/
/usr/include/linux
@kraih
kraih / Coro.pm
Last active April 19, 2019 13:48
package Mojolicious::Plugin::Coro;
use Mojo::Base 'Mojolicious::Plugin';
use Coro;
use Mojo::IOLoop;
# Wrap application in coroutine and reschedule main coroutine in event loop
sub register {
my ($self, $app) = @_;
my $subscribers = $app->plugins->subscribers('around_dispatch');
#!/usr/bin/env perl
use Mojolicious::Lite;
use Coro;
use Mojo::IOLoop;
# Magical class for calling a method non-blocking (with a closure) and
# rescheduling the current coroutine until it is done
package with::coro {
use Coro;
@tempire
tempire / gist:5621542
Last active December 17, 2015 13:59
Non-blocking request within a Mojolicious app
get '/' => sub {
my $self = shift;
my $ua = Mojo::UserAgent->new;
my $tx = $ua->build_tx(GET => 'http://tempi.re');
$tx->on(finish => sub {
my $tx = pop;
warn $tx->error; # premature connection close