Skip to content

Instantly share code, notes, and snippets.

View melo's full-sized avatar

Pedro Melo melo

View GitHub Profile
@melo
melo / Explanation.txt
Created May 16, 2012 17:17
strange nginx behaviour with error_page + proxy_pass
I expected the first configuration below, simple.conf, to work just fine.
But it doesn't. My app server receives the second hit with the same URI as the first hit.
On the second config, wtf.conf, I keep the original URL on a variable to use in the error redirect.
My question is this: why doesn't the first simple.conf configuration works?
@melo
melo / ssh.pl
Created May 29, 2012 16:19
A sample Net::SSH2 command line talking to a inline remote perl script
#!/usr/bin/env perl
use v5.14;
use strict;
use Net::SSH2;
my $user = shift(@ARGV) || usage('Missing user');
my $host = shift(@ARGV) || usage('Missing host');
my $port = shift(@ARGV) || 22;
@melo
melo / hand_coded_nester.pl
Created May 30, 2012 17:21
Having fun nesting DBI results
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
## The ouput of a DBI querie with multiple nested join's
my @raw = (
{ p1_id => 1, p1_n => 'a', p2_pa => 1, p2_pb => 1, p2_pn => 'p1', p3_s => 1, p3_sn => 's1' },
@melo
melo / 11-db-sql.t
Created June 6, 2012 18:18
Add support for table joins to SQL::Abstract select()
#! perl
use strict;
use warnings;
use Test::More;
use MyTK::DB::SQL;
my $sql = MyTK::DB::SQL->new;
subtest '__build_from' => sub {
@melo
melo / x-music-what-who
Created June 8, 2012 10:19
What is the music playing? \cc @consttype :)
#!/bin/sh
# hat tip to @consttype: https://twitter.com/#!/consttype/status/211035411026427904
osascript -e 'tell application "iTunes" to pause'
x='tell application "iTunes" to get'
y='of current track as string'
say Title is `osascript -e "$x name $y"` . Author is `osascript -e "$x artist $y"`
@melo
melo / smzp_sinopsys.md
Created August 1, 2012 11:37
mzp synopsis

mpz synopsis

mpz is a ZeroMQ-based pipe.

It will read stuff from STDIN and output to ZeroMQ sockets, and read from ZeroMQ sockets and send to STDOUT. Works fine for line- based streams.

Supports 1-to-1, 1-to-N and N-to-1. There is a special mode to start as a forwarder to support N-to-N topologies.

@melo
melo / test.c
Created August 21, 2012 16:11
Strange problem with ZeroMQ perl bindings + fork
//
// Demonstrate that zmq_init followed by fork does not die
//
// Compile/run:
//
// cc -lzmq -o test test.c ; ./test
//
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#!/usr/bin/env perl
#
# Filesystem changes trigger
use v5.14;
use FindBin;
use lib "$FindBin::Bin/../lib";
use E1::Setup::Perl;
use Filesys::Notify::Simple;
@melo
melo / C1.pm
Created September 24, 2012 14:19
Open-ended role exclusion
package C1;
use Moose;
with 'R1'; ## this works
with 'R2'; ## this also works
with 'R1', 'R2'; ## this will fail
1;
#!/bin/bash
#
# PS1 magic
#
# Mostly copied from YUVAL KOGMAN version, added my own __git_ps1 stuff
# Original: http://gist.github.com/621452
#
# See video demo of this at http://vimeo.com/15789794
#
# To enable save as .bash_prompt in $HOME and add to .bashrc: