Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco Bartoli francbartoli

View GitHub Profile
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
Created Nov 19, 2019 — forked from caio/Dockerfile
A multi-stage Dockerfile to build an image for a minimal python pipenv-managed app
View Dockerfile
FROM python:3.7 as build
# The python:3.7 image is HUGE but already comes with all the essentials
# for compiling (most) python modules with native dependencies
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
RUN pip install pipenv
WORKDIR /build
COPY Pipfile Pipfile.lock /build/
View GeoNode_2.4_2.10_migration.md

GeoNode 2.4 -> 2.10.1 migration

PostgreSQL

Create a role and a database for Django:

create role user with superuser login with password '***';
create database gn_24 with owner user;
\c gn_24
View timescale--db--backend--base.py
import logging
from django.contrib.gis.db.backends.postgis.base import \
DatabaseWrapper as PostgisDBWrapper
from django.db import ProgrammingError
from .schema import TimescaleSchemaEditor
logger = logging.getLogger(__name__)
@francbartoli
francbartoli / diff_strings.py
Created Aug 1, 2019 — forked from ines/diff_strings.py
Print colored visual diff in Python
View diff_strings.py
import difflib
import wasabi
def diff_strings(a, b):
output = []
matcher = difflib.SequenceMatcher(None, a, b)
for opcode, a0, a1, b0, b1 in matcher.get_opcodes():
if opcode == "equal":
output.append(a[a0:a1])
elif opcode == "insert":
View fastapi_basic_imports.py
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel
View fastapi_api_key.py
from fastapi import Security, Depends, FastAPI, HTTPException
from fastapi.security.api_key import APIKeyQuery, APIKeyCookie, APIKeyHeader, APIKey
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
from starlette.status import HTTP_403_FORBIDDEN
from starlette.responses import RedirectResponse, JSONResponse
API_KEY = "1234567asdfgh"
API_KEY_NAME = "access_token"
View fastapi_google_authentication_imports.py
from typing import Optional
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from fastapi import Depends, FastAPI, HTTPException
from fastapi.encoders import jsonable_encoder
from fastapi.security.oauth2 import (
OAuth2,
View fastapi_basic.py
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel
@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()