Skip to content

Instantly share code, notes, and snippets.

@sonkol
sonkol / routes_stops.sql
Created October 22, 2024 17:34
List stops that chosen routes stop at
SELECT DISTINCT
stop_id,
stop_name,
group_concat(DISTINCT route_short_name ORDER BY cast(route_id AS INT)) routes,
group_concat(DISTINCT trip_headsign ORDER BY cast(route_id AS INT)) headsigns
FROM stop_times
INNER JOIN stops using (stop_id)
INNER JOIN trips using (trip_id)
INNER JOIN routes using (route_id)
WHERE trip_operation_type = 1 -- do not list services in/outbound of depots
@sonkol
sonkol / next_stops.sql
Created October 9, 2024 14:33
Given a stop from which connections departure, return a list of following stops
-- Query GTFS tables
SELECT DISTINCT
x.stop_id,
next_stop,
stops.stop_name
FROM
(
SELECT
stop_id,
stop_sequence,
@sonkol
sonkol / average.py
Last active January 21, 2025 11:18
Average of pngs in folder
# Based on https://stackoverflow.com/a/17383621
import os, numpy, PIL
from PIL import Image
# Access all PNG files in directory
allfiles=os.listdir(os.getcwd())
imlist=[filename for filename in allfiles if filename[-4:] in [".png",".PNG"]]
# Assuming all images are the same size, get dimensions of first image
@sonkol
sonkol / rand4.sh
Created July 22, 2024 14:22
Generate random 4 digit numbers
cat /dev/urandom | tr -cd "0-9" | head -c 60 | sed "s/.\{4\}/&\n/g"
@sonkol
sonkol / download_sdo.js
Last active July 22, 2024 14:24
Download SDO imagery in regular intervals (uses Luxon time library)
date = luxon.DateTime.fromISO("2024");
final = luxon.DateTime.fromISO("2024-04-30");
string = "";
for (;date < final; date = date.plus({minutes: 90})){
Y = date.toFormat("y");
M = date.toFormat("LL");
D = date.toFormat("dd");
h = date.toFormat("HH");
m = date.toFormat("mm");
s = date.toFormat("ss");