Skip to content

Instantly share code, notes, and snippets.

View bchapuis's full-sized avatar

Bertil Chapuis bchapuis

View GitHub Profile
@bchapuis
bchapuis / undirected_graph.sql
Last active October 10, 2022 20:34
Demonstrates the use of a recursive CTE to find the neighbors of a vertex through its edges in a PostgreSQL database.
-- https://www.postgresql.org/docs/current/queries-with.html
DROP TABLE IF EXISTS vertex;
DROP TABLE IF EXISTS edge;
CREATE TABLE IF NOT EXISTS vertex (
id int primary key
);
CREATE TABLE IF NOT EXISTS edge (
@bchapuis
bchapuis / extract-and-aggregate-json-attributes.sql
Last active July 22, 2021 21:31
Demonstrates how to extract and aggregate attributes in a json data structure
SELECT id,
array_to_json(array_remove(array_agg(a), NULL)) as a,
array_to_json(array_remove(array_agg(b), NULL)) as b,
array_to_json(array_remove(array_agg(c), NULL)) as c
FROM (
SELECT jsonb_path_query_first(value, '$[*].id') as id,
jsonb_path_query(value, '$[*].a') as a,
jsonb_path_query(value, '$[*].b') as b,
jsonb_path_query(value, '$[*].c') as c
FROM (
@bchapuis
bchapuis / gist:f24f0b821a60e3f50ebf6aae5ac8ebcb
Created October 7, 2020 11:06
Baremaps OSM Liechtenstein Demo
id: 'openstreetmap'
center:
lon: 9.5554
lat: 47.1660
zoom: 14
bounds:
minLon: 9.471078
maxLon: 9.636217
minLat: 47.04774
maxLat: 47.27128
@bchapuis
bchapuis / gist:9f109cf736f85f4944cabf93c02dc91a
Created October 7, 2020 09:38
Baremaps OSM Switzerland Configuration
id: 'openstreetmap'
center:
lon: 6.5743
lat: 46.5189
zoom: 14
bounds:
minLon: 5.8358
minLat: 45.6591
maxLon: 10.9794
maxLat: 47.8700
def groupConsecutive[T](list: List[T]) : List[List[T]] = list match {
case Nil => Nil
case h::t =>
val segment = list.takeWhile(h ==)
segment :: groupConsecutiveStates(list.drop(segment.length))
}
@bchapuis
bchapuis / server.go
Created August 4, 2015 13:12
Simple Restic REST backend build for testing purposes
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"

Keybase proof

I hereby claim:

  • I am bchapuis on github.
  • I am bchapuis (https://keybase.io/bchapuis) on keybase.
  • I have a public key whose fingerprint is E846 81BD 2790 6AB3 8BB0 E305 7E80 BB87 0896 71C1

To claim this, I am signing this object:

@bchapuis
bchapuis / portForwarding.sh
Last active December 17, 2015 07:59
Iptables port forwarding
iptables -t nat -F
iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80 -j
REDIRECT --to-ports 9000
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT
--to-port 9000
@bchapuis
bchapuis / decodeUrlParameter.js
Last active April 22, 2024 21:17
Replace the plus sign which encode spaces in GET parameters using javascript.
function decodeUrlParameter(str) {
return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}
@bchapuis
bchapuis / getUrlParameter.js
Last active July 10, 2021 13:37
Retrieve the value of a GET parameter using javascript
function decodeUrlParameter(str) {
return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}
function getUrlParameter(name) {
return decodeUrlParameter(decodeURI(
(RegExp(name + '=' + '(.*?)(&|$)').exec(location.search)||[,null])[1]
));
}