Skip to content

Instantly share code, notes, and snippets.

View mfontani's full-sized avatar

Marco Fontani mfontani

View GitHub Profile
#!/usr/bin/env perl
use Mojolicious::Lite;
my $use_auth = 1; # with auth enabled..
my ( $user, $pass ) = qw/user password/;
if ($use_auth) { plugin 'basic_auth'; }
get '/' => sub { my $self = shift; $self->redirect_to('/upload'); };
get '/upload' => sub {
my $self = shift;
#!/usr/bin/env perl
use strict;
use warnings;
# List of previously installed modules was created with:
# perldoc -o text perllocal | grep '"Module"' | cut -d'"' -f3 | cut -d' ' -f2
my $installed = shift;
$installed = "$ENV{HOME}/perl-installed-20100908-1917.txt" unless defined $installed;
print "Using modules list from $installed\n";
@mfontani
mfontani / 4005150.pl
Created October 23, 2010 17:56
Answer on SO
use strict;
use warnings;
# Column details and sample line, from the post
my $header = q{0 AOZSVIN, TAMSSZ B A A- B+ B B- C+ C C- D+ D D- F CR P PR I I* W WP WF AU NR FN FS};
my $sample = q{0 AAS 150 23 25 16 35 45 14 8 10 2 1 1 4 4 };
# -+--------+-----+-----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---..
# chars 1212345678912345612345612341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234...
# num. chars: 2 9 6 6 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 *
my $unpack = q{A2A9 A6 A6 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A*};
@mfontani
mfontani / repack-git-repos.sh
Created November 8, 2010 19:34
Repack all my Git repos, si vous plait!
#!/bin/sh
# Marco Fontani - MFONTANI at cpan dot org
# Repack all the .git repos from the current directory
# using 8 processes at once
find . -type d -name '.git' | \
xargs -I{} -P8 \
sh -c "(cd {}/..; git gc; echo done {})2>/dev/null"
# scripts/capsule.sh
if [ -f 'dist.ini' ]; then
echo "Found dist.ini, using Dist::Zilla"
#dzil authordeps | cpanm
#cpanm --installdeps .
echo "Installing author deps" >> $logfile
dzil authordeps | cpanm >> $logfile 2>&1
echo "Installing dist deps" >> $logfile
dzil listdeps | cpanm >> $logfile 2>&1
@mfontani
mfontani / log-deployment.txt
Created April 29, 2011 23:06
Deploying a dancer webapp to DotCloud.com
Dancing on the cloud
okram@BLUEDESK ~> sudo aptitude install python-setuptools
[...]
okram@BLUEDESK ~> sudo easy_install dotcloud
[...]
okram@BLUEDESK ~> dotcloud
Warning: /home/okram/.dotcloud/dotcloud.conf does not exist.
@mfontani
mfontani / go-to-perl-module-source.vim
Created May 3, 2011 12:11
Vim: {v,}split source file for Perl module under cursor
" split edit the source file for the Perl module under the current WORD
nnoremap ,m :execute 'spl `perldoc -l ' . expand("<cWORD>") . '`'<CR>
nnoremap ,M :execute 'vspl `perldoc -l ' . expand("<cWORD>") . '`'<CR>
@mfontani
mfontani / raptor.sh
Created June 23, 2011 13:10
raptor -- type less to do more with a Perl one-liner
# Based on http://blogs.perl.org/users/randy_stauner/2011/06/exploratory-one-liners-with-less-typing.html
# and a couple more things which are *really* handy
function raptor {
case "$1" in
-*) break ;;
'')
echo "Syntax: raptor [-lneEp etc] 'code'
The code can make use of:
DD() to Data::Dumper::Dumper() a thing, D() to say() it
YY() to YAML::Dump() a thing, Y() to say() it
@mfontani
mfontani / perl_miner.pl
Created June 27, 2011 08:16
A (test,simplistic) Perl bitcoin miner
#!/usr/bin/env perl
use 5.010_001;
use strict;
use warnings;
use Digest::SHA;
use JSON::XS;
use WWW::Mechanize;
use Time::HiRes qw<time gettimeofday tv_interval>;
use Getopt::Long;
@mfontani
mfontani / git-rr
Created June 28, 2011 16:46
git-rr: show which files were changed in commits, when rebasing
#!/bin/sh
# Usage:
# Once you started git rebase --interactive master, and you are presented
# with the list of commit SHAs and commit messages, from Vim:
# - visually select all SHAs via "V}k"
# - launch git-rr: !git-rr
# - ...
# - profit! you now have the same info as before, just with the list of
# filenames which changed with each commit, and can now move around