Skip to content

Instantly share code, notes, and snippets.

View Framartin's full-sized avatar

Martin Gubri Framartin

View GitHub Profile
@Framartin
Framartin / organize_folder.sh
Created August 16, 2022 19:25
Crude script to sort a single folder of photos into year/month subfolders
cd my_huge_DCIM_folder
for Y in {2017..2019} ; do
echo "****** YEAR $Y ******"
for M in {01..12} ; do
echo "------ Month $M ------"
mkdir -p "$Y/$M"
mv IMG_${Y}${M}*.jpg "$Y/$M/"
mv VID_${Y}${M}*.mp4 "$Y/$M/"
mv PANO_${Y}${M}*.jpg "$Y/$M/"
done
@Framartin
Framartin / imagenet_subset.sh
Last active September 2, 2021 22:55
Create a subset of ImageNet (ILSVRC2012) for debug
echo "Create a subset of ImageNet of 2 images per class for debug"
SOURCE="data/ILSVRC2012/train"
DEST="data/ILSVRC2012_samples/train"
SOURCE="data/ILSVRC2012/validation"
DEST="data/ILSVRC2012_samples/validation"
cd "$SOURCE"
for file in */ ; do
@Framartin
Framartin / Dobble_reglas.md
Created January 19, 2021 13:26
Reglas de Dobble (juego de mesa)

Traducción ES: Framartin, 2019


Cómo jugar a Dobble

Si nunca has jugado o si estás jugando con gente que nunca antes has jugado, coge dos cartas al azar y ponlas boca arriba en la mesa entre todos los jugadores.

Busque el símbolo idéntico entre las dos tarjetas (misma forma, mismo color, sólo el tamaño puede ser diferente). El primer jugador que encuentra el símbolo correcto lo nombra en voz alta y coge dos cartas nuevas que se colocan boca arriba sobre la mesa.

@Framartin
Framartin / countrycode_france.py
Last active May 28, 2019 02:29
Country codes of France (including Overseas France)
# List of ISO 2 country codes of France and DOM-TOM (Overseas territories of France)
# gathered from https://fr.wikipedia.org/wiki/France_d%27outre-mer#Liste
COUNTRYCODES_FR_DOM_TOM = ['BL', 'FR', 'GF', 'GP', 'MF', 'MQ', 'NC', 'PF', 'PM',
'RE', 'TF', 'YT', 'WF']
@Framartin
Framartin / extensions.py
Last active November 2, 2021 02:32
Simplest scrapy extension to send all errors and exceptions to Sentry
import sentry_sdk
from scrapy.exceptions import NotConfigured
class SentryLogging(object):
"""
Send exceptions and errors to Sentry.
"""
@classmethod
def from_crawler(cls, crawler):
@Framartin
Framartin / esprima_node_generator.py
Last active June 10, 2022 13:52
Generator to browse all the nodes of an Esprima Tree
def node_generator(node):
"""
Generator that takes an Esprima object (or a Esprima node) from the esprima
module converted as a dict, and outputs all child nodes at any level of the
tree. It's useful to browse the entire tree.
Subnodes are generated by browsing all the keys. It's not the most
optimized way to browse the tree, because some keys will never contains
child nodes. But it's very simple, and you're sure to not miss any subnodes.
"""
if node: # not empty dict or list
@Framartin
Framartin / renormalize_pb.R
Created October 25, 2015 16:58
Renormalization issue
library(spdep)
data(oldcol)
lw <- nb2listw(COL.nb)
attr(lw, "region.id")
region.id.wanted.order <- attr(lw, "region.id")[c(1:41, 44:49, 42, 43)] # cannot be obtain with subset.listw
# we convert it to a Matrix and re-normalized it with mat2listw()
W <- as(lw, "CsparseMatrix")
W <- W[region.id.wanted.order, region.id.wanted.order]
style <- lw$style
lw1 <- mat2listw(W, row.names = region.id.wanted.order, style = style) # re-normalize to keep the style
@Framartin
Framartin / predict.sarlm.R
Created September 19, 2015 21:09
Code used to compute lagged variables in predict.sarlm()
K <- ifelse(colnames(X)[1] == "(Intercept)", 2, 1)
m <- ncol(X)
# check if there are enough regressors
if (m > 1) {
WX <- matrix(nrow=nrow(X),ncol=(m-(K-1)))
for (k in K:m) {
wx <- lag.listw(listw, X[,k],
zero.policy=zero.policy)
if (any(is.na(wx)))
stop("NAs in lagged independent variable")