Skip to content

Instantly share code, notes, and snippets.

View ThomasG77's full-sized avatar

Thomas Gratier ThomasG77

View GitHub Profile
@ThomasG77
ThomasG77 / promise-race.js
Created August 28, 2018 23:14
Promise.race illustrated with sourceforge mirrors
const fetch = require('node-fetch');
const mirrors = ['astuteinternet', 'ayera', 'cfhcable', 'cytranet', 'datapacket', 'excellmedia', 'freefr', 'gigenet', 'iweb', 'jaist', 'kent', 'liquidtelecom', 'managedway', 'nchc', 'netcologne', 'netix', 'newcontinuum', 'phoenixnap', 'pilotfiber', 'razaoinfo', 'superb-dca2', 'superb-sea2', 'svwh', 'tenet', 'ufpr', 'versaweb'];
const url = 'https://sourceforge.net/projects/filezilla/files/FileZilla_Client/3.31.0/FileZilla_3.31.0_win64-setup.exe/download';
// Find the fastest Sourceforge mirror manually
// The usual use case would for Promise.race would be
// when calling images from multiple servers
// (imagine different AWS S3 storage) to get the fastest one
var p = Promise.race(
<!doctype html>
<!--
This can be used to test the tile serving.
In a browser, open this as a local file.
You will have to start the app server instance without the host option, so that it
will serve as "localhost".
-->
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
@ThomasG77
ThomasG77 / demo_reproject_to_epsg4326.sh
Created December 6, 2018 13:10
Démo pour montrer comment reprojeter en EPSG 2154 un CSV issu du géocodage de l'API CSV de http://adresse.data.gouv.fr/
## How to reproject to EPSG 2154
# Get data
cd /tmp/
wget http://www.douane.gouv.fr/Portals/0/fichiers/datadouane/geolocalisation/annuaire-des-debits-de-tabac-2018.zip
# Uncompress
unp annuaire-des-debits-de-tabac-2018.zip
# Take only 10 first lines
# Code borrowed from https://subscription.packtpub.com/book/application_development/9781783984985/1/ch01lvl1sec18/creating-a-standalone-application
# and upgraded for QGIS 3.0
import sys
from qgis.core import (QgsApplication, QgsFeature, QgsGeometry,
QgsProject, QgsVectorLayer)
from qgis.gui import QgsMapCanvas
from qgis.PyQt.QtCore import Qt
# Unused so commented
# from qgis.PyQt.QtGui import *
@ThomasG77
ThomasG77 / .gitignore
Last active April 28, 2019 15:56
Generate H3 hexagons
node_modules/
package-lock.json
*.geojson
*.gpkg
@ThomasG77
ThomasG77 / geojson_to_h3_hexagons.py
Created April 28, 2019 18:00
Take a GeoJSON as an input, take all H3 hexagons within and output GeoJSON hexagons with their id
from h3 import h3
geoJson = {'type': 'Polygon',
'coordinates': [[[37.813318999983238, -122.4089866999972145],
[ 37.7866302000007224, -122.3805436999997056 ],
[37.7198061999978478, -122.3544736999993603],
[ 37.7076131999975672, -122.5123436999983966 ],
[37.7835871999971715, -122.5247187000021967],
[37.8151571999998453, -122.4798767000009008]]] }
@ThomasG77
ThomasG77 / index.html
Created May 4, 2019 11:05
Leaflet.Spin standalone (similar to official https://github.com/makinacorpus/Leaflet.Spin but use only CDNs)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Leaflet.Spin</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.Spin/1.1.0/leaflet.spin.min.js" charset="utf-8"></script>
<style type='text/css'>
@ThomasG77
ThomasG77 / .gitignore
Last active May 4, 2019 20:55
Use GDAL2Tiles to view images in Leaflet
btv1b53095142n_f1.jpg
tiled/
# Execute in the PyQGIS console
def showXY(p):
print(p.x(), p.y())
currentCanvas = iface.mapCanvas()
currentCanvas.xyCoordinates.connect(showXY)
# Below enable to "unregister" listening to click event
# currentCanvas.xyCoordinates.disconnect(showXY)
@ThomasG77
ThomasG77 / index.md
Created September 26, 2019 21:25
Docker/Docker-compose recipes

Docker-compose recipes

Get IP for PostgreSQL docker image

# Filter docker image running with port 5432 to get IP to use for Pgadmin connexion
# Get the key of the inspected network (one in our case) from this image using docker inspect
# Provide the key to access to the IP of the docker container with DB
# Copy/paste to use in PgAdmin (PS: we use a local docker running with postgres user but passwordless)
key=`docker inspect $(docker-compose ps |grep 5432 |cut -d ' ' -f1) |jq '.[].NetworkSettings.Networks|keys[]'` \