Skip to content

Instantly share code, notes, and snippets.

View fernandolopez's full-sized avatar

Fernando López fernandolopez

View GitHub Profile
@fernandolopez
fernandolopez / listcomprehensions.md
Created January 22, 2015 20:11
List comprehensions simuladas en Ruby

Trying to emulate list comprehensions syntax I came with this syntax that resembles haskell list comprehensions (by having several guards separated by , and allowing zero guards):

> (1..24).comp { |x| [x, x.even?, x > 6] }
=> [8, 10, 12, 14, 16, 18, 20, 22, 24]

> [nil, nil, 1, 2, 3, 4, 5].comp { |x| [x, x != 4] }
=> [nil, nil, 1, 2, 3, 5]

> [nil, nil, 1, 2, 3, 4, 5].comp { |x| [x] }

=> [nil, nil, 1, 2, 3, 4, 5]

@fernandolopez
fernandolopez / reproducir.py
Created May 27, 2014 18:01
Ejemplos de audio
# Con archivos grandes tarda mucho hay que usar audios cortos
# hay otro ejemplo más completo en:
# http://www.stuartaxon.com/2008/02/24/playing-a-sound-in-pygame/
import pygame
import time
pygame.init()
sound = pygame.mixer.Sound('audiobook.ogg')
canal = sound.play()
#!/bin/sh
# Transformar páginas de didiwiki a markdown
sed -i -r 's/\x00/\n/g' * # Las páginas de didiwiki terminan en \0
sed -i -r 's/\[(\S+)\s(.+)\]/[\2](\1)/g' * # Los links tienen formato distinto
# Los links locales no tienen extensión
sed -i -r 's/(\[.+\]\([^(https?:)].+)\)/\1.md)/g' *
sed -i -r 's/\[([^(https?:)][^]]+)\]\s+$/[\1](\1.md)/g' *
@fernandolopez
fernandolopez / deploy_ruby.sh
Last active December 14, 2020 19:49
Instalación de Ruby 2 con rbenv
#!/bin/bash
if [ ! -d "$HOME/.rbenv" ]; then
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
echo 'eval "$(rbenv init -)"' >> ~/.profile
fi
export PATH="$HOME/.rbenv/bin:$PATH"
@fernandolopez
fernandolopez / shell.py
Last active December 14, 2020 19:49
Ejemplo muy básico de un shell para ilustrar la diferencia de los comandos internos y comandos externos de los shells usados en sistemas operativos unix-like. El ejemplo no un estilo muy prolijo ni pythonico porque está pensado para ser fácil de entender para personas que no conocen el lenguaje.
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
#
# Ejemplo de un shell extremadamene rudimentario e incompleto
# para ilustrar la diferencia entre comandos internos
# y comandos externos
#
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential git-core curl libssl-dev \
libreadline5 libreadline5-dev \
zlib1g zlib1g-dev \
libmysqlclient-dev \
libcurl4-openssl-dev \
libxslt-dev libxml2-dev
@fernandolopez
fernandolopez / rvm_without_sudo.sh
Last active December 14, 2020 19:50
Install RVM without sudo
#!/bin/bash
# Change this:
RUBY_VERSION=1.9.3
echo "su -c apt-get install curl"
while ! su -c apt-get install curl; do
true
done
curl -L https://get.rvm.io | bash -s stable --autolibs=read-fail
if ! grep 'source $HOME/.bash_profile' ~/.bashrc; then
@fernandolopez
fernandolopez / unload_mod.sh
Last active December 14, 2020 19:50
unload_mod.sh unloads the selected linux kernel module and all the other modules that depends on it.
#!/bin/bash
###############################################################################
#
# Copyright 2013 Fernando E. M. López
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@fernandolopez
fernandolopez / run_boxed_dropbox.sh
Last active December 14, 2020 19:50
Boxed Dropbox permite ejecutar al mismo tiempo múltiples instancias de Dropbox asociadas a distintas cuentas.Requiere zenity y dropbox ya instalado en el PATH del sistema (paquete nautilus-dropbox en Debian).Si existe $HOME/Dropbox RENOMBRARLO o BORRARLO de otra manera el script descargará todo dentro del mismo.Uso:- Descargar en el home del usu…
#!/bin/sh
# run_boxed_dropbox.sh permite ejecutar al mismo tiempo múltiples
# instancias de Dropbox asociadas a distintas cuentas.
# Copyright (C) 2013 Fernando López <flopez [at] linti.unlp.edu.ar>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#!/bin/sh
if [ -n "$RANDOM" ]; then
# Bash
random(){ echo $RANDOM; }
elif which perl; then
random(){ perl -e "print(rand() * (10**15))"; }
elif which openssl; then
random(){ printf "%d" 0x$(openssl rand -hex $(date +%r)); }
else
random(){