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 / zip.mk
Created March 18, 2017 08:08
zip via Make
.PHONY: clean
recipes.zip: .
zip recipes.zip *.mk *.md
clean:
rm *~
@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 / 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 / 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 / Madhava-Leibniz-series-v2.sh
Last active March 22, 2021 08:11
Cool Perl 6 one liners vol. 2: computing Pi in a series
#You can also copy/paste this directly into the command line if perl6 is installed
raku -e "say π - 4 * ([+] <1 -1> <</<< (1,3,5,7,9...10000)) "
# This is an implementation of the Madhava-Lebniz series: https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80
# And a better, or at least shorter, version of https://gist.github.com/JJ/23801c82b218b25da7fc8831b7c331ad
# Instead of creating two series and combining them, this combines 1,-1 and the series of odd numbers
# by applying them successively: 1 divided by the first, -1 by the second, and so on. This creates exactly the same effect.
# It is faster and you only need to change one number, the 10000, to compute Pi with a bigger precision.
@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 / Fibonacci.pm
Created December 23, 2016 18:37 — forked from massa/Fibonacci.pm
Fibonacci sequence implementation in Perl6
my constant @fib = 1, 1, *+* ... *;
@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 / Submitting Rmd to Arxiv.md
Last active April 12, 2022 08:00
Submitting RMarkdown articles to Arxiv

Mini-HowTo submit RMarkdown articles to ArXiV

ArXiV is a place for publishing scientific technical reports and drafts which is tightly tied to LaTeX. That is why if you generate a PDF from your RMarkdown article it will tell you, hey, this has been generated using LaTeX, I want the LaTeX source. In principle, RStudio does not admit LaTeX as a final format, only .doc, .pdf or HTML. But it is no big deal.

You only need to add this to the metadata in the RMarkdown document

output: 
  pdf_document:
    keep_tex: true
@size = (1920, 1080);
@center = (-.743653135, .131826563);
$zoom = .000014628;
$max_it = 700;
$oversample = 2;
$_ *= $oversample for (@size);
open $fh, "|-", "convert -size ".join("x",@size)." -depth 8 gray:- ".
"-resize ".(100/$oversample)."% mandel.png";
for $py (1 .. $size[1]) {