Skip to content

Instantly share code, notes, and snippets.

View jjl's full-sized avatar

jjl

View GitHub Profile
use Modern::Perl;
use utf8;
use Carp;
use Want;
use CLASS;
use SUPER;
use autodie;
use autobox;
use autobox::Core;
use signatures;
use strict;
sub foo {
interceptive_block {
bar();
} intercept(baz => $baz) {
//$baz = 'baz'
}
}
sub bar {
@jjl
jjl / gist:5405191
Created April 17, 2013 15:21
Conversion from MySQL to other SQLs using SQL::Translate
#!/usr/bin/perl
use strict;
use warnings;
use SQL::Translator;
use File::Basename qw( basename dirname );
use Cwd qw( realpath );
use File::Temp qw( tempfile tempdir );
@jjl
jjl / gist:6140437
Created August 2, 2013 14:48
Django - code equivalent of the 'static' template tag
from django.core.files.storage import DefaultStorage
return DefaultStorage().url('/path/to/img.gif')
@jjl
jjl / gist:6140927
Created August 2, 2013 15:43
pretty-print-xml. I need to add this to the elisp repo
(defun bf-pretty-print-xml-region (begin end)
"Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this. The function inserts linebreaks to separate tags that have
nothing but whitespace between them. It then indents the markup
by using nxml's indentation rules."
(interactive "r")
(save-excursion
(nxml-mode)
(goto-char begin)
@jjl
jjl / gist:6251860
Created August 16, 2013 17:34
Python -> Ecmascript literal converter
print repr(structure) # they share the same syntax.
@jjl
jjl / printshape.py
Last active December 21, 2015 06:09
Print the shapes of nested data structures
def printshape(x):
children = lambda a: { printshape(b) for b in a }
fmt = lambda a,b: a.format("|".join(b))
together = lambda a,b: fmt(a, children(b))
if isinstance(x, list):
return together("list[{}]", x)
elif isinstance(x, set):
return together("set[{}]", x)
elif isinstance(x, tuple):
return together("tuple[{}]", x)
@jjl
jjl / ConnectToSharedNetwork.sh
Created August 28, 2013 12:33
Allowing machine C access to machine A's network via machine B
ssh -L1080:127.0.0.1:1080 userc@machineb
@jjl
jjl / normalisecsv.pl
Last active December 22, 2015 10:58
Useful things for cleaning up csv
use Text::CSV::Encoded;
use Encode qw(encode decode);
use autodie;
use feature ':5.16';
use strict;
use warnings;
sub go {
my $lineno = 1; # Sadly, using Text::CSV to read the lines (necessary for
# correctly handling embedded newlines) breaks $.
@jjl
jjl / LinAlg.hs
Created October 3, 2013 20:59
Linear Algebra. Or the little bit I need to know for something I've been working on.
-- Multiply a Row Vector by a Column Vector
multPerpendicularVecs = zipWith (*)
-- Multiply 2 Row Vectors (ugh, that's not supposed to happen), or 2x Col Vecs
multParallelVecs a b = fmap (* (sum a)) b