Skip to content

Instantly share code, notes, and snippets.

@chansen
chansen / test.pl
Created February 16, 2012 23:58
US § 6103. HOLIDAYS (Federal)
#!/usr/bin/perl
use strict;
use warnings;
do 'us_federal_holidays.pl';
# Test cases extracted from <http://www.opm.gov/Operating_Status_Schedules/fedhol/Index.asp>
my @tests = (
[ 1997, '1997-01-01', '1997-01-20', '1997-02-17', '1997-05-26', '1997-07-04',
'1997-09-01', '1997-10-13', '1997-11-11', '1997-11-27', '1997-12-25' ],
@chansen
chansen / fix_latin.pl
Created December 26, 2011 22:22
Decodes UTF-8, interpreting ill-formed UTF-8 sequences as CP1252, posted in reply to <http://blog.endpoint.com/2011/12/sanitizing-supposed-utf-8-data.html>
#!/usr/bin/perl
use strict;
use warnings;
use Encode qw[find_encoding];
use Unicode::UTF8 qw[decode_utf8];
{
my $encoding = find_encoding('Windows-1252')
or die q/Couldn't find Windows-1252 encoding/;
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Response;
my $response = HTTP::Response->new(
200, 'OK', [ 'Content-Type' => 'multipart/form-data' ]
);
@chansen
chansen / bug.pl
Created September 24, 2011 13:52
Reproducible test case for CVE-2011-2766
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Fast qw[];
use FCGI qw[];
use IO::Socket::INET qw[];
use Net::FastCGI::Constant qw[:common :type :role];
use Net::FastCGI::IO qw[ read_record
@chansen
chansen / benchmark results
Created April 11, 2011 21:27
Comparison of hash objects with packed objects (SvPV)
/opt/perl/5.13.11/bin/perl packed_vs_hash.pl
Benchmarking constructor
Rate hash pack
hash 445987/s -- -10%
pack 496264/s 11% --
Benchmarking accessor
Rate vec hash
vec 1190203/s -- -9%
hash 1308227/s 10% --
@chansen
chansen / json.pl
Created February 3, 2011 21:55
PP json parser
#!/usr/bin/perl
use strict;
use warnings;
use Carp qw[];
my $WS = '[\x20\x09\x0A\x0D]*';
sub err {
@chansen
chansen / fastcgi-ping.pl
Created April 17, 2010 11:21
fastcgi-ping.pl
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket qw[];
use Net::FastCGI::Constant qw[ :type FCGI_NULL_REQUEST_ID FCGI_HEADER_LEN ];
use Net::FastCGI::Protocol qw[ build_record parse_header get_type_name ];
sub fatal ($;$);
sub timeout (&$$);