Skip to content

Instantly share code, notes, and snippets.

Avatar

Joan Arnaldich jarnaldich

View GitHub Profile
@jarnaldich
jarnaldich / RasterGeoPackage.ps1
Created Sep 6, 2022
[Raster GeoPackage with Custom Tile Schema] Sample on generating a Raster GeoPackage with a Custom Tile Schema with GDAL 3 #gdal #geopackage #raster
View RasterGeoPackage.ps1
function GetInfo {
param([string]$InputPath)
gdalinfo -json $InputPath | ConvertFrom-JSon -AsHashTable
}
function Urbana {
param(
[string]$InputPath,
[string]$OutputPath,
[String[]]$Bands=(1, 2, 3))
@jarnaldich
jarnaldich / catastro.ps1
Created Apr 20, 2022
[Catastro WebService Query in PowerShell] Query and process Xml Result for Catastro in PowerShell #xml #PowerShell #webservice
View catastro.ps1
function Consulta_DPNRC($cod_parcela) {
$response = Invoke-WebRequest -UseBasicParsing -Uri "http://ovc.catastro.meh.es/ovcservweb/OVCSWLocalizacionRC/OVCCallejero.asmx/Consulta_DNPRC" `
-Method "POST" `
-WebSession $session `
-Headers @{
"Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
"Accept-Encoding"="gzip, deflate"
"Accept-Language"="es-419,es;q=0.9,en;q=0.8"
"Cache-Control"="no-cache"
@jarnaldich
jarnaldich / out.py
Created Mar 28, 2022
[TFW from GCPs with RasterIO] #gdal #rasterio
View out.py
from affine import dumpsw
ts = rio.transform.from_gcps(ds.gcps[0])
open(r"e:\public\aerot\1988040011117.tfw", 'w').write(dumpsw(ts))
@jarnaldich
jarnaldich / etl.hs
Last active Mar 26, 2022
[ETL in Haskell] Enrich a geojson file with attributes coming from an .xml #haskell #xml #geojson
View etl.hs
#!/usr/bin/env stack
{-
stack
--install-ghc runghc
--package aeson
--package lens-aeson
--package xml-lens
-}
{-# Language OverloadedStrings #-}
import Control.Monad.Reader
@jarnaldich
jarnaldich / xml2json.hs
Created Mar 18, 2022
XML to JSON in Haskell sample #haskell #json #xml
View xml2json.hs
#!/usr/bin/env stack
{-
stack
--install-ghc runghc
--package aeson
--package aeson-pretty
--package lens-aeson
--package xml-lens
-}
{-# LANGUAGE OverloadedStrings #-}
@jarnaldich
jarnaldich / autoargs.py
Created Feb 20, 2022
[Automatically set attributes from __init__ args in Pyhon] #python #args #init #constructor
View autoargs.py
# 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 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"