Skip to content

Instantly share code, notes, and snippets.

@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 (&$$);
@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 / 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 / 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
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Response;
my $response = HTTP::Response->new(
200, 'OK', [ 'Content-Type' => 'multipart/form-data' ]
);
@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/;
@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 / perlio-scalar-eof.patch
Created March 25, 2012 23:36
PerlIO::scalar patch
diff --git a/ext/PerlIO-scalar/scalar.xs b/ext/PerlIO-scalar/scalar.xs
index eac682b..d324bdd 100644
--- a/ext/PerlIO-scalar/scalar.xs
+++ b/ext/PerlIO-scalar/scalar.xs
@@ -125,6 +125,18 @@ PerlIOScalar_tell(pTHX_ PerlIO * f)
return s->posn;
}
+IV
+PerlIOScalar_eof(pTHX_ PerlIO * f)
package unicode;
use strict;
use warnings;
use warnings::register;
use Carp qw[croak cluck];
use Encode qw[];
# from perl.h verified in 5.6.2, 5.8.9, 5.10.1 and blead (2010-02-27)
sub HINT_BLOCK_SCOPE () { 0x00000100 }
@chansen
chansen / eigen.pl
Created September 6, 2013 12:30
Transparent singleton methods in Perl
#!/usr/bin/perl
use strict;
use warnings;
# Transparent singleton methods in Perl
# First a new anonymous class is created to hold the object's singleton
# methods, this anonymous class assumes the role of the object's class
# and the original class is designated as the super class of that anonymous
# class. This is completely transparent and the anonymous class can't be
# referenced by name.