Skip to content

Instantly share code, notes, and snippets.

View aw's full-sized avatar

Alex Williams aw

View GitHub Profile
@aw
aw / sram.rs
Last active March 8, 2021 03:29
Rust embedded driver for Microchip 23x SRAM/NVSRAM - https://blog.a1w.ca/p/rust-embedded-driver-microchip-23x-sram/
#![no_std]
#![no_main]
use panic_halt as _;
use embedded_graphics::fonts::{Font12x16, Text};
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::Rectangle;
use embedded_graphics::{primitive_style, text_style};
@aw
aw / twos-complement.md
Created October 12, 2020 09:42
Twos complement and reverse in PicoLisp

This obtains the twos complement of a signed integer (from signed -> unsigned), or reverse (from unsigned -> signed)

  • Int: an positive or negative integer
  • Size: expressed in bits (ex: 8, 16, 32, 64...)
(de twos-complement (Int Size)
  (if (lt0 Int)
      (+ Int (>> (- Size) 1))
      (if (=0 (& Int (>> (- (- Size 1)) 1)))
 Int
@aw
aw / posix_mq_attr.md
Last active September 15, 2020 03:03
mq_attr struct size is 64 bytes, not 32

Problem

When parsing with PicoLisp (native) and the mq_getattr() call, I kept seeing errors such as:

corrupted size vs. prev_size

or

@aw
aw / bitmap64.l
Last active November 9, 2020 08:44
Fast'ish bitmap ops (population count, set/clear/toggle bit) in PicoLisp
#!/usr/bin/env pil
# 64-bit max
#
# functions to set/clear/toggle a specific bit in an 64-bit integer (8 bytes)
[de lpad (Int)
(pad 64 (bin Int) ]
[de getbit (Int Pos)
(& 1 (>> Pos Int) ]
@aw
aw / headers-patch.l
Last active May 28, 2020 23:48
[PicoLisp] Store extra HTTP headers in global variable
# load this code after loading http.l
# ex: pil http.l headers-patch.l --server 8000 yourcode.l
(patch _htHead
'(T (if (eol) (char) (line T) @S))
(fill '(T (if (eol) (char) (when @ (push '*Headers (list @ (cdr (line))))))
. @S) ) )
@aw
aw / explain.md
Last active April 21, 2024 13:38
[SOLVED] Proxmox VE and cloud-init snippets etc

Proxmox VE 6.x release includes a feature to add custom cloud-init configs. Unfortunately there is poor documentation, so I had to figure this out by adding pieces of information together.

The custom cloud-init files (user-data, meta-data, network-config)

The cloud-init files need to be stored in a snippet. This is not very well documented:

  1. Go to Storage View -> Storage -> Add -> Directory
  2. Give it an ID such as snippets, and specify any path on your host such as /snippets
  3. Under Content choose Snippets and de-select Disk image (optional)
  4. Upload (scp/rsync/whatever) your user-data, meta-data, network-config files to your proxmox server in /snippets/snippets/ (the directory should be there if you followed steps 1-3)
@aw
aw / csv.md
Last active May 14, 2018 06:24
CSV parsing in PicoLisp

Parse a CSV in PicoLisp:

Examples:

: (make-csv "Testing,csv,\"parsing,a,csv\",test")
-> ("Testing" "csv" "\"parsing,a,csv\"" "test")
: (make-lst '("n" "g" "," "\"" "p" "a" "," "a" "," "c" "s" "v" "\"" "," "t") ",")
-> (("n" "g") (("\"" "p" "a" "," "a" "," "c" "s" "v" "\"")) ("t"))
: (make-quot '("n" "g" "," "\"" "p" "a" "," "a" "," "c" "s" "v" "\"" "," "t"))
@aw
aw / native-atomic.md
Last active May 7, 2018 06:10
Create a file atomically in PicoLisp using native

PicoLisp's (native) can be used to create files atomically

The C equivalent would be:

open("atomic.file", O_RDWR|O_CREAT|O_EXCL, 0644);

PicoLisp:

@aw
aw / picolisp-wildcard.md
Created February 3, 2018 13:41
PicoLisp glob/wildcard expansion in call and exec commands

In PicoLisp, there is often a situation where you want to execute a command with the * argument. Bash shell expands * to the list of filenames, but PicoLisp doesn't.

Here are two workarounds for this bash command:

grep -l "let" *

1. with (cons)

@aw
aw / uptime.l
Created January 5, 2018 10:16
Parse uptime in PicoLisp
# (MIT)
# v1
(setq *Mystr "09:56:51 up 6:46, 1 user, load average: 0.81, 0.45, 0.36")
(extract pack (mapcar clip (split (stem (chop *Mystr) "l" "o" "a" "d" "a" "v" "e" "r" "a" "g" "e" ":") ",")))