Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco Bartoli francbartoli

View GitHub Profile
@francbartoli
francbartoli / demo.py
Created Jun 2, 2019 — forked from wshayes/demo.py
[Websocket demo for fastapi] example of broadcast using websockets for fastapi #fastapi #websockets
View demo.py
# From https://github.com/tiangolo/fastapi/issues/258
from typing import List
from fastapi import FastAPI
from starlette.responses import HTMLResponse
from starlette.websockets import WebSocket, WebSocketDisconnect
app = FastAPI()
@francbartoli
francbartoli / fastapi_demo.py
Created Jun 2, 2019 — forked from wshayes/fastapi_demo.py
[FastAPI Single File Demo] Example fastapi single file testable example #fastapi
View fastapi_demo.py
import logging
from fastapi import FastAPI
from starlette.responses import RedirectResponse
from starlette.testclient import TestClient
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
app = FastAPI()
@francbartoli
francbartoli / pygeoapi-config-ogc-dev-track-step1.yml
Created Mar 24, 2021
pygeoapi practical session - OGC developer track
View pygeoapi-config-ogc-dev-track-step1.yml
server:
bind:
host: 0.0.0.0
port: 5000
url: http://localhost:5000
mimetype: application/json; charset=UTF-8
encoding: utf-8
language: en-US
# cors: true
pretty_print: true
@francbartoli
francbartoli / cql.py
Created Mar 22, 2021
CQL JSON models
View cql.py
# generated by datamodel-codegen:
# filename: cql-schema.json
# timestamp: 2021-03-13T21:05:20+00:00
from __future__ import annotations
from datetime import date, datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Union
@francbartoli
francbartoli / conftest.py
Created Jun 2, 2019 — forked from wshayes/conftest.py
[Example conftest.py for fastapi/sqlalchemy] #fastapi #pytest
View conftest.py
# From @euri10 -- https://gitter.im/tiangolo/fastapi?at=5cd915ed56271260f95275ac
import asyncio
import pytest
from sqlalchemy import create_engine
from sqlalchemy_utils import create_database, database_exists, drop_database
from starlette.config import environ
from starlette.testclient import TestClient
@francbartoli
francbartoli / docker-cleanup-resources.md
Last active Sep 24, 2020 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks
View docker-cleanup-resources.md

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

View pygeoapi_config_geopython_demo.yml
server:
bind:
host: 0.0.0.0
port: 5000
url: http://localhost:5000
mimetype: application/json; charset=UTF-8
encoding: utf-8
language: en-US
# cors: true
pretty_print: true
@francbartoli
francbartoli / test_csv.py
Created Apr 14, 2020
COVID-19 data loaded by GDAL
View test_csv.py
from osgeo import gdal
ds = gdal.OpenEx('CSV:/vsicurl/https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni.csv', gdal.OF_VECTOR, open_options=['X_POSSIBLE_NAMES=long', 'Y_POSSIBLE_NAMES=lat'])
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
f.ExportToJson()
'{"type": "Feature", "geometry": {"type": "Point", "coordinates": [13.39843823, 42.35122196]}, "properties": {"data": "2020-02-24T18:00:00", "stato": "ITA", "codice_regione": "13", "denominazione_regione": "Abruzzo", "lat": 42.35122196, "long": 13.39843823, "ricoverati_con_sintomi": "0", "terapia_intensiva": "0", "totale_ospedalizzati": "0", "isolamento_domiciliare": "0", "totale_positivi": "0", "variazione_totale_positivi": "0", "nuovi_positivi": "0", "dimessi_guariti": "0", "deceduti": "0", "totale_casi": "0", "tamponi": "5", "note_it": "", "note_en": ""}, "id": 1}'
View MBTiles: Pipe GeoJSON from PostGIS to Tippecanoe.md

I had a large dataset in postgis and wanted to avoid the hassle of first exporting it to a several GB geojson file before tiling it with Tippecanoe.

ogr2ogr -f GeoJSON /dev/stdout \                                                                            
PG:"host=localhost dbname=postgres user=postgres password=thepassword" \
-sql "select * from a, roi where a.geom && roi.geom" \
| docker run -i -v ${PWD}:/data tippecanoe:latest tippecanoe \
--output=/data/yourtiles.mbtiles
@francbartoli
francbartoli / Dockerfile-geonode
Last active Nov 20, 2019
Reproducible and deterministic GeoNode image 2.10.1
View Dockerfile-geonode
FROM python:2.7.17-stretch AS base
MAINTAINER GeoNode development team
# This section is borrowed from the official Django image but adds GDAL and others
RUN apt-get update && apt-get install -y \
gcc \
zip \
gettext \
postgresql-client libpq-dev \
sqlite3 \