Skip to content

Instantly share code, notes, and snippets.

@pdl
pdl / .block
Last active February 26, 2016 11:35 — forked from mbostock/.block
[ISSUE] d3.zoom and bootstrap tooltips
license: gpl-3.0
@pdl
pdl / pl2js.pl
Created June 22, 2015 09:21
Convert perl scripts to javascript with the awesome power of regular expressions.
#!perl -w
=head1 NAME
pl2js.pl
=head1 DESCRIPTION
Attempts to convert perl scripts to javascript with the awesome power of regular expressions.
@pdl
pdl / ack-blame
Last active April 10, 2017 10:18
ack plus git blame
# ack Module::Load --output='@{[`git blame $_[1] -L $.,$. | perl -e "chomp and print while <STDIN>"`]}'
alias ack-blame="ack --output='@{[\`git blame \$_[1] -L \$.,\$. | perl -e \"chomp and print while <STDIN>\"\`]}'"
@pdl
pdl / libxml_element.pl
Created February 24, 2014 14:03
Quickly create a new element using XML::LibXML
sub element {
my $name = shift;
my $element = XML::LibXML::Element->new($name);
my $next = shift;
if (ref $next eq ref {}){
foreach my $attrName (keys %$next){
$element->setAttribute ($attrName, $next->{$attrName});
}
$next = shift;
@pdl
pdl / libxml_threads.pl
Created January 2, 2014 17:35
Using Threads and XML::LibXML appears to cause a memory allocation bug.
use strict;
use warnings;
use threads;
use Thread::Queue;
my $q = Thread::Queue->new(); # A new empty queue
my $q2 = Thread::Queue->new(); # A new empty queue
use XML::LibXML qw(:threads_shared);
my $parser = XML::LibXML->new;
@pdl
pdl / first_or_all.pl
Created July 17, 2013 14:20
Demonstrate simple function to return the first item in an array if called in scalar context.
#!perl
use strict;
use warnings;
use Test::More;
sub first_or_all {
return @_ if wantarray;
return shift;
}
@pdl
pdl / self-sorting-script.pl
Created January 24, 2013 20:45
A script which sorts itself
no less; use strict; use warnings;
open (my $fhIN, '<', $0) or die; my @lines = <$fhIN>;
open (my $fhOUT, '>', $0) or die;
print $fhOUT sort {$a cmp $b} @lines;
@pdl
pdl / subclasshash.pl
Created January 1, 2013 18:35
Is there a perl module that allows inheritance like a compile-time modifiable symbol table?
use strict;
use warnings;
use 5.010;
{
package A;
our $hash={1=>'i',2=>'j'};
}
{
@pdl
pdl / overload-stringify.pl
Created November 11, 2012 17:28
Why do overloaded objects bechave differently depending on their construction?
package Acme::Object::Overloaded;
use overload '""' => sub{ 'String' }, '0+' => sub{ 123 }, 'fallback' => '0+';
sub new{
bless {}, shift;
}
1;
package main;
@pdl
pdl / pl2py.pl
Created October 23, 2012 14:28
Convert perl scripts to python with the awesome power of regular expressions.
#!perl -w
=head1 NAME
pl2py.pl
=head1 DESCRIPTION
Attempts to convert perl scripts to python with the awesome power of regular expressions.