Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env python
# Tested on Postgres 9.5
import psycopg2
import datetime
conn = psycopg2.connect("dbname=sandbox user=postgres")
cursor = conn.cursor()
View numbers.everyone.should.know.txt
Numbers Everyone Should Know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
jeromer /
Last active Aug 20, 2021
compass bearing between two points in Python
# LICENSE: public domain
def calculate_initial_compass_bearing(pointA, pointB):
Calculates the bearing between two points.
The formulae used is the following:
θ = atan2(sin(Δlong).cos(lat2),
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong))
jeromer /
Created Feb 22, 2012
Orthodromic distance using the Harversine formula in Python
# -*- coding: utf-8 -*-
import math
def calculate_orthodromic_distance(pointA, pointB):
Calculates the great circle distance between two points.
The great circle distance is the shortest distance.
This function uses the Haversine formula :