Skip to content

Instantly share code, notes, and snippets.

@errkk
errkk / dl.py
Last active July 10, 2023 09:37
Generate Driving licence number
#! /usr/bin/python3
# Thing for making up a valid (ish) driving licence number
# https://www.drivercheck.co.uk/find-out-more/photocard-driving-licence-explained/
# Note checksum is just dumped on there, not generated cos IDK how it's calculated
import argparse
from datetime import date
from typing import Tuple
@errkk
errkk / garage.rb
Last active December 26, 2016 19:09
#!/usr/bin/env ruby
#
require 'rmodbus'
status_labels = [
['Drive not ready', 'Ready for operation (READY)'],
['Stop', 'Running operation message (RUN)'],
['Clockwise rotating field (FWD)', 'Anticlockwise rotating field (REV)'],
['No fault', 'Fault detected (FAULT)'],
['No warning', 'Warning active (ALARM)'],
@errkk
errkk / findpis.sh
Last active May 18, 2016 17:07
Find Raspberry Pis on network
#!/bin/sh
RANGE=$1
echo "Looking for Pis in 10.193.${RANGE:-9}.0/24"
sudo nmap -sP "10.193.${RANGE:-9}.0/24" | grep "B8:27" -B 2
@errkk
errkk / Stepper.ino
Last active April 19, 2016 21:53
Controls a 4 phase 28BYJ-48 stepper motor, via some digital pins an an LM2003 driver
// Control a 4 phase stepper motor with an Arduino
// Controls a 28BYJ-48 stepper motor, via some digital pins an an LM2003 driver
// Uses direct port manipulation for fast concurrent pin state changes
// https://en.wikipedia.org/wiki/Stepper_motor#/media/File:Drive.png
int motorSpeed = 1000;
int count = 0;
int countsperrev = 32*16;
// can do > 1100 uS
#include <TinyWireS.h>
// MAX INT 32767
#ifndef TWI_RX_BUFFER_SIZE
#define TWI_RX_BUFFER_SIZE (16)
#endif
#define ADDR 0x11
// readCapacitivePin
// Input: Arduino pin number
// Output: A number, from 0 to 17 expressing
// how much capacitance is on the pin
// When you touch the pin, or whatever you have
// attached to it, the number will get higher
uint8_t readCapacitivePin(int pinToMeasure) {
// Variables used to translate from Arduino to AVR pin naming
volatile uint8_t* port;
@errkk
errkk / gist:7412982
Created November 11, 2013 13:11
cooking bad
eyJzdiI6eyJjIjoiMzFkNjMiLCJjcyI6ImkyYmwiLCJ3IjoiY2Y5IiwiY2wiOiJjMTowfGMyOjF8YzM6MHxjNDoxfGM1OjF8YzY6MSIsInNsIjoiczE6MnxzMjozfHMzOjF8czQ6NXxzNToyfHM2OjF8czc6MCIsImJuIjoiYjE6MHxiMjozfGIzOjJ8YjQ6MnxiNTowIiwidSI6InUwMXx1MDJ8dTAzfHUwNHx1MDV8dTA2fHUwN3x1MDl8dTEwfHUxMXx1MTJ8dTEzfHUxNHx1MTV8dTE2fHUxN3x1MjZ8dTI3fHUyOHx1Mjl8dTMwfHUzMXx1MzJ8dTMzfHUzNHx1MzV8dTM2fHUzN3x1MzgiLCJzIjoic2VsbGVyX3JwczoxODd8Y2xpY2tlcl9ycHM6MTIyfGJhbmtfcnBzOjVnY3xjaGVhdGVkX3dpZGdldHM6MHxjaGVhdGVkX2Nhc2g6MHxoYW5kX21hZGVfd2lkZ2V0czpmNjU0fG1hZGVfd2lkZ2V0czoxZGJjai5mazNrM2JhM2cwaXxzb2xkX3dpZGdldHM6MWNtbGEuYjBuMG4wNjdlZzN8aGFuZF9zb2xkX3dpZGdldHM6NWNiYy5uMG4wbjEwODI5MjZ8c2Vjb25kc19wbGF5ZWQ6NWFofGJvdWdodF91cGdyYWRlczoxNXx0b3RhbF9jYXNoOjEyaGprbi5rOWU5ZWNoZGx8c3RhcnRfdGltZTpjZGoxZ2RoZGYifSwiYWMiOiJhMDF8YTAyfGEwM3xhMDR8YTA3fGEwOHxhMTR8YTE4fGEyMnxhMjMifQ
@errkk
errkk / RadioSwitch.ino
Last active December 27, 2015 04:19
RadioSwitch
// See http://www.fanjita.org/serendipity/archives/53-Interfacing-with-radio-controlled-mains-sockets-part-2.html
#define PAYLOAD_SIZE 48
#define DATA_PIN A4
#define VCC_PIN A5
#define GND_PIN A3
#define LED_PIN 13
#define CHANNEL 1
#define TURNON 1
@errkk
errkk / gist:7006532
Created October 16, 2013 11:52
Pusher Parrot
#include <SPI.h>
#include <Ethernet.h>
#include <PusherClient.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
PusherClient client;
IPAddress ip(192,168,1,101);
const int parrot = 3;
@errkk
errkk / gist:6279024
Last active December 21, 2015 08:38
Composite a PNG over an input video frame by frame
avconv -i input.mp4 -f image2 frames/f_%00d.jpg
for F in $(ls frames/)
do
composite -compose atop -gravity SouthWest overlay_frame.png frames/$F out/$F
done
avconv -f image2 -i out/f_%00d.jpg out.mpeg -b 2400kb