Skip to content

Instantly share code, notes, and snippets.

View jberger's full-sized avatar

Joel Berger jberger

View GitHub Profile
@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
@pstuifzand
pstuifzand / MarpaX-JSON.pm
Last active December 10, 2015 14:28
A JSON parser in Marpa.
package MarpaX::JSON;
use strict;
use Marpa::R2 2.039_000;
sub new {
my ($class) = @_;
my $self = bless {}, $class;
$self->{grammar} = Marpa::R2::Scanless::G->new(
@wchristian
wchristian / gist:5119725
Created March 8, 2013 20:45 — forked from anonymous/gist:5119721
xml::libxml on windows
13-03-08@21:19:28 (jdb) http://paste.stacka.to/gejavoyifo.pl
13-03-08@21:19:51 (jdb) This is the script that is called to build libxml on the PPM builders.
13-03-08@21:20:33 (jdb) It assumes the tarball is already unpacked and the CWD is the top-level directory inside the tarball
13-03-08@21:21:19 (jdb) http://paste.stacka.to/furanimeli.avrasm
13-03-08@21:21:31 (jdb) This is the "control file"
13-03-08@21:24:58 (Mithaldu) can you give me links for the iconv sources you use?
13-03-08@21:25:34 (jdb) https://code.google.com/p/win-iconv/
13-03-08@21:26:05 (Mithaldu) and zlib?
13-03-08@21:26:33 (jdb) http://paste.stacka.to/guhelixuwo.pl
13-03-08@21:27:04 (jdb) http://zlib.net/zlib-1.2.5.tar.gz
sub _inlinify_css_rules {
my $self = shift;
my $html = shift;
my $dom = Mojo::DOM->new($html);
for my $selector ( sort keys %rules ) {
my $styler = sub {
my $element = shift;
my $style = $element->attrs('style') // q{};
@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
@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 }
{
"_source" : "module",
"aggregations" : {
"count" : {
"terms" : {
"field" : "distribution",
"size" : 999
}
}
},
#!/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;
(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) {
@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