Skip to content

Instantly share code, notes, and snippets.

@gzagatti
gzagatti / find_docker_mounts.sh
Created July 18, 2018 19:32
Figure out Docker container mounts using JQ
docker inspect container | jq -r '..|.Mounts? |select(.!=null) | map(.Source)[]'
@gzagatti
gzagatti / resize_default_window_safari.sh
Created July 14, 2018 23:18
Resize the default window in Safari
defaults write com.apple.safari "NSWindow Frame BrowserWindowFrame" "0 0 1280 685 0 0 1280 777"
@gzagatti
gzagatti / syntax_group.vim
Created June 5, 2018 04:08
Figure out within which syntax group we are
" from https://github.com/suy/vim-context-commentstring/blob/master/doc/context-commentstring.txt
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
@gzagatti
gzagatti / raster_postgis.py
Last active April 13, 2024 08:09
Loads raster data from POSTGIS directly to numpy.array using rasterio
import psycopg2
from rasterio.io import MemoryFile
conn = pscopg2.connect("<connection string>")
cur = conn.cursor()
# ensure that the GTiff driver is available,
# see https://postgis.net/docs/postgis_gdal_enabled_drivers.html
cur.execute('''
SET postgis.gdal_enabled_drivers TO 'GTiff';
SELECT ST_AsGDALRaster(rast, 'GTiff') FROM raster.table;
@gzagatti
gzagatti / vim_capture_search.md
Created March 26, 2018 22:17
capture search to a variable for later re-use in Vim

The expression below captures the first group match and adds its to a list for later use.

let t =[] | '<,'>s/\v\\code\{([^}]+)}\zs/\=add(t, submatch(1))[1:0]/g

We can then place the list into another section of the file with.

put = t
@gzagatti
gzagatti / change_tex_label.vim
Last active February 16, 2018 20:18
Rename figure tag in tex and move the corresponding file.
function! VimtexLabelRename(oldtag, newtag)
" Change figure tag in tex and move the corresponding
" file.
exe '%s/\v\{(fig:)?' . a:oldtag . '\}/{fig:' . a:newtag . '}/g'
exe '%s/\v\{' . a:oldtag . '(_.*)?\.png\}/{' . a:newtag . '\1.png}/g'
exe '!for i in `find assets -name 'a:oldtag.'*`; do mv $i ${i/'.a:oldtag.'/'.a:newtag.'}; done'
"exe '!mv' 'assets/'.a:oldtag.'.png' 'assets/'.a:newtag.'.png'
endfunction
command! -nargs=* VimtexLabelRename call VimtexLabelRename(<f-args>)
@gzagatti
gzagatti / docker_run_tmp_shell.sh
Created February 9, 2018 15:55
Run temporary shell in docker with desired image.
docker run --name <container_name> --rm -i -t <image> <shell, eg. /bin/bash>
@gzagatti
gzagatti / pr-assignee
Last active February 1, 2018 15:36
Find all pull-requests in Github assigned to user.
is:open is:pr assignee:<username>
@gzagatti
gzagatti / pyenv.md
Last active January 30, 2018 22:22
Installing python with pyenv

pyenv was failing to install python due the inexistence of the pyexpat library.

In order to solve this problem, I upgraded brew, installed and uninstalled openssl with brew and installed the HEAD version of pyenv.

Before installing the required python versions I exported the following flags:

CFLAGS="-I$(brew --prefix openssl)/include"
LDFLAGS="-L$(brew --prefix openssl)/lib"
@gzagatti
gzagatti / spss_to_csv.r
Created August 3, 2017 02:35
Converting a list of SPSS files (.sav) to CSV using magrittr
library('magrittr')
library('memisc')
# get all .sav files from directory
files <- list.files('.', pattern='.sav$', recursive=FALSE)
# get the dataframes
dfs <- list.files('.', pattern='.sav$', recursive=FALSE) %>%
lapply(spss.system.file) %>%
lapply(as.data.set) %>%