Skip to content

Instantly share code, notes, and snippets.

View dbrgn's full-sized avatar

Danilo Bargen dbrgn

View GitHub Profile
use std::sync::Arc;
use tokio::sync::Semaphore;
/// An async latch.
/// Internally this is implemented using a semaphore with an initial value of 0.
/// The semaphore can be closed to "trigger" the latch. A "Closed" error when
/// awaiting the semaphore is treated as if the latch is unlocked.
dbrgn / PKGBUILD.diff
Created April 29, 2020 11:43
index 15a4390..eeed273 100644
@@ -2,12 +2,13 @@
# Contributor: Michael Düll <>
# Contributor: sancspi <sancospi [at]>
# Contributor: tze <>
+# Contributor: Danilo <aur ät dbrgn döt ch>
/// The result of a form validation: Either a successful redirect, or a
/// template response with an error status.
/// TODO: Generalize this and move it into a helper module.
pub enum ValidationResult {
Invalid(Template, Status)
impl<'r> response::Responder<'r> for ValidationResult {
dbrgn /
Created April 18, 2019 15:30
WASM aware python testserver
from http import server
PORT = 8000
class WasmAwareRequestHandler(server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.extensions_map['.wasm'] = 'application/wasm'
extern crate hyper;
extern crate reqwest;
extern crate rustysafe;
use std::thread;
use hyper::Server;
use hyper::rt::Future;
use hyper::service::service_fn;
dbrgn /
Created June 29, 2018 09:34
Example: Shutdown script for iC880A backplane
#!/usr/bin/env python3
import os
import sys
import time
import RPi.GPIO as g
# Pins
dbrgn /
Last active February 9, 2024 19:55
RPLCD numbering mode notes

In RPLCD version 1.0, some APIs were slightly changed. Previously the CharLCD instance would provide default values for the pin numbers and the numbering mode. But that was changed, since it may be dangerous if these pins are connected to other hardware.

So if you have installed version 1.0 of RPLCD, you need to provide the pin numbering mode yourself. If your code previously looked like this:

from RPLCD import CharLCD
lcd = CharLCD(cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[40, 38, 36, 32, 33, 31, 29, 23])

...and if you use the BOARD numbering scheme, then change the code like this:

dbrgn /
Last active April 5, 2018 10:05
iC880A Backplane: LED and button example script
import sys
import time
from RPi import GPIO
LED_R = 36
LED_Y = 38
LED_B = 40
# Use the BOARD numbering system
dbrgn /
Last active June 2, 2017 09:23
iC880A Backplane: ADC example script
Example script to read the input voltage, measured by the MCP3425 ADC.
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import time
import smbus
dbrgn /
Created April 3, 2017 14:49
Custom Text based Diesel type for an enum
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum State {
impl fmt::Display for State {