Skip to content

Instantly share code, notes, and snippets.

View melo's full-sized avatar

Pedro Melo melo

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / bench_crc.pl
Created May 3, 2012 09:11
Digest::CRC vs String::CRC32
#!/usr/bin/env perl
use 5.014;
use warnings;
use Benchmark 'cmpthese';
use Digest::CRC ();
use String::CRC32 ();
my $payload = 'a' x 1024;
@melo
melo / Class.pm
Created April 26, 2012 09:27
My Perl class builder
package E6::Setup::Class;
use :5.14;
use warnings;
use utf8;
use Moose ();
use MooseX::HasDefaults::RO ();
use MooseX::StrictConstructor ();
use MooseX::AttributeShortcuts ();
use Try::Tiny ();
@melo
melo / gist:2365612
Created April 12, 2012 08:26
reminds me of something...
Naturally the common people don't want war... but after all it is the
leaders of a country who determine the policy, and it is always a
simple matter to drag the people along, whether it is a democracy, or
a fascist dictatorship, or a parliament, or a communist dictatorship.
Voice or no voice, the people can always be brought to the bidding of
the leaders. That is easy. All you have to do is tell them they are
being attacked, and denounce the pacifists for lack of patriotism and
exposing the country to danger. It works the same in every country.
-- Hermann Goering, Nazi and war criminal, 1883-1946
@melo
melo / .perltidyrc
Created March 4, 2012 09:34
The quest for the perfect .perltidyrc
# My (almost) perfect perl tidy config file
-l=100 # Max line width is 100 cols - We are not on vt100 line terminals anymore
-i=2 # Indent level is 2 cols
-ci=2 # Continuation indent is 2 cols
-se # Errors to STDERR
-vt=2 # Maximal vertical tightness
-cti=0 # No extra indentation for closing brackets
-pt=2 # High parenthesis tightness
-bt=2 # High brace tightness
@melo
melo / gist:1937200
Created February 29, 2012 02:54
Compiling perl 5.14.2 with perlbrew on CentOS 6 64bit with mod_perl support
# the fpic is needed for mod_perl
# so is usesshrplib
# use 64bitall just makes sense as uselargefiles
# the ldflags mimic the settings of the system perl
perlbrew install -j 8 5.14.2 \
-Dcccdlflags=-fPIC \
-Duseshrplib \
-Duse64bitall \