Skip to content

Instantly share code, notes, and snippets.

Avatar

Joan Arnaldich jarnaldich

View GitHub Profile
@jarnaldich
jarnaldich / my-match-lambda.rkt
Created Oct 24, 2014
Racket genericity with match-lambda clauses
View my-match-lambda.rkt
#lang racket
(provide my-match-lambda*
(struct-out my-match-lambda-procedure)
my-match-lambda-append
my-match-lambda-add-clause!
my-match-lambda-add-overriding-clause!
(struct-out exn:fail:my-match-lambda:no-match)
(struct-out exn:fail:my-match-lambda:no-match:next-clause)
raise-my-match-lambda:no-match-error)
@jarnaldich
jarnaldich / SumXmlField.hs
Created Mar 31, 2017
Add fields from a directory tree with XML files using lenses, Directory Tree
View SumXmlField.hs
#!/usr/bin/env stack
{-
stack
--resolver lts-4.2
--install-ghc runghc
--package xml-lens
--package directory-tree
-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
@jarnaldich
jarnaldich / tick.psm1
Created Jun 6, 2017
Sample Code for Blog Post on Porting Unix Philosophy To Windows
View tick.psm1
function Sample-Count-Files {
[CmdletBinding()]
param(
# The file pattern to count
[Parameter(Mandatory=$true,
Position=0)]
[string]$pattern,
# Name of the log file
@jarnaldich
jarnaldich / flightDates.hs
Created Nov 28, 2018
[Using Text.XML.Lens with namespaces] Example of using namespaces for Text.MXL.Lens #haskell #xml #stack #script
View flightDates.hs
#!/usr/bin/env stack
{-
stack
--install-ghc runghc
--package xml-lens
-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import System.Environment (getArgs)
import Text.XML
@jarnaldich
jarnaldich / parCurl.hs
Created Nov 29, 2018
[Concurrent Curl in Haskell] Concurrency in Haskell #haskell #concurrency #parallel #network
View parCurl.hs
#!/usr/bin/env stack
{- stack --resolver lts-12.20 --install-ghc runghc
--package random --package async --package stm-chans --package wreq --package cassava
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE DeriveGeneric #-}
import Control.Exception
import Control.Concurrent.Async (mapConcurrently, concurrently)
@jarnaldich
jarnaldich / FileWatcher.ps1
Created Feb 6, 2019
Powershell File System Watcher #powershell #watch #filesystem
View FileWatcher.ps1
$w = New-Object System.IO.FileSystemWatcher
$w.Path= pwd
$w.Filter= "*.py"
$w.EnableRaisingEvents = $true
$action = { (&{ cls; $p = $Event.SourceEventArgs.FullPath; python $p }) 2>&1 | Write-Host }
$changed = Register-ObjectEvent $w "Changed" -Action $action
Unregister-Event $changed.Id
@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 < $<
@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 / 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 / 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';