Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Gratier ThomasG77

View GitHub Profile
View generate-image-to-drawing.py
# Code borrowed from https://py.plainenglish.io/convert-a-photo-to-pencil-sketch-using-python-in-12-lines-of-code-4346426256d4
# This code depends from OpenCV Python library you can install with
# pip install opencv-python
# You run it with the following. It relies on Python 3
# python3 generate-image-to-drawing.py /tmp/puppy.png
# or how you installed or your OS
# python generate-image-to-drawing.py /tmp/puppy.png
# It will generate an image at /tmp/puppy_sketch.png
import argparse
@ThomasG77
ThomasG77 / pdftk-split-every-n-page.sh
Created Feb 18, 2021
Need to split PDF every n pages, do it with pdftk
View pdftk-split-every-n-page.sh
# Recipe from https://unix.stackexchange.com/questions/66931/split-pdf-into-documents-with-several-pages-each
pagesper=2
file=layout_atlas_multipage.pdf
number=$(pdfinfo -- "$file" 2> /dev/null | awk '$1 == "Pages:" {print $2}')
count=$((number / pagesper))
filename=${file%.pdf}
counter=0
while [ "$count" -gt "$counter" ]; do
View download-gpkg-topage-2019.txt
http://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/CoursEau/CoursEau_FXX-gpkg.zip
https://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/TronconHydrographique/TronconHydrographique_FXX-gpkg.zip
http://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/PlanEau/PlanEau_FXX-gpkg.zip
http://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/SurfaceElementaire/SurfaceElementaire_FXX-gpkg.zip
http://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/BassinHydrographique/BassinHydrographique_FXX-gpkg.zip
http://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/BassinVersantTopographique/BassinVersantTopographique_FXX-gpkg.zip
http://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/LimiteTerreMer/LimiteTerreMer_FXX-gpkg.zip
http://services.sandre.eaufrance.fr/telechargement/geo/ETH/BDTopage/2019/NoeudHydrographique/NoeudHydrographique_FXX-gpkg.zip
View demo-gdal-merge-single.sh
# Generate structure
rm -rf demo
mkdir demo
mkdir demo/germany
mkdir demo/france
cd demo/germany
# Get data
ogr2ogr germany.shp /vsicurl/https://github.com/datasets/geo-countries/raw/master/data/countries.geojson -dialect SQLite -sql "SELECT * FROM countries WHERE ADMIN = 'Germany'"
cd ../france
View graphhopper-minimum-illinois.sh
mkdir ~/graphhopper/
cd ~/graphhopper/
wget https://graphhopper.com/public/releases/graphhopper-web-2.3.jar https://raw.githubusercontent.com/graphhopper/graphhopper/stable/config-example.yml https://download.geofabrik.de/north-america/us/illinois-latest.osm.pbf
java -Ddw.graphhopper.datareader.file=illinois-latest.osm.pbf -jar *.jar server config-example.yml
# Wait data to be processed to get something like below
# 2021-02-15 17:09:38.543 [main] INFO org.eclipse.jetty.server.Server - Started @145741ms
# Then, open URL below
curl http://localhost:8989/isochrone?profile=car&buckets=3&point=40.7208,-89.6094&result=polygon&time_limit=1800
@ThomasG77
ThomasG77 / README.md
Last active Feb 11, 2021
Recipe to get JSON using pagination using command line tools e.g curl, jq, bc, cat
View README.md
@ThomasG77
ThomasG77 / download-torrent.sh
Last active Feb 5, 2021
Test torrent command line from URL using lftp and aria2c
View download-torrent.sh
# Work
aria2c http://files.opendatarchives.fr/professionnels.ign.fr/bdtopo/BDTOPO_3-0_2020-12-15/torrents/BDTOPO_3-0_TOUSTHEMES_SQL_WGS84G_FRA_2020-12-15.7z.001.torrent
## Output: work but complains about an error
# 02/05 18:50:23 [NOTICE] Downloading 1 item(s)
# 02/05 18:50:24 [NOTICE] Téléchargement terminé: /home/thomasg/BDTOPO_3-0_TOUSTHEMES_SQL_WGS84G_FRA_2020-12-15.7z.001.torrent
# 02/05 18:50:24 [NOTICE] DHT IPv4 : En écoute sur le port UDP 6886
# 02/05 18:50:24 [NOTICE] IPv4 BitTorrent: listening on TCP port 6958
# 02/05 18:50:24 [NOTICE] IPv6 BitTorrent: listening on TCP port 6958
# 02/05 18:50:24 [ERROR] CUID#27 - Download aborted. URI=http://tracker.computel.fr:80/announce?info_hash=%E0%2B%92%E8j%5D%EA%BDjG%18Uy%EA%8C3%DC%17%26%8C&peer_id=A2-1-33-1-%DC%F4%F6%F3G%B5%7C%3Ci%AB&uploaded=0&downloaded=0&left=4294967296&compact=1&key=%F6%F3G%B5%7C%3Ci%AB&numwant=50&no_peer_id=1&port=6958&event=started&supportcrypto=1
@ThomasG77
ThomasG77 / split-openvpn-file-for-gnome-manager-import.sh
Last active Feb 4, 2021
Convert single OpenVPN file to multiple to be compatible for import in Gnome VPN manager (improved from https://askubuntu.com/questions/134918/setting-vpn-client)
View split-openvpn-file-for-gnome-manager-import.sh
#!/usr/bin/env bash
# Improved and automated version of https://askubuntu.com/questions/134918/setting-vpn-client
# First arg = directory where you want to collect files
# Second arg = filename input
# To illustrate
# ./generate-cleaned-openvpn.sh my_test_directory labtop.ovpn
# After run, import with
# sudo nmcli connection import type openvpn file my_test_directory/client.ovpn
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Demo raster tile source + GeoJSON line + onclick on map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://cdn.maptiler.com/maplibre-gl-js/v1.13.0-rc.4/mapbox-gl.js'></script>
<link href='https://cdn.maptiler.com/maplibre-gl-js/v1.13.0-rc.4/mapbox-gl.css' rel='stylesheet' />
<style>
body {