Skip to content

Instantly share code, notes, and snippets.

@gzagatti
gzagatti / html_table_to_csv.js
Created October 12, 2021 03:10
HTML tables to csv
// 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 September 2, 2021 14:18
A Gaussian mixture model with Soss.jl
### A Pluto.jl notebook ###
# v0.15.1
using Markdown
using InteractiveUtils
# ╔═╡ 6ca58e9a-0707-11ec-1a6c-bdb652993535
begin
using Plots
using StatsPlots
@gzagatti
gzagatti / missing_deps.sh
Created August 4, 2020 06:42
find required but unavailable shared libraries
find /usr/local/agens/bin -type f -perm /a+x -exec ldd {} \; | grep ‘not found’
@gzagatti
gzagatti / svg2icns
Created February 6, 2020 03:45 — forked from zlbruce/svg2icns
covert svg to icns (with imagemagick)
#!/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 August 20, 2019 02:26
Remove quarantine attribute from applications installed by admin
xattr -d com.apple.quarantine my_jar.jar
@gzagatti
gzagatti / rm_gps_tags_exiv2.sh
Last active February 10, 2023 21:02
Deleting GPS tags from images using exiv2
# 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 August 1, 2018 18:32
List complete nodes which have a given child using sed.
# 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.
@gzagatti
gzagatti / remove_duplicate_lines_sed.sh
Created July 30, 2018 21:05
Remove consecutive duplicate lines with sed
# from https://www.linuxquestions.org/questions/programming-9/removing-duplicate-lines-with-sed-276169/
# $!N
# if not in the last line, append the next line of input
# pattern space (no duplicates): line1\nline2
# stdout: null
#
# /^\(.*\)\n\1$/
# does the pattern space (eg. line1\nline2) contains duplicate lines (eg. line1 == line2)?
#
# /<REGEX>/!P
@gzagatti
gzagatti / change_multiple_files.vim
Last active July 23, 2018 16:08
Change multiple files at once in Vim.
set aw
" There are two different approaches for finding the target files
" execute "args" join(systemlist("ag -l pattern path/to/files"), " ")
args `ag -l pattern path/to/files`
argdo %s/pattern/new/g | w
@gzagatti
gzagatti / average_tables_in_the_wild.js
Created July 21, 2018 17:13
Performs basic analysis on a random table found in a webpage using basic JS
// Before proceeding add an ID `target` to the table you want to perform the analysis on
// Google Chrome intercepts $ as a shortcut for document.querySelector() and
// $$() as a shortcut for document.querySelectorAll()
items = []
$$('#target tr').forEach(
(row) => items.push(
parseFloat(