Skip to content

Instantly share code, notes, and snippets.

View JJ's full-sized avatar
🏠
Working from home

Juan Julián Merelo Guervós JJ

🏠
Working from home
View GitHub Profile
@JJ
JJ / git-hooks.pl
Created August 26, 2013 17:07
Git post-commit hook for modifying .md files to work with gh-pages and just copy other files, like .png, .css and so on.
#!/usr/bin/env perl
use strict;
use warnings;
use v5.14;
use Git::Hooks;
use File::Slurp qw(read_file write_file);
my $layout_preffix=<<EOT;
---
@JJ
JJ / node-and-npm-in-30-seconds.sh
Last active January 3, 2016 11:59 — forked from isaacs/node-and-npm-in-30-seconds.sh
Installing node in a very raw box (like the one provided by docker). It will take a bit more than 30 seconds, somehow
#Problem with this is that it needs lots of installed stuff, so I'll put it here
# sudo or admin shell is presupposed
apt-get install make curl python-setuptools gcc g++
#Maybe you can safely supress make and gcc from here, since they are dependencies of g++
#Then you can proceed to the original set
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir /usr/local
mkdir ~/node-latest-install
@JJ
JJ / chef-solo.sh
Created January 24, 2014 07:27
Provisioning chef-solo for ArchLinux 2013
pacman -S ruby make gcc
gem install chef ohai --no-user-install
@JJ
JJ / get-diffs.pl
Created August 28, 2016 17:13
Extract number of lines changed per commit in a downloaded repository
#!/usr/bin/env perl
=head1 NAME
get-diffs.pl - Quantify diffs in a software repository
=head1 SYNOPSIS
First, install needed modules
@JJ
JJ / Madhava-Leibniz-series.sh
Last active January 6, 2017 11:29
Cool perl6 one liners vol. 2: Computing Pi from a series
#You can also copy/paste this directly into the command line if perl6 is installed
perl6 -e "say π - 4 * ([+] (( 1 <</<< (1,5,9...5000) ) Z ( -1 <</<< (3,7...5000))).flat)"
# This is an implementation of the Madhava-Lebniz series: https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80
# This script creates two series (1,5...) and (3,7) for even and odd positions in the sequence.
# Then, the inverse of the sequence is computed 1/(the sequence) with the 1<</<< construction
# Then they are zipped together using Z
# Finally, [+] sums all terms of the sequence together. Since the sequence is an approximation to π/4 it's multiplied by 4
# and then substracted from π. This should give a good 3-digit approximation. Change 5000 by a bigger number if you want bigger precision
@JJ
JJ / install_Git.pm.md
Last active January 6, 2017 11:32
Install Git.pm in a perlbrew installation

Git.pm is a module that comes with git and can't be installed with the usual cpan magic. If you switch to perlbrew you'll get a Can't locate Git.pm error when you try to run it, so you need to install it explicitly if you want to use it in your own installation, mainly if you use perlbrew I use it in my novels for post-commit hooks, so here's what you have to do to have it available in your programs

bash$ cp /usr/share/perl5/Git.pm ~/perl5/perlbrew/perls/perl-5.x.y/lib/site_perl/5.x.y

you'll have to change x.y by the perl version you're actually using. You'll also need Error.pm, so do

bash$ cp /usr/share/perl5/Error.pm ~/perl5/perlbrew/perls/perl-5.x.y/lib/site_perl/5.x.y

And that's it!

@JJ
JJ / dumb-cypher.sh
Created January 6, 2017 17:38
Perl6 one liners vol. 3: a very simple cypher
# This cypher applies character displacement to a set of letters using a "cypher" both users must have
perl6 -e "say (<1 -1 3 -3 4> <<+<< <t h i s i s s o s 1 k r i t>.map: {.ord}).map: {.chr}"
# In this case, the cypher is <1 -1 3 -3 4> and will be applied to the message after <<+<<
# You can retrieve the original message by applying the inverse of the cypher
perl6 -e "say (<-1 1 -3 3 -4> <<+<< <u g l p m t r r p 5 l q l q>.map: {.ord}).map: {.chr}"
@JJ
JJ / binomial-coefficient.sh
Created January 15, 2017 19:01
Perl6 one liners, vol 3: Print n over m, or the binomial coefficient for n and m
# The first argument will be n and entered into the $^ß placeholder, the second into the $^þ placeholder
perl6 -e 'say { ([*] 1..$^ß ) / ( [*] 1..$^þ) * ([*] 1..($^ß - $^þ)) }(@*ARGS[0],@*ARGS[1])' 20 11
# [*] 1..$^ß ) will compute the factorial by creating a range 1..$^ß and then multiplying all of them together.
# @*ARGS contains the arguments handled to the script; @*ARGS[0] will be the first and so on.
@JJ
JJ / backup.mk
Last active March 18, 2017 08:08
Backup using Make
.PHONY: clean
BKDIR = /tmp/copia
$(BKDIR): .
rsync -avz $< $@
clean:
rm *~
@JJ
JJ / zip.mk
Created March 18, 2017 08:08
zip via Make
.PHONY: clean
recipes.zip: .
zip recipes.zip *.mk *.md
clean:
rm *~