Skip to content

Instantly share code, notes, and snippets.

View mfontani's full-sized avatar

Marco Fontani mfontani

View GitHub Profile
#!/bin/sh
# TO BE PLACED IN .git/hooks/prepare-commit-msg
# The first comments out the "Conflicts:" part of a merge commit.
# The second creates a template for a commit message
# The third example adds a Signed-off-by line to the message, that can
# still be edited. This is rarely a good idea.
# This hook is invoked by git commit right after preparing the default log
# message, and before the editor is started.
# It takes one to three parameters. The first is the name of the file that
@mfontani
mfontani / gist:4195954
Created December 3, 2012 16:03
Weird mark_raw problem with Xslate + wonky workaround
#!/usr/bin/env perl
use strict;
use warnings;
use Text::Xslate qw<mark_raw>;
use 5.010_000;
my $x = Text::Xslate->new(
function => {
p => sub {
return mark_raw( "L(@_)" );
@mfontani
mfontani / extract-subs.pl
Created December 29, 2011 12:23
Grab subroutines (and variable parameters!) from a Perl file
#!/usr/bin/env perl
use common::sense;
use PPI;
my $file = shift;
die "Need a file to operate on\n"
if !$file
|| !-f $file;
my $doc = PPI::Document->new($file);
@mfontani
mfontani / git-changefile
Created November 9, 2011 11:22
Which branches "change" this file, compared to the current branch?
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename qw<basename>;
my $file = shift
or die basename($0), ": need a file\n";
my @branches = map {
chomp;substr($_,2)
@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
@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 / 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 / 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 / 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.
# 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