Skip to content

Instantly share code, notes, and snippets.

@gzagatti
gzagatti / raster_postgis.py
Last active May 29, 2022
Loads raster data from POSTGIS directly to numpy.array using rasterio
View raster_postgis.py
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;
View html_table_to_csv.js
// selects all table rows element in an HTML document ("tr").
$$("tr").map(
// for each row, select each table data element ("td").
(row) => Array.from(
row.querySelectorAll("td")
// for each data element return the inner text surrounded by quotes and stripped of line breaks.
).map(
(cell) => "'" + cell.innerText.replace("\n", " ") + "'"
// join same row elements with ","
).join(", ")
@gzagatti
gzagatti / soss-mixture.jl
Created Sep 2, 2021
A Gaussian mixture model with Soss.jl
View soss-mixture.jl
### A Pluto.jl notebook ###
# v0.15.1
using Markdown
using InteractiveUtils
# ╔═╡ 6ca58e9a-0707-11ec-1a6c-bdb652993535
begin
using Plots
using StatsPlots
@gzagatti
gzagatti / resize_default_window_safari.sh
Created Jul 14, 2018
Resize the default window in Safari
View resize_default_window_safari.sh
defaults write com.apple.safari "NSWindow Frame BrowserWindowFrame" "0 0 1280 685 0 0 1280 777"
@gzagatti
gzagatti / time_machine_backup.md
Last active Nov 21, 2020
Set up time machine with sparse bundles on NAS drivers
View time_machine_backup.md

Time Machine Backup w/ Sparse Bundles

  1. create a sparse image: hdiutil create -size 600g -type SPARSEBUNDLE -fs "HFS+J" NAME_XXXXXXX.sparsebundle -volname 'untitled' -encryption
  • ideally the sparse bundle should have about twice the size of your Mac's storage
  1. copy sparse bundle to the network and then mount it: rsync -aE NAME_XXXXXXXXXXXX.sparsebundle /Volumes/DRIVE/.
  2. remove the sparse bundle from machine: rm -rf NAME_XXXXXXXXXXXX.sparsebundle
  3. tell time machine to backup your mounted drive: sudo tmutil setdestination /Volumes/TimeMachine
  4. head to System preferences, then open Time Machine settings; you should see your virtual drive as the default backup destination
@gzagatti
gzagatti / missing_deps.sh
Created Aug 4, 2020
find required but unavailable shared libraries
View missing_deps.sh
find /usr/local/agens/bin -type f -perm /a+x -exec ldd {} \; | grep ‘not found’
@gzagatti
gzagatti / svg2icns
Created Feb 6, 2020 — forked from zlbruce/svg2icns
covert svg to icns (with imagemagick)
View svg2icns
#!/bin/bash
echo "*** SVG 2 ICNS ***"
if [ $# -ne 1 ]; then
echo "Usage: svg2icns filename.svg"
exit 100
fi
filename="$1"
name=${filename%.*}
ext=${filename##*.}
echo "processing: $name"
@gzagatti
gzagatti / rm_quarantine_attr.sh
Created Aug 20, 2019
Remove quarantine attribute from applications installed by admin
View rm_quarantine_attr.sh
xattr -d com.apple.quarantine my_jar.jar
@gzagatti
gzagatti / rm_gps_tags_exiv2.sh
Last active Oct 6, 2018
Deleting GPS tags from images using exiv2
View rm_gps_tags_exiv2.sh
# get the GPS keys from a random image
# we assume that all images have the same metadata fields,
# since they were obtained from the same device in similar conditions
export opts=$(exiv2 -p a IMG_2421.JPG | grep -i 'gps' | awk -F " " -v q='"' '{print "-M" q "del " $1 q}' | tr '\n' ' ')
# delete the keys from the metadata
for f in `ls`; do eval "exiv2 $opts $f"; done
@gzagatti
gzagatti / list_dependency_graphs_sed.sh
Last active Aug 1, 2018
List complete nodes which have a given child using sed.
View list_dependency_graphs_sed.sh
# sometimes we have a hierarchical list and we want to print all of the nodes
# that have a certain child, simple regular expression will only yield the child
# not the whole node. We can use sed to recover the whole node.
#
# let's say we want to recover all packages in pipenv graph that use pandas.
# /^ /!x{...}
# all of lines which do not start with a space are at the top of the
# hierarchy, swap them with the hold space. The hold space has now the node
# and the pattern space contains the contents of the hold space. Execute all
# commands between brackets.