Skip to content

Instantly share code, notes, and snippets.

View belden's full-sized avatar

Belden Lyman belden

View GitHub Profile
@belden
belden / gist:1958828
Created March 2, 2012 14:44 — forked from Ovid/gist:1957853
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';
@belden
belden / The output
Created May 9, 2012 17:20
Perl functions by prototype
# this is for Perl v5.10.1
#
($$$$$)
msgrcv
($$$$)
semctl
shmread
shmwrite
@belden
belden / toy-exception.pl
Created May 23, 2012 13:36
Locally replace die to not.
#!/usr/bin/env perl
use strict;
use warnings;
use Want qw(rreturn);
use Test::Resub qw(resub);
BEGIN { *CORE::GLOBAL::die = sub { CORE::die(@_) } }
use Data::Dumper;
@belden
belden / y-combinator.js
Created August 22, 2012 20:26
y-combinator.js
// Here's a simple lambda combinator; it'll turn the function passed in
// into a function which, when called, returns a recursible copy of itself.
function y_combinator(curried) {
return function(f1){
return curried(function () { f1(f1)(arguments) });
}(function (f2) {
return curried(function () { f2(f2)(arguments) });
});
}
@belden
belden / y-combinator.pl
Created August 22, 2012 20:55
y-combinator.pl
#!/usr/bin/env perl
use strict;
use warnings;
sub y_combinator (&) {
my $curried = shift;
return sub {
my $f1 = shift;
return $curried->(sub { $f1->($f1)(@_) });
}->(sub {
@belden
belden / sticky-inc.patch
Created February 21, 2013 01:02
lib::with::preamble places a code hook at the beginning of @inc, and then relies upon that hook remaining at $INC[0]. In a suitably complicated codebase, there is likely to be one module which modifies the head of @inc, and some subsequent module which violates the constraints that lib::with::preamble is intended to enforce. Included in the patc…
diff --git a/Makefile.PL b/Makefile.PL
index cfc4d6d..8e90634 100644
--- Makefile.PL
+++ Makefile.PL
@@ -8,5 +8,8 @@ WriteMakefile(
NAME => 'lib-with-preamble',
VERSION_FROM => 'lib/lib/with/preamble.pm',
PM_FILTER => 'perl my/filter',
- PREREQ_PM => { 'PerlIO::via::dynamic' => 0.02 },
+ PREREQ_PM => {
@belden
belden / maybe.pl
Created March 18, 2013 14:55
Whenever I look at Patterns::UndefObject I want it to act more like this instead.
#!/usr/bin/env perl
{
package maybe;
use overload 'bool' => sub { 0 };
sub new { bless \$_[0] }
sub DESTROY {}
sub AUTOLOAD { shift }
}
@belden
belden / gmtime-for-cookies.pl
Created April 24, 2013 15:28
Testing equivalence: gmtime for cookies from an epoch
# instruct Test::Easy's time-equivalence function how to compare an epoch timestamp
# to something like "Wed, 24-Apr-2013 16:15:38 GMT"
Test::Easy::Time->add_format(
_description => 'gmtime for cookies',
format_epoch_seconds => sub {
Inhalation of crystalline silica is harmful to the lungs, causing
silicosis. Amorphous silica is considered to be low toxicity, but prolonged
inhalation cause changes to the lungs.[24] Diatomaceous earth is mostly
amorphous silica, but contains some crystalline silica, especially in the
saltwater forms.[25] In a study of workers, those exposed to natural DE for
over 5 years had no significant lung changes, while 40% of those exposed
to the calcined form had developed pneumoconiosis.[26] Today's common
D.E. formulations are safer to use as they are predominantly made up of
amorphous silica and contain little or no crystalline silica.[27]
@belden
belden / tail-factorial.pl
Created December 2, 2013 23:03
Tail recursion pattern in Perl - for some reason people say Perl doesn't have tail recursion; you just need to do a little extra work.
#!/usr/bin/env perl
use strict;
use warnings;
use bigrat;
my $n = shift || 100;
print "$n! = " . tail_factorial($n) . "\n";