Skip to content

Instantly share code, notes, and snippets.

View rodolfo42's full-sized avatar
🎧

Rodolfo Ferreira rodolfo42

🎧
View GitHub Profile
@rodolfo42
rodolfo42 / install_vbox_guest_additions_docker.sh
Last active August 29, 2015 14:07
Downloads ISO w/ Guest Additions for Virtual Box v4.3.14 and sets up boot2docker to use it
#!/bin/bash
if [ -z $(which boot2docker) ]; then
echo "You must install boot2docker first"
echo "Your PATH: $PATH"
exit 1
fi
if [ -z $(which VBoxManage) ]; then
echo "You must have VBoxManager in your PATH"
@rodolfo42
rodolfo42 / callbacks_before_jquery.js
Created July 3, 2014 12:51
Code to simulate registering onload callbacks with $( <function> ) but before jQuery is included in the page
window.$ = (function () {
var cbs = [];
return function (callback) {
cbs.push(callback);
window.onload = function () {
while( !window.jQuery );
cbs.map(function (c) { c(); });
};
};
})();
@rodolfo42
rodolfo42 / update_all.sh
Created May 27, 2014 20:28
Update all repos that live under the first level of the current directory
#!/bin/bash
for D in *; do
if [ -d "${D}" ] && [ -d "${D}/.git" ]; then
echo "--> ${D}\n"
pushd "${D}"
git up
popd
fi
done
@rodolfo42
rodolfo42 / macro.sh
Created May 27, 2014 13:52
Install "Optimize Imports and Save" macro on IntelliJ IDEA 12/13
PREF="$HOME/Library/Preferences/"
if [ -r "$PREF/IntelliJIdea13" ]; then
folder="$PREF/IntelliJIdea13"
elif [ -r "$PREF/IntelliJIdea12" ]; then
folder="$PREF/IntelliJIdea12"
else
echo "Pasta do IntelliJ nao encontrada"
exit 1
fi
$(document).on('mousedown', 'a', function(e) {
if(($(this).attr('target') == '' || $(this).attr('target') != '_blank') && !new RegExp('/' + window.location.host + '/').test(this.href)) {
$(this).attr('target', '_blank');
}
});
diskpart
list disk
select disk #
clean
create partition primary
select partition 1
active
format fs=ntfs
assign
@rodolfo42
rodolfo42 / getOrElse.js
Created March 14, 2014 18:40
simple getOrElse in javascript
function getOrElse(value, _) {
var args = Array.prototype.slice.call(arguments);
for (var i = 0; i < args.length; i++) {
var arg = args[i];
if(typeof arg != "undefined" && arg != null && !isNaN(arg)) {
return arg;
}
}
return null;
}
#!/bin/bash
curl https://gist.githubusercontent.com/rodolfo42/6637163/raw/5e5258426eb8a8085dac4ce8074e8903b85dcee4/LocaleList.java > LocaleList.java
javac LocaleList.java
java LocaleList | less
String periodoInicial = null;
String periodoFinal = null;
String periodoInicialAux = null;
String periodoFinalAux = null;
if(buscaPor == 1) {
periodoInicial = request.getParameter("dataInicial");
periodoFinal = request.getParameter("dataFinal");
periodoInicialAux = request.getParameter("dataInicial");
periodoFinalAux = request.getParameter("dataFinal");
@rodolfo42
rodolfo42 / TailRecursion.md
Created October 22, 2013 15:48
Resumo sobre a apresentação de Tail Recursion para o Blog da Bluesoft

Tail Recursion

O paradigma da programação funcional está cada vez ganhando mais antenção no mercado, especialmente o interesse em linguagens funcionais como Scala, Clojure, LISP, Scheme, OCaml, entre outras.

Uma das razões para este interesse é o fato de que a maneira funcional de pensar vem se mostrando cada vez mais útil e produtiva em relação á abordagens tradicionais como orientação à objetos, especialmente para os novos problemas dos dias de hoje.

Na base do pensamento funcional está a premissa de que funções são representações como qualquer outra em uma linguagem, assim como números, strings e objetos e, portanto, podem ser definidas com liberdade, passadas como parâmetros para outras funções, serem valores de retorno de outras funções, etc.

Nesta apresentação, introduzo um aspecto da programação funcional que se chama tail recursion (ou tail call). É basicamente uma otimização que o compilador exerce ao detectar que a última expressão em uma função é em si nada mais que uma chamada para uma