Skip to content

Instantly share code, notes, and snippets.

View jarnaldich's full-sized avatar

Joan Arnaldich jarnaldich

View GitHub Profile
@jarnaldich
jarnaldich / autoargs.py
Created February 20, 2022 07:28
[Automatically set attributes from __init__ args in Pyhon] #python #args #init #constructor
# Also check data classes and collections for this
import inspect
import functools
def autoargs(*include,**kwargs):
def _autoargs(func):
attrs,varargs,varkw,defaults=inspect.getargspec(func)
def sieve(attr):
if kwargs and attr in kwargs['exclude']: return False
@jarnaldich
jarnaldich / json2csv.sh
Created November 4, 2021 06:54
[Json 2 CSV with jq] #json #jq
jq.exe --% -r ".result | map([(.doy|tostring), .timestamp, (.val|tostring), (.interpol|tostring)] | join(\",\")) | join(\"\n\")" rasdaman.json
@jarnaldich
jarnaldich / table_columns.sql
Last active October 15, 2024 18:11
[Introspect Table Column DataTypes in PostgreSQL] View listing all tables joined with columns and data types for PostgreSQL
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 April 8, 2021 11:32
[Nested Update Purescript]
-- 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 07:29
Install new Ubuntu machine for work
# 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 January 30, 2020 09:31
Copying map extent to clipboard in QGIS with python #qgis #python
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 January 29, 2020 11:15
RGBIZE DSM with rio calc for use with nextzen DTM tiles #rasterio #rio #dsm #bash
#!/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 December 12, 2019 10:09
Recuperar Backup Postgres #postgresql #backup #shell
#!/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 February 25, 2020 09:04
Start a F# Dotnet.Core Project
#!/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 July 15, 2019 06:54
[PrepareWSL] Prepare WSL for remote acess #wsl #zsh
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