Skip to content

Instantly share code, notes, and snippets.

View jberger's full-sized avatar

Joel Berger jberger

View GitHub Profile
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@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
@jberger
jberger / URLQueue.pl
Last active November 10, 2022 20:58
Modularization of my answer from SO on URL queuing for non-blocking ua
#!/usr/bin/env perl
package Mojo::URLQueue;
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::UserAgent;
has queue => sub { [] };
has ua => sub { Mojo::UserAgent->new(max_redirects => 5) };
has concurrency => 4;
@dankrause
dankrause / _hover_example.py
Last active March 8, 2024 18:31
Example code to use the (unofficial, unsupported, undocumented) hover.com DNS API.
import requests
class HoverException(Exception):
pass
class HoverAPI(object):
def __init__(self, username, password):
params = {"username": username, "password": password}
r = requests.post("https://www.hover.com/api/login", params=params)
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
#!/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;
@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');
@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