Skip to content

Instantly share code, notes, and snippets.

View martjanz's full-sized avatar

Martín Anzorena martjanz

View GitHub Profile
@martjanz
martjanz / gist.sh
Last active August 18, 2021 18:14
Reduce *.jpg size
#!/bin/sh
fd -t f -e jpg -x convert "{}" -quality 80% "low/{}"
@martjanz
martjanz / convert.sh
Last active June 10, 2021 12:48
Convert audio and image formats to smaller and compressed formats
#!/bin/sh
# (Linux, Unix) Convert to mp3 at maximum VBR using ffmpeg, then delete source audio files
fd -t f -e aiff -x ffmpeg -i "{}" -qscale:a 0 "{.}.mp3" && fd -t f -e aiff -x rm {}
fd -t f -e flac -x ffmpeg -i "{}" -qscale:a 0 "{.}.mp3" && fd -t f -e flac -x rm {}
fd -t f -e m4a -x ffmpeg -i "{}" -qscale:a 0 "{.}.mp3" && fd -t f -e m4a -x rm {}
fd -t f -e wav -x ffmpeg -i "{}" -qscale:a 0 "{.}.mp3" && fd -t f -e wav -x rm {}
fd -t f -e wma -x ffmpeg -i "{}" -qscale:a 0 "{.}.mp3" && fd -t f -e wma -x rm {}
# (Mac) Convert bmp to jpeg
@martjanz
martjanz / deletuips.py
Last active November 12, 2020 00:09
Deletuips: just another bulk tweet deletion tool using requested Twitter archive
#!/bin/python3
#
# Requirements:
# - Python 3
# - tweepy Python library (pip install tweepy)
# - Twitter API keys and secrets (from https://developer.twitter.com/)
#
# Instructions:
# - Request and download your Twitter archive (from https://twitter.com/settings/your_twitter_data)
# - Rename downloaded zip file to twitter-archive.zip
@martjanz
martjanz / channel-downloader.py
Last active September 29, 2020 06:21
YouTube Channel Downloader
# YouTube Channel Downloader
#
# Download all videos from all user/channel playlists
#
# TODO: check pagination. Tested with up to 10 playlists and up to 50 videos each.
import json
import re
import time
import traceback
from urllib.request import urlopen
@martjanz
martjanz / playlist-downloader.py
Last active September 29, 2020 01:50
YouTube Playlists Downloader
# -- Requirements (Python 3)--
import re
import time
import traceback
# External dependency: pytube3 (pip install pytube3)
from pytube import Playlist
from pytube import YouTube
# -- Parameters --
@martjanz
martjanz / downloader.py
Last active July 16, 2020 17:21
Heinrich - Sanguinetti photo archive downloader
"""
Heinrich - Sanguinetti Archive photo downloader
Downloads the photo archive from the Endangered Archives Programme of the British Public Library.
This script assumes that photos are numbered consecutively inside and between folders. There are
some (few) exceptions, a manual review after the run to check if all files were downloaded will be needed.
Sample image URL: http://images.eap.bl.uk/EAP755/EAP755_1_1_295/2987.jp2/full/1287,/0/default.jpg
"""
words_male = list('004' + f'{n:07}' for n in range(99999999))
words_female = list('014' + f'{n:07}' for n in range(99999999))
with open('words.txt', 'w') as fhandler:
for item in (words_male + words_female):
fhandler.write('%s\n' % item)
@martjanz
martjanz / snippet.sql
Last active June 8, 2020 22:43
[Create database user to view/copy only] #postgresql
CREATE ROLE downloader NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN PASSWORD 'the-password';
GRANT CONNECT ON DATABASE db_name TO downloader;
GRANT ALL ON SCHEMA public TO downloader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO downloader;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO downloader;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT ON TABLES TO downloader;
@martjanz
martjanz / create_table.sql
Created May 22, 2020 20:02
Text field spell checker (PostgreSQL)
CREATE TABLE dict_english (
word varchar NOT NULL
);
CREATE UNIQUE INDEX dict_english_word_idx ON dict_english (word);
@martjanz
martjanz / README.md
Last active August 16, 2019 20:07
Geocoding Establecimientos Electorales 2019

Tenemos:

  • polígonos de circuitos (DINE)
  • establecimientos por circuito (DINE)
  • puntos de establecimientos (Educación)

Si bien no tenemos puntos de establecimientos DINE sabemos (suponemos) que están dentro del circuito. Con los puntos de establecimientos Educación, que suponemos también están dentro del circuito (ST_Contains()) nos deja deja no más de diez/veinte establecimientos de cada lado para matchear. Con un fuzzy sobre el nombre podemos resolver varios de ellos, alivianando el fuzzy match hasta encontrar algo más o menos óptimo. Los resultados de los matches pueden ir guardándose en distintas tablas, uno por cada grado de fuzzy match para luego revisar manualmente y ver cuál se ajusta mejor. Estimo que al ser una muy acotada cantidad de establecimientos por circuito podremos matchear incluso con un fuzzy muy bajo, solo necesitamos que los nombres sean remotamente parecidos o al menos el más parecido dentro de los que disponemos para ese circuito.

Hay circuitos que parecieran haber cambiado de nume