Skip to content

Instantly share code, notes, and snippets.

@hernan604
hernan604 / gist:6928422
Last active December 25, 2015 05:59
Dadas 3 listas com números, encontrar os que aparecem em ao menos 2 listas \ Given 3 lists with numbers, find the ones that appear in at least 2 lists
from the internet:
my @array1 = (1, 2, 3, 4);
my @array2 = (2, 3, 4);
my @array3 = (2, 5, 4);
my %original = ();
my @isect = ();
map { $original{$_} = 1 } @array1;
@isect = grep { $original{$_} } @array2;
@hernan604
hernan604 / gist:6955005
Created October 12, 2013 21:14
generate one tiled image from multiple images
use strict;
use warnings;
use Imager::Montage;
use Data::Printer;
my $imgs =# <*.*>;
[
'11.JPG',
'14.JPG',
'2.JPG',
@hernan604
hernan604 / gist:7032435
Created October 17, 2013 21:24
Basic readline example allows mount of a list of servers
use Term::ReadLine;
my $servers = [
{
servidor1 => 'mount /dev/x1 /mount/servidor1',
},
{
servidor2 => 'mount /dev/x2 /mount/servidor2',
},
{
@hernan604
hernan604 / gist:7083667
Created October 21, 2013 13:13
HTTP::Tiny request with gzip plus response decompress
use HTTP::Tiny;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
use Data::Printer;
my $ua = HTTP::Tiny->new(
agent => "Mozilla/5.0 (Windows 8; rv:24.0) Gecko/20100101 Firefox/24.0" ,
default_headers => {
'Accept-Encoding' => 'gzip'
}
) ;
@hernan604
hernan604 / gist:7123681
Last active December 26, 2015 08:39
quick perl code generator
#quick perl code generator, im pretty sure mst mentioned this tip, so here it is
use strict;
use warnings;
use IO::All;
use Encode qw/decode encode/;
use v5.10;
use Path::Class;
my $config = {
#!/usr/bin/perl
use Mysql;
use strict;
use vars qw($school_name);
use vars qw($pass);
require "./cgi-lib.pl";
@hernan604
hernan604 / gist:7365314
Created November 8, 2013 02:25
WWW Vimeo Download november 2013 version
use Moose;
use HTTP::Tiny;
use JSON::XS;
use DDP;
my $video_id = "78802560";
my $ua = HTTP::Tiny->new();
my $res = $ua->get( "http://vimeo.com/".$video_id );
my ( $stuff, $key ) = $res->{ content } =~ m!data-config-url="([^"]+)&amp;s=([a-zA-Z0-9]+)"!;
warn $key;
@hernan604
hernan604 / proxy.pl
Last active December 28, 2015 08:09
http proxy interceptor example.
#build your proxy class with the plugins you want
package My::Proxy;
use Moose;
extends qw/HTTP::Proxy::Interceptor/;
with qw/
HTTP::Proxy::InterceptorX::Plugin::ContentModifier
/;
# with qw/
# HTTP::Proxy::InterceptorX::Plugin::File
@hernan604
hernan604 / SmallExcerptBetweenTwoWords.pm
Last active December 28, 2015 20:39
Given a book, and two words from that book, create a method to give the smallest number of words between those two words.
package SmallExcerptBetweenTwoWords;
use strict;
use warnings;
use utf8;
use DDP;
use Moo;
=head1 SYNOPSIS
Given a book, and two words from that book, create a method to give the smallest number of words between those two words. Assume that the book is large (over 500 pages) and memory usage and performance is a concern.
@hernan604
hernan604 / gist:7573659
Created November 21, 2013 00:12
read file in chunks
open FILE, "text";
my $text;
while ( read FILE, $text, 10 ) {
warn $text;
}
open FILE, "text";
my $text;
while ( sysread FILE, $text, 10 ) {