Skip to content

Instantly share code, notes, and snippets.

View loleg's full-sized avatar

Oleg Lavrovsky loleg

View GitHub Profile
@loleg
loleg / geohelper.js
Created October 21, 2022 13:57
A tiny library to load common GeoJSON formats in Processing
// A function that helps plot various GeoJSON to the canvas. This does not
// cover every type and use case, but may be a useful reference.
// See also: https://mappa.js.org/
function drawGeoJson(json_data, palette='white') {
// Iterate every feature
json_data.features.forEach((feature, ix) => {
// Make sure that we have a properly formatted file
if (typeof feature.geometry !== 'object' ||
@loleg
loleg / CHtoWGS84.js
Last active October 11, 2022 15:51
Convert GeoJSON in Swiss coordinates (fromLV03 or fromLV95) to WGS84
// Adapted from https://github.com/idris-maps/swiss-projection
// https://gist.github.com/loleg/06ad3db0cbbfadb200be7fc0b1451c35/revisions
// https://www.swisstopo.admin.ch/content/swisstopo-internet/en/online/calculation-services/_jcr_content/contentPar/tabs/items/documents_publicatio/tabPar/downloadlist/downloadItems/19_1467104393233.download/ch1903wgs84_e.pdf
// Convert the projection coordinates E (easting) and N (northing) in LV95 into the civilian system (Bern = 0 / 0) and express in the unit [1000 km]
var getY2FromE = function (E) { return (E - 2600000) / 1000000; };
var getX2FromN = function (N) { return (N - 1200000) / 1000000; };
// Convert the projection coordinates y and x in LV03 into the civilian system (Bern = 0 / 0) and express in the unit [1000 km]
var getY2FromY = function (y) { return (y - 600000) / 1000000; };
var getX2FromX = function (x) { return (x - 200000) / 1000000; };
@loleg
loleg / shuffle.js
Last active April 3, 2022 10:14
Populates a column of random numbers for shuffling the order of an Airtable
// Select a table containing a "Sort Order" number column
const TABLE_NAME = "<Your Table Name Here>"
// A time limit comfortably within the allowable script runtime
const MAX_TIME = 25;
// Maximize shuffle within the time limit
const startTime = new Date();
function timeElapsed() {
const endTime = new Date().getTime();
@loleg
loleg / geoadmincoding.js
Last active July 18, 2022 14:15
Airtable script for geocoding addresses using the swisstopo REST API
/* Geocoding utility script by @loleg
* Latest version: https://gist.github.com/loleg/2e38752732e29472993dd74da988d7e6
*
* - fills location coordinates based on an "Address" field
* - uses the open data API service of swisstopo (Switzerland only)
* - currently auto-throttled by Airtable, with fetch limits
* - retries continuously to let you fix addresses in your table
* - add this to a "create record" automation and also limit by time
*
* Required fields:
@loleg
loleg / DDA.p5.js
Created January 24, 2022 16:41
The simplest line drawing algorithm
/*
* @name DDA graphics algorithm
* @description A simple implementation of line rasterization using the Digital differential analyzer.
* Press the mouse button on any two points to draw a line. A color will be picked at random.
* See https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
*/
let i = x1 = y1 = x2 = y2 = dx = dy = step = 0;
let pickStart = pickEnd = false;
@loleg
loleg / combine_data_by_egid.py
Created November 13, 2021 08:12
Combine geodata referenced by EGID (building identifier) #DataHackdaysBE
import csv, io
# Configuration
input_addresses = "Gebaeudeadressen_1636760957021_53445 - Gebäudeadressen.csv"
egidcol_addresses = "Eidg. Gebäude-ID (EGID)"
input_opendata = "V20211111.csv"
egidcol_opendata = "egid"
output_filename = "combined.csv"
# Preload address file
@loleg
loleg / emojipedia-cheatsheet.js
Created June 26, 2021 09:15
Console script to generate an Emoji cheatsheet
/*
1. Go to any emoji list page on Emojipedia, e.g.
https://emojipedia.org/google/
2. Scroll down until every icon has loaded
3. Run this script in your console
4. Print!
*/
$('li a img').each(function() { nm = $(this).attr('title'); $(this).parent().append('<ttl>' + nm + '</ttl>') });
$('header,.ad-header,.ad-footer,section,.vsfilter,.sidebar,footer').hide();
@loleg
loleg / santa.py
Created December 6, 2020 10:21 — forked from will-bainbridge/santa.py
Secret Santa script
#!/usr/bin/python3
"""
Ye olde Secret Santa script based on https://gist.github.com/will-bainbridge/a4666a196fb5833cf37035647b74c064
You will need to prepare a "people file", which is in CSV format (UTF-8, comma delimited) and has the following columns (without a header row)
Name, E-mail, Extra content 1, Extra content 2
We used the postal address as extra content 1 and a link to Google Street View as extra content 2. Then you can specify a plain text message file which includes %s for the buyer name, recipient name, recipient extra 1, and recipient extra 2 (in that order!). For example:
title tags description slideOptions
Oleg @ OpenDataBeer 12
dribdat
View the slide with "Slide Mode".
theme
white

OpenDataBeer logo

@loleg
loleg / corona-mix.ino
Created October 30, 2020 17:16
A zombie remix of tamberg's SwissCovid-detector and ganda1f's PartyNoise-detector
// Just getting my hands dirty with Arduino! Please don't be upset ...
/* Sources:
*
* https://github.com/gand417/mz2020_audio/blob/main/mz2020_audio.ino
* https://github.com/make-zurich/makezurich-hardware-intro/blob/master/Arduino/Neno33BleSense_CoronaAppScanner/Neno33BleSense_CoronaAppScanner.ino
*/
#include <Adafruit_NeoPixel.h>
#include <ArduinoBLE.h>