Skip to content

Instantly share code, notes, and snippets.

View elcritch's full-sized avatar

Jaremy Creechley elcritch

View GitHub Profile
@elcritch
elcritch / kalman_simple.nim
Last active February 26, 2022 09:38
Example Nim port of a Kalman filter
## * A simple kalman filter example by Adrian Boeing
## www.adrianboeing.com
## original at: https://gist.github.com/jannson/9951716
## Note: I imported this to Nim, but haven't run or tested it.
import std/random, std/strformat, std/math
proc runKalman*() =
## initial values for the kalman filter
@elcritch
elcritch / 00-setup-zephyr-opensuse.sh
Created December 7, 2021 01:43
Setup Zephyr Linux
sudo zypper in libusb-compat-devel
sudo zypper in mbedtls-devel libmbedtls13
sudo zypper in usbsdmux-udev udev-browse udev-extra-rules
sudo zypper install git cmake ninja-build gperf ccache dfu-util dtc wget \
python3-pip python3-tkinter xz file glibc-devel libstdc++-devel python38 \
SDL2-devel
@elcritch
elcritch / dts_example.nim
Created October 5, 2021 05:03
Example of DTS tree encoded into a pure Nim Macro
deviceTree:
&mikrobus_i2c {
status = "okay",
spi-max-frequency = `<100000>`,
}
&mikrobus_spi:
status: "okay"
click_spi2: spi-device@1 {
@elcritch
elcritch / usbreset.nim
Created March 12, 2021 04:34
usbreset.nim -- Nim version of USB port reset on Linux
## usbreset -- linux program reset a usb port using /dev/ttyUSB<n> file paths
# usage: usbreset /dev/ttyUSB0
# Install:
# nim c usbreset.nim
# sudo cp usbreset /usr/local/bin
# Setuid to not need sudo (at your own peril):
# sudo chmod 4555 /usr/local/bin/usbreset
import os, system, osproc, posix, strutils, re, strformat
@elcritch
elcritch / setup.sh
Created May 19, 2021 23:58
Manjaro dev tools setup because I always forget
sudo pacman -Syu base-devel --needed
@elcritch
elcritch / gist:95e1a62e7b6974768823ce4128584ea6
Created April 19, 2016 01:42
Upload to Box via WebDav using cURL
curl -u me@email.com:mypassword -T local_file_path https://dav.box.com/dav/remote_file_name
curl -u me@email.com:mypassword https://dav.box.com/dav/remote_file_name --output download_file_path
@elcritch
elcritch / gpio_setup_example.nim
Created March 7, 2021 20:33
Nim Hard Port Configuration Example
type
Direction* = enum
input
output
PinConf* = object
dir: Direction
Port0* = object
@elcritch
elcritch / valgrind.log
Created October 29, 2020 19:01
JSON RPC Memory Corruption - Nim 1.4.0
> $ valgrind -v --leak-check=yes ./rpcsocket_json [±compiler-1_4_0_failure-test ●]
==529377== Memcheck, a memory error detector
==529377== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==529377== Using Valgrind-3.16.1-36d6727e1d-20200622X and LibVEX; rerun with -h for copyright info
==529377== Command: ./rpcsocket_json
==529377==
--529377-- Valgrind options:
--529377-- -v
--529377-- --leak-check=yes
--529377-- Contents of /proc/version:
@elcritch
elcritch / other.exs
Created June 25, 2020 19:23
Byte String Pad
0x4A |> Integer.to_string(2) |> String.pad_leading(8, "0") |> String.pad_leading(10,"0x")
@elcritch
elcritch / parse_udhcpd.exs
Created June 25, 2020 01:57
Elixir Module to parse UDHCPD Lease Files
defmodule ParseUdhcpd do
def find_leases(interface \\ "eth0") do
udhcpd_lease_bytes =
"/tmp/vintage_net/udhcpd.#{interface}.leases"
|> File.read!()
<<written_at::signed-integer-64, leases_bytes::bits >> = udhcpd_lease_bytes
parse_leases(leases_bytes, [])