Skip to content

Instantly share code, notes, and snippets.

View cosmoscalibur's full-sized avatar
🎯
Focusing

Edward Villegas-Pulgarin cosmoscalibur

🎯
Focusing
View GitHub Profile
@cosmoscalibur
cosmoscalibur / arbitrary_args
Created September 30, 2013 19:34
If you need a function with arbitrary args you can use kwargs dictionary and exec statement over its items. If 'f' is not a builtin function you need to add from module import function in this auxiliar module.
def eval_fun(f, **args):
''' (str, dict) -> object
f: Function as string.
args: dictionary with arbitrary variables.
Use arbitrary args in **args to eval general functions.
Examples:
>> eval_fun('x**2',x=5)
25
>> eval_fun('x*y', x=3, y=2)
6
@cosmoscalibur
cosmoscalibur / delrepeat
Created June 6, 2017 15:32
Remove duplicate files (use under your own risk). Example: `delrepeat "*.mp3"`
#! /usr/bin/env bash
## Usage: delrepeat STRING_PATTERN
## Example: delrepeat "*.mp3"
## IFS=$' \t\n' # default
SAVEIFS=$IFS
IFS=$'\n'
files=$(find . -iname "$1")
declare -a hashes
removed=0
@cosmoscalibur
cosmoscalibur / topocolombia_generar.sh
Created August 21, 2017 19:47
Convierte el reporte excel del DIVIPOLA a las listas de lemas de topónimos colombianos para diccionario hunspell.
#! /usr/bin/env bash
# Rutina elaborada por Edward Villegas Pulgarin (@cosmoscalibur en github).
# Genera lista de lemas de topónimos colombianos para diccionario hunspell a partir del reporte de DIVIPOLA.
# Realizado para la localización es_CO de [RLA-ES](https://github.com/sbosio/rla-es).
A=departamentos
B=municipios
C=centros_poblados
l=lista-
@cosmoscalibur
cosmoscalibur / propioscolombianos_generar.sh
Created August 22, 2017 04:03
Genera lista de lemas asociados a nombres propios a partir de una lista de nombres propios en texto plano. Elimina duplicados respecto a topónimos y nombres propios existentes en el proyecto (RLA-ES).
#!/usr/bin/env bash
# Rutina elaborada por Edward Villegas Pulgarin (@cosmoscalibur en github).
# Genera lista de lemas de nombres propios colombianos para diccionario hunspell
# a partir de una lista de nombres compuestos en archivo de texto plano, comparando
# con los topónimos y nombres propios ya incluidos.
# El archivo debe ubicarse en el directorio de la localización.
# Realizado para la localización es_CO de [RLA-ES](https://github.com/sbosio/rla-es).
# $1: Nombre del archivo de listas de nombres
@cosmoscalibur
cosmoscalibur / download_es_guttenberg.py
Last active May 30, 2018 02:10
Automatic download of Spanish books from Guttenberg project.
"""
This script help you to download the large collection of Spanish books included
in `Guttenberg project <https://www.gutenberg.org/browse/languages/es>`_.
You need to install `requests-html <http://html.python-requests.org/>`_.
:Authors:
Edward Villegas-Pulgarin <cosmoscalibur at gmail dot com>.
"""
from requests_html import HTMLSession
@cosmoscalibur
cosmoscalibur / condawrapper.py
Last active August 2, 2018 16:22
This is a convenient way to install packages in all conda environments
"""
This script help you to list your conda environments and install packages in multiples environments.
You need conda package manager installed (Anaconda/Miniconda) and Python Anaconda.
:Authors:
Edward Villegas-Pulgarin <cosmoscalibur at gmail dot com>.
"""
#%%
@cosmoscalibur
cosmoscalibur / anaconda_pyinstaller
Last active August 6, 2018 00:38
Minimal example of PyInstaller with Python Anaconda in Linux
conda create -y -n pyinstaller python=3.6
conda activate pyinstaller
pip install pyinstaller
echo 'print("hola mundo")' > hola.py
pyinstaller --onefile hola.py
./dist/hola
@cosmoscalibur
cosmoscalibur / vexrobotics_scraping.py
Last active June 22, 2019 17:40
web scraping example with requests and bs4
#! /usr/bin/env python3
# author: Edward Villegas-Pulgarin (@cosmoscalibur)
# Scraping web site and convert to markdown format.
# Extract product catalog.
# June 28, 2017.
# Last test: June 22, 2019.
import requests
@cosmoscalibur
cosmoscalibur / normalize_filename.sh
Created June 24, 2019 00:53
Bash script to normalize filenames (lower case and underlines instead of spaces)
#! /usr/bin/env bash
SAVEIFS=$IFS
IFS=$'\n'
FILES=$(find . -iname "$1")
for FILE in ${FILES[@]}; do
DIRECTORY=$(echo $FILE | sed -n -E 's/^(\.?\/?(.+\/))?(([^\/]+)(\.([^\.\/]+))?)$/\1/p')
FILENAME=$(echo $FILE | sed -n -E 's/^(\.?\/?(.+\/))?(([^\/]+)(\.([^\.\/]+))?)$/\3/p')
FILENAME_NORM=$(echo $FILENAME | sed -E -e 's/./\l\0/g' -e 's/( |_)+/_/g' \
-e 's/^_//' -e 's/(_|-)\./\./g' -e 's/\.\./\._/g')
if ! [[ "$DIRECTORY$FILENAME" = "$DIRECTORY$FILENAME_NORM" ]]; then
@cosmoscalibur
cosmoscalibur / issue15_RAE
Last active June 27, 2019 01:59
Lemas RAE reporte 15
[+] abarrocado
abarrocado, da.
1. adj. Que presenta rasgos barrocos. Estilo, vestido abarrocado.
[+] abarrotamiento
abarrotamiento.
1. m. Acción y efecto de abarrotar (‖ llenar por completo un espacio).
[+] abocardamiento
abocardamiento.
1. m. Acción y efecto de abocardar.
[+] abochornante