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.
#[derive(Clone)]
@dbrgn
dbrgn / PKGBUILD.diff
Created April 29, 2020 11:43
jcryptool-0.9.10-0
diff --git PKGBUILD PKGBUILD
index 15a4390..eeed273 100644
--- PKGBUILD
+++ PKGBUILD
@@ -2,12 +2,13 @@
# Contributor: Michael Düll <mail@akurei.me>
# Contributor: sancspi <sancospi [at] gmail.com>
# Contributor: tze <tze@datalove.me>
+# 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 {
Success(Redirect),
Invalid(Template, Status)
}
impl<'r> response::Responder<'r> for ValidationResult {
@dbrgn
dbrgn / testserver.py
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
dbrgn / button-shutdown.py
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
print('Initializing...')
# Pins
@dbrgn
dbrgn / numbering_mode.md
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
dbrgn / leds_button.py
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
BUTTON = 32
# Use the BOARD numbering system
@dbrgn
dbrgn / adc.py
Last active June 2, 2017 09:23
iC880A Backplane: ADC example script
"""
Example script to read the input voltage, measured by the MCP3425 ADC.
Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf
"""
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import time
import smbus
@dbrgn
dbrgn / state.rs
Created April 3, 2017 14:49
Custom Text based Diesel type for an enum
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all="snake_case")]
pub enum State {
Pending,
Sending,
Sent,
Failed,
}
impl fmt::Display for State {