Skip to content

Instantly share code, notes, and snippets.

Avatar

Ruurd Moelker RRMoelker

View GitHub Profile
@RRMoelker
RRMoelker / highlightjs-tag-nunjucks.js
Created Dec 5, 2019
Nunjuck highlight.js tag extension
View highlightjs-tag-nunjucks.js
//
// Allows highlighting of code blocks in Nunjucks template.
// https://mozilla.github.io/nunjucks/api.html#custom-tags
//
const nunjucks = require('nunjucks');
const hljs = require('highlight.js');
function HighlightJsExtension() {
this.tags = ['highlightjs'];
@RRMoelker
RRMoelker / asyncio_pipeline_basic.py
Last active Nov 12, 2021
Dead simple asyncio pipeline
View asyncio_pipeline_basic.py
"""
Example program for basic asyncio pipeline.
Program takes string as input and converts it to upper case.
For sake of simplicity missing some "features", most notably error handling is absent.
Errors will silenty prevent program completion in many cases.
"""
import asyncio
from dataclasses import dataclass
@RRMoelker
RRMoelker / rapid-recording.py
Created Oct 21, 2019
YUV format picamera real time recording
View rapid-recording.py
# python3
# based on https://raspberrypi.stackexchange.com/questions/58871/pi-camera-v2-fast-full-sensor-capture-mode-with-downsampling/58941#58941
import time
import picamera
import numpy as np
from PIL import Image
RECORD_TIME = 5 # number of seconds to record
WRITE_IMAGES = False
@RRMoelker
RRMoelker / mutli-value-labelled-arduino-serial-plotter-example.ino
Created Jul 25, 2020
Multi value labelled Arduino Serial Plotter example, open serial plotter in Arduino IDE to see the labelled lines plotted over time.
View mutli-value-labelled-arduino-serial-plotter-example.ino
int t = 0;
void setup() {
Serial.begin(38400);
}
void loop() {
double a = sin(t / 100.0);
double b = cos(t / 110.0);
double c = sin(t / 50.0) + 1.0;
@RRMoelker
RRMoelker / detect_marker_still.py
Last active Oct 24, 2019
Image marker recognition, threshold, opening, connected components and centroid calculation
View detect_marker_still.py
"""
Detect markers in image and display results
"""
import time
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from skimage import io
from skimage import morphology
@RRMoelker
RRMoelker / detect_marker_still.py
Created Oct 24, 2019
Image marker recognition, threshold, opening, connected components and centroid calculation
View detect_marker_still.py
"""
Detect markers in image and display results
"""
import time
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from skimage import io
from skimage import morphology
@RRMoelker
RRMoelker / capture-luminance.py
Last active Oct 21, 2019
Capture luminance still Raspberry PI camera
View capture-luminance.py
# python3
# based on https://raspberrypi.stackexchange.com/questions/58871/pi-camera-v2-fast-full-sensor-capture-mode-with-downsampling/58941#58941
import time
import picamera
import numpy as np
from PIL import Image
RESOLUTION = (1640, 1232)
# Calculate the actual image size in the stream (accounting for rounding
@RRMoelker
RRMoelker / serial_list_detail_example.py
Created Jul 25, 2019
Performs list detail network requests in sequence
View serial_list_detail_example.py
"""
Example program that retrieves sink speed for first 100 meetbouten.
First fetches ids using list endpoint and calls detail endpoint for each id.
p.s. A meetbout is a physical screw on the outside of a building which is used to determine the "sink" rate of the
structure.
"""
import logging
import json
import sys
@RRMoelker
RRMoelker / asyncio_list_detail_pipeline.py
Created Jul 25, 2019
Asyncio pipeline performing concurrent network request
View asyncio_list_detail_pipeline.py
"""
Asyncio pipeline example program that retrieves sink speed for first 100 meetbouten.
First fetches ids using list endpoint and calls detail endpoint for each id.
p.s. A meetbout is a physical screw on the outside of a building which is used to determine the "sink" rate of the
structure.
"""
import asyncio
import json
import random