Skip to content

Instantly share code, notes, and snippets.

@jacopofar
jacopofar / wiktextract_schema.json
Created December 20, 2022 14:43
JSONSchema of a Wiktextract entry
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"pos": {
"type": "string",
"enum": [
"noun",
"verb",
"adj",
@jacopofar
jacopofar / shapely_to_3d_mesh.py
Created February 22, 2022 15:20
Render Shapely multipolygon as a 3D prism and export in gltf2
from shapely import wkb
from shapely.ops import triangulate
from shapely.geometry import LineString
import trimesh
# Hol-y building https://www.openstreetmap.org/relation/3868363
wkb_holes = bytes.fromhex(
"""
01060000000100000001030000000500000036000000BBA067EAA3D836414EC6A5B2124A5A415E4
E319AAED83641F70DA6AD114A5A4151BE9F9CB9D83641BE8D6992104A5A416011309ED4D8364162
@jacopofar
jacopofar / steam_system_information.txt
Created November 13, 2021 20:04
Steam system information
Computer Information:
Manufacturer: Unknown
Model: Unknown
Form Factor: Laptop
No Touch Input Detected
Processor Information:
CPU Vendor: AuthenticAMD
CPU Brand: AMD Ryzen 7 PRO 4750U with Radeon Graphics
CPU Family: 0x17
@jacopofar
jacopofar / countries_capitals.tsv
Created April 27, 2021 10:33
Some countries and capitals for an exercise
England London
Scotland Edinburgh
United Kingdom London
Northern Ireland Belfast
France Paris
Wales Cardiff
Georgia Tbilisi
Germany Berlin
Greece Athens
Greenland Nuuk
#!/usr/bin/env bash
#####
# This script runs OUTSIDE docker, and uses pgosm-flex to load a PBF file into postgres
# then generates a dump, which is used later to rebuild a DB from scratch
# Usage: ./database_from_pbf.sh some-file.osm.pbf
#####
# exit on error
set -e
@jacopofar
jacopofar / sql_flex_dump_from_pbf.sh
Created March 9, 2021 19:00
sql_flex_dump_from_pbf.sh
#!/bin/bash
# This script is designed to run INSIDE the pgosm-flex container
# Run with:
# ./sql_flex_dump_from_pbf.sh \
# /app/input/filename.pbf \
# 4000 \
# run-all
#
# $1 - the PBF file to ingest
# $2 - Cache (mb) - e.g. 4000
@jacopofar
jacopofar / sse_fe.py
Created February 14, 2020 21:39
Starlette SSE with demo frontend
from asyncio.queues import Queue
import uvicorn
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import JSONResponse, StreamingResponse, HTMLResponse
class SSE:
def __init__(self, data, event=None, event_id=None, retry=None):
@jacopofar
jacopofar / sunrise_sunshine.py
Created May 17, 2019 17:47
Sunrise and sunshine calculation in pure Python 3.7
"""Calculate the sunrise, sunset and noon time for a given coordinate.
Based on the code at: https://michelanders.blogspot.com/2010/12/calulating-sunrise-and-sunset-in-python.html
"""
from math import cos, sin, acos, asin, tan
from math import degrees as deg, radians as rad
from datetime import datetime, time, timezone, timedelta
class Sun:
"""
@jacopofar
jacopofar / jwt_keypair_expiration.py
Created July 25, 2018 15:32
Python 3 JWT example with keypair
import datetime
import time
# not used, but required by pyjwt, import to ensure it exists
import cryptography
import jwt
key = 'secret'
encoded = jwt.encode({'some': 'payload'}, key, algorithm='HS256')
print('encoded', encoded)
@jacopofar
jacopofar / ensure_venv.sh
Last active November 13, 2017 10:17
Create a virtualenv based on the hash of a requirements.txt file if it does not exist, and softlink it
#!/bin/sh
# processes a requirements.txt file, creates the virtualenv in a given folder
# if it does not exist already and creates a symlink to that
if [[ ! $# -eq 3 ]] ; then
echo 'Parameters error' 1>&2
echo 'Required: the requirements.txt path, the folder for the virtualenvs and the symlink to create' 1>&2
exit 1
fi
set -x