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:

@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)
@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';
@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;
@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
@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');
@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) {
#!/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;
{
"_source" : "module",
"aggregations" : {
"count" : {
"terms" : {
"field" : "distribution",
"size" : 999
}
}
},