Skip to content

Instantly share code, notes, and snippets.

Avatar

Kristian Sloth Lauszus Lauszus

View GitHub Profile
@Lauszus
Lauszus / pre-commit
Last active Apr 20, 2021
clang-format pre-commit hook
View pre-commit
#!/bin/sh
# Check if this is the initial commit
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@Lauszus
Lauszus / max98357a-no-din-overlay.dts
Created Feb 23, 2021
Maxim MAX98357A audio DAC without using the PCM_DIN pin
View max98357a-no-din-overlay.dts
// Overlay for Maxim MAX98357A audio DAC without using the PCM_DIN pin
// dtparams:
// sdmode-pin - Specify GPIO pin to which SD_MODE is connected (default 20).
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
@Lauszus
Lauszus / mcp2515-spi0-4cs-overlay.dts
Last active Feb 6, 2021
Raspberry Pi device tree overlay for creating up to four CAN-Bus interfaces on spi0 using four MCP2515's
View mcp2515-spi0-4cs-overlay.dts
/*
* Device tree overlay for mcp251x on any spi interface by Kristian Sloth Lauszus.
* Should be used with the "spi0-4cs" overlay.
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
@Lauszus
Lauszus / main.py
Created Oct 1, 2020
Siglent SDS2000X plus hack
View main.py
import hashlib
SCOPEID = '0000000000000000'
Model = 'SDS2000X+'
# Note that 'AWG' should be used for the 'FG' option
# If you have the 100 MHz model, then first upgrade it to 200 MHz, then 350 MHz and finally 500 MHz
bwopt = ('25M', '40M', '50M', '60M', '70M', '100M', '150M', '200M', '250M', '300M', '350M', '500M', '750M', '1000M', 'MAX', 'AWG', 'WIFI', 'MSO', 'FLX', 'CFD', 'I2S', '1553', 'PWA')
hashkey = '5zao9lyua01pp7hjzm3orcq90mds63z6zi5kv7vmv3ih981vlwn06txnjdtas3u2wa8msx61i12ueh14t7kqwsfskg032nhyuy1d9vv2wm925rd18kih9xhkyilobbgy'
@Lauszus
Lauszus / os-release-bionic
Last active Sep 3, 2021
Nvidia SDKManager on Ubuntu 20.04
View os-release-bionic
# Put in "/usr/lib/os-release-bionic"
NAME="Ubuntu"
VERSION="18.04 (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04"
VERSION_ID="18.04"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
@Lauszus
Lauszus / 80-can.network
Last active Oct 15, 2020
Ubuntu 20.04 auto configure CAN bus interfaces using systemd
View 80-can.network
[Match]
Name=can*
[CAN]
BitRate=250000
# Put this file in: "/etc/systemd/network/" and then run "sudo systemctl enable systemd-networkd" to enable systemd-networkd
# Now start systemd-networkd: "sudo systemctl start systemd-networkd"
# Credit: https://github.com/linux-can/can-utils/issues/68#issuecomment-584505426
@Lauszus
Lauszus / hass_install_notes.md
Last active Dec 9, 2019
Home Assistant Docker installation notes on a Raspberry Pi 3
View hass_install_notes.md

Install some required packages first:

sudo apt-get update
sudo apt-get install -y \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common
@Lauszus
Lauszus / gh-dl-release
Created Jun 6, 2019 — forked from maxim/gh-dl-release
Download assets from private Github releases
View gh-dl-release
#!/bin/bash -e
#
# gh-dl-release! It works!
#
# This script downloads an asset from latest or specific Github release of a
# private repo. Feel free to extract more of the variables into command line
# parameters.
#
# PREREQUISITES
#
@Lauszus
Lauszus / crc.py
Last active Oct 11, 2021
Generic CRC-8, CRC-16 and CRC-32 calculations in Python
View crc.py
#!/usr/bin/env python
# Inspired by: https://www.youtube.com/watch?v=izG7qT0EpBw
# The CRC values are verified using: https://crccalc.com/
def reflect_data(x, width):
# See: https://stackoverflow.com/a/20918545
if width == 8:
x = ((x & 0x55) << 1) | ((x & 0xAA) >> 1)
x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2)
x = ((x & 0x0F) << 4) | ((x & 0xF0) >> 4)
@Lauszus
Lauszus / GPS.py
Created Feb 21, 2019
GPS NMEA string generator
View GPS.py
#!/usr/bin/env python
import numpy as np
def main():
def ubx_checksum(data):
ck_a = 0
ck_b = 0
for byte in data: