Skip to content

Instantly share code, notes, and snippets.

View fernandrone's full-sized avatar

Fernando Barbosa fernandrone

View GitHub Profile
@fernandrone
fernandrone / pow.clj
Created February 26, 2021 15:01
Clojure exponential/power function.
(defn pow [x n]
"x^n"
(if (>= n 0)
(->> x (repeat n) (reduce *))
(->> (pow (/ 1 x) (- n)))))
@fernandrone
fernandrone / topw
Last active February 1, 2021 15:12
Top N most-used words in a text
#!/usr/bin/env sh
#
# Simple script that prints out the top N most-used words in a text from standard input.
#
# Inspired by https://buttondown.email/hillelwayne/archive/donald-knuth-was-framed/. The short
# linux script is first shown at https://www.cs.tufts.edu/~nr/cs257/archive/don-knuth/pearls-2.pdf
topw() {
tr -cs A-Za-z '\n' | tr A-Z a-z | sort | uniq -c | sort -rn | sed "$N"q
}
@fernandrone
fernandrone / love.1
Last active March 1, 2020 01:54
whatis love
.TH "LOVE" "1" "Love User Manuals" "Fernando Barbosa" "FEBRUARY 2020"
.SH NAME
.PP
love \- baby don't hurt me, don't hurt me, no more
.SH AUTHOR
.PP
Fernando Barbosa (mail@fdr.one)
@fernandrone
fernandrone / gitbig.sh
Last active May 5, 2021 21:08
Returns the N biggest git refs
#!/bin/bash
# USAGE: gitbig N - returns the N biggest git refs (default N is 10).
#
# Note that to remove these refs you will need to rewrite the
# commit history. See https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html
# for more information.
if (( `find .git/objects/pack -name *.idx | wc -l` > 1 )); then
git gc --aggressive --prune=now
fi
@fernandrone
fernandrone / pprint
Created October 3, 2017 13:54
JSON Pretty Print
#!/bin/sh
echo "$1" | python -m json.tool