Skip to content

Instantly share code, notes, and snippets.

View Ovid's full-sized avatar

Ovid Ovid

View GitHub Profile
@Ovid
Ovid / perlc.pl
Created December 6, 2011 17:00
Rerun perl -c with warnings unused
#!/usr/bin/env perl
use Modern::Perl;
use File::Temp 'tempfile';
use IO::All;
my $libcustom = '.libcustom';
# run the code with perl -c and show STDERR if it fails. Otherwise, rerun it
# with perl -c -Mwarnings::unused
@Ovid
Ovid / unicode_cmp.pl
Created February 9, 2012 08:55
Unicode Collation Algorithm in Perl
use strict;
use warnings;
use utf8::all;
use Test::More;
use Unicode::Collate;
my $a1 = "\N{U+212B}"; # Å
my $a2 = "\N{U+00C5}"; # Å
my $a3 = "\N{U+0041}\N{U+030A}"; # Å
@Ovid
Ovid / version.pl
Created February 18, 2012 10:18
Strange syntax error when asserting version
use strict;
use warnings;
use Devel::Peek;
Dump $_ for .96, 0.96;
# this is fine
eval "use Data::Dumper 0.01 'Dumper'";
my $error = $@ || "none";
print "\nError is: $error\n";
@Ovid
Ovid / gist:1957853
Created March 2, 2012 11:16
perlfind -- perldoc on steroids
#!/usr/bin/env perl
use strict;
use warnings;
use Carp qw(cluck);
use autodie ':all';
use Getopt::Long 2.33 qw(:config auto_help);
use File::Find::Rule;
use File::Basename 'basename';
@Ovid
Ovid / gist:2035495
Created March 14, 2012 10:01
strace of failed git push
execve("/usr/bin/git", ["git", "push", "-v", "origin", "users/ovid"], [/* 66 vars */]) = 0
brk(0) = 0x13f3000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3804f8f000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=80249, ...}) = 0
mmap(NULL, 80249, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f3804f7b000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
@Ovid
Ovid / gist:2263374
Created March 31, 2012 12:26
How to lie to the debugger about what its lines of code are
# lie to the debugger about what the lines of code are
no strict 'refs';
my $line_num = 0;
foreach ( @{"::_<$filename"} ) {
# uncomment these to blow your f'in mind
#if ( not defined ) {
# use Devel::Peek;
# warn "line number is $line_num";
# Dump($_);
@Ovid
Ovid / federal_register.pl
Created April 13, 2012 07:27
Federal Register XML Documents
# Fetch Federal Register daily XML documents
# I decided not to include this in my book.
#
# This script is for daily updates and will be slow. Go to
# http://www.gpo.gov/fdsys/bulkdata/FR to download a year
# worth of documents at a time in .zip format. This script
# can then keep you up to date.
use strict;
use warnings;
@Ovid
Ovid / gist:2415513
Created April 18, 2012 18:10
Can you spot this bug in this line from YAML::Mo?
# Why do people think this stuff is clever?
no warnings;my$M=__PACKAGE__.::;*{$M.Object::new}=sub{bless{@_[1..$#_]},$_[0]};
*{$M.import}=sub{import warnings;$^H|=1538;my($P,%e,%o)=caller.::;shift;
eval"no Mo::$_",&{$M.$_.::e}($P,\%e,\%o,\@_)for@_;return if$e{M};
%e=(extends,sub{eval"no $_[0]()";@{$P.ISA}=$_[0]},has,sub{my$n=shift;
my$m=sub{$#_?$_[0]{$n}=$_[1]:$_[0]{$n}};$m=$o{$_}->($m,$n,@_)for sort keys%o;
*{$P.$n}=$m},%e,);*{$P.$_}=$e{$_}for keys%e;@{$P.ISA}=$M.Object};
*{$M.'builder::e'}=sub{my($P,$e,$o)=@_;$o->{builder}=sub{my($m,$n,%a)=@_;
my$b=$a{builder}or return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=
$_[0]->$b:$m->(@_)}}};*{$M.'default::e'}=sub{my($P,$e,$o)=@_;$o->{default}
@Ovid
Ovid / gist:3142826
Created July 19, 2012 10:02
Integrating perlcritic and vim
#!/usr/bin/env perl
# in your .vimrc
# " quickfix for Perl error formats
# set errorformat+=%m\ at\ %f\ line\ %l\.
# set errorformat+=%m\ at\ %f\ line\ %l
# noremap ,c :!time perlc --critic %<cr>
use 5.10.0;
use File::Temp 'tempfile';
@Ovid
Ovid / gist:3350491
Created August 14, 2012 16:00
throws_ok should use classnames, not regexes
throws_ok { $job_rs->add_job }
qr/Mandatory parameters.*missing/,
'... and it should fail with no arguments';
my %args = (
third_party_key => 'not a valid key',
client_id => 1111111111,
campaign_id => 2222222222,
ad_group_id => 3333333333,
);