Skip to content

Instantly share code, notes, and snippets.

@chansen
chansen / benchmark.txt
Created October 13, 2014 19:21
Unicode::UTF8 vs Encode
$ perl benchmarks/bench.pl
perl: 5.020001 (darwin 13.3.0)
Encode: 2.60
Unicode::UTF8: 0.60
ar.txt: code points: 14308 (U+0000..U+007F: 2698 U+0080..U+07FF: 11610)
Rate Encode Unicode::UTF8
Encode 4121/s -- -83%
Unicode::UTF8 24613/s 497% --
@chansen
chansen / ago.pl
Created July 10, 2015 20:59
Simple and efficient formatting of relative date/time using Time::Moment
#!/usr/bin/perl
use strict;
use warnings;
use Carp qw[];
use Time::Moment 0.19 qw[];
sub YEAR () { 365.2425 }
sub MONTH () { YEAR / 12 }
sub DAY () { 1 }
@chansen
chansen / result.txt
Last active August 29, 2015 14:25
Benchmark of slurping UTF-8 encoded file in Perl
$ perl benchmarks/slurp.pl
perl: 5.023001 (darwin 14.4.0)
Encode: 2.75
Unicode::UTF8: 0.60
PerlIO::encoding: 0.21
PerlIO::utf8_strict: 0.006
ar.txt: Size: 25918 Code points: 14308 (U+0000..U+007F: 2698 U+0080..U+07FF: 11610)
Rate :encoding(UTF-8) Encode :utf8_strict Unicode::UTF8
@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 / 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
@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)
@chansen
chansen / id_rsa.pub
Created October 15, 2015 16:32
id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvkbSjboxgPOsq6rbKxww8taPipuM17Fj9xURQjIkEiunb+6mBumR+ct1d//O5Va6/t/srAg14KeQWEY6Ody+EC8DVI02TtX4buBc1rAL7BCRarLrTJCNYpJ9VLhu+h/u2x/3SgdMfHsBKbs65jqDIsSooXjyuJz3GDWrMDculQqwCiGGhkNPkzjdB1cXIOt8PEMRYV8/A/yqZtfIgd9lumT069m3xc1uKSScSpTSI4BeLMRTfydh5JlLATrBEPqHT/Iudb8xy37YdO0v0Et03eL5j8BID7RAZlnNq6ECV22doqBZ2UrfYnaqY/HeiekqaY52vNnATZ0pXlRItKvkuw== chansen@cpan.org