Skip to content

Instantly share code, notes, and snippets.

@jarnaldich
jarnaldich / json2csv.sh
Created Nov 4, 2021
[Json 2 CSV with jq] #json #jq
View json2csv.sh
jq.exe --% -r ".result | map([(.doy|tostring), .timestamp, (.val|tostring), (.interpol|tostring)] | join(\",\")) | join(\"\n\")" rasdaman.json
@jarnaldich
jarnaldich / table_columns.sql
Last active Aug 30, 2021
[Introspect Table Column DataTypes in PostgreSQL] View listing all tables joined with columns and data types for PostgreSQL
View table_columns.sql
CREATE OR REPLACE VIEW table_columns AS
WITH table_oids AS (
SELECT c.relname, c.oid
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE
pg_catalog.pg_table_is_visible(c.oid)),
column_types AS (
SELECT
toids.relname AS "tablename",
@jarnaldich
jarnaldich / Main.purs
Last active Apr 8, 2021
[Nested Update Purescript]
View Main.purs
-- Proposed Purescript Solution for: https://github.com/josevalim/nested-data-structure-traversal
-- Pure solution (no mutability), Strongly Typed (try to mess around, eg, misspelling an attribute)
-- Nothing fancy (no optics), just the usual pure functional artillery (foldl, zipWith...)
-- plus the convenience of extendable row types in Purescript. A seasoned Purescript dev may improve
-- on this, though...
module Main where
import Prelude
import Data.Array (zipWith, length, (..), snoc)
@jarnaldich
jarnaldich / setup.sh
Created May 18, 2020
Install new Ubuntu machine for work
View setup.sh
# Check version
lsb_release -a
# Install zsh oh my zsh...
sudo apt install zsh
sudo apt-get install powerline fonts-powerline
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.zsh-syntax-highlighting" --depth 1
echo "source $HOME/.zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> "$HOME/.zshrc"
@jarnaldich
jarnaldich / copy_extent_to_clipboard.py
Created Jan 30, 2020
Copying map extent to clipboard in QGIS with python #qgis #python
View copy_extent_to_clipboard.py
def copy_extent_to_clipboard(separator=';'):
ext = iface.mapCanvas().extent()
coords = [ ext.xMinimum(), ext.yMinimum(), ext.xMaximum(), ext.yMaximum() ]
txt = separator.join([ "{:10.4f}".format(x) for x in coords ])
QgsApplication.clipboard().setText(txt)
# Run: exec(open('C:/Users/j.arnaldich/copy_extent_to_clipboard.py'.encode('utf-8')).read())
@jarnaldich
jarnaldich / RGBIZE DSM with rio calc for use with nextzen DTM tiles
Created Jan 29, 2020
RGBIZE DSM with rio calc for use with nextzen DTM tiles #rasterio #rio #dsm #bash
View RGBIZE DSM with rio calc for use with nextzen DTM tiles
#!/bin/bash
SRC=$1
DST=$2
rio calc --co COMPRESS=LZW --co BIGTIFF=YES -t uint8 "(asarray (/ (+ 3278 (read 1 1)) 256) (mod (+ 3278 (read 1 1)) 256) (* 256 (- (+ 3278 (read 1 1)) (floor (+ 3278 (read 1 1))))))" $SRC $DST
@jarnaldich
jarnaldich / prod2dev.sh
Last active Dec 12, 2019
Recuperar Backup Postgres #postgresql #backup #shell
View prod2dev.sh
#!/bin/bash
SRC_DBNAME=$1
TARGET_DBNAME=$2
DATE=`date +%Y%m%d`
PGPASSWORD=$SRCPASS /usr/lib/postgresql/9.5/bin/pg_dump -F c --file /mnt/d/public/lliscat_$DATE.backup --host 172.30.22.110 --username postgres --format=c --blobs $SRC_DBNAME
PGPASSWORD=$DSTPASS psql -h phineas -U postgres <<END
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid <> pg_backend_pid() AND datname = '$TARGET_DBNAME';
@jarnaldich
jarnaldich / cmds.sh
Last active Feb 25, 2020
Start a F# Dotnet.Core Project
View cmds.sh
#!/bin/bash
# To install dotnet on windows choco install -y dotnetcore-sdk
PRJ=$1
dotnet new console -lang F# -o $PRJ
cd $PRJ
dotnet add package FSharp.Data
# The only working one I could find...
dotnet add package -v 2.4.2 GDAL.Native
@jarnaldich
jarnaldich / prepare_wsl.sh
Last active Jul 15, 2019
[PrepareWSL] Prepare WSL for remote acess #wsl #zsh
View prepare_wsl.sh
sudo apt-get purge openssh-server
sudo apt-get install openssh-server
sudo apt install -y zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# Can change THEME to agnoster in .zshrc
curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage
chmod u+x nvim.appimage
@jarnaldich
jarnaldich / Makefile
Created Feb 27, 2019
[sample makefile for image transformation] takes a directory of input files and performs 2 chained transformations #make #makefile
View Makefile
TXTS=$(shell CMD /C DIR /B Z:\mrsids\params)
OUT=\\icgc.local\dades\datacloud_2\of5m_ETRS89\sid_ed50\\
OUTS=$(patsubst %.tif,$(OUT)%.tif,$(TXTS:.txt=.tif))
SIDS=$(patsubst %.sid,$(OUT)%.sid,$(TXTS:.txt=.sid))
target: $(SIDS)
$(OUT)%.tif : Z:\mrsids\params\%.txt
\\icgc.local\aplicacions\produccio\DFApplications\ICCImageOperationsGeocorrection\exe\ICCImageGeoTransformation.exe < $<