Skip to content

Instantly share code, notes, and snippets.

@laanwj
laanwj / 99-aithra-serial.rules
Last active January 11, 2021 16:54
udev rules example for lots of serial devices (put in /etc/udev/rules.d)
# serial devices
# get attributes using: udevadm info -a -n /dev/ttyUSBn
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="Flyswatter2", ENV{ID_USB_INTERFACE_NUM}=="00", SYMLINK+="serial/flyswatter-jtag"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="Flyswatter2", ENV{ID_USB_INTERFACE_NUM}=="01", SYMLINK+="serial/flyswatter-tty"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="Dual RS232-HS", ENV{ID_USB_INTERFACE_NUM}=="00", SYMLINK+="serial/unleashed-jtag"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="Dual RS232-HS", ENV{ID_USB_INTERFACE_NUM}=="01", SYMLINK+="serial/unleashed-tty"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ATTRS{product}=="Quad RS232-HS", ENV{ID_USB_INTERFACE_NUM}=="00", SYMLINK+="serial/zodiac-jtag0"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ATTRS{product}=="Quad RS232-HS", ENV{ID_USB_IN
@laanwj
laanwj / gitian.md
Last active September 23, 2020 15:35
gitian buildling on debian 9.5

Some changes are needed to build on debian because of the switch of the guest OS to bionic.

lxc that comes with debian is not high enough version to support bionic (the minimum is 2.1.1), so need to build from scratch.

debootstrap that comes with debian will give the following error:

    $ bin/make-base-vm --lxc --suite bionic --arch amd64                                                                                              
 E: No such script: /usr/share/debootstrap/scripts/bionic
@laanwj
laanwj / blocktoimg.py
Last active January 31, 2024 11:06
tools to write (block) data to png files and vice versa
#!/usr/bin/env python3
# Distributed under the MIT software license
import binascii, struct, sys, io, argparse
from PIL import Image
IMG_WIDTH = 512 # could be made adaptive...
MIN_HEIGHT = 4 # minimum height of image; twitter won't let us upload anything smaller
BYTES_PER_PIXEL = 4 # RGBA, 8 bit
def div_roundup(x,y):
@laanwj
laanwj / sendalert.cpp
Created June 14, 2018 20:24
sendalert.cpp
// *** CONFIDENTIAL - NOT FOR RELEASE ***
#include "main.h"
#include "net.h"
#include "alert.h"
#include "init.h"
static const int64_t DAYS = 24 * 60 * 60;
void ThreadSendAlert()
{
@laanwj
laanwj / c++14.patch
Created May 31, 2018 07:50
Patch for buiding Bitcoin Core with C++14
diff --git a/configure.ac b/configure.ac
index 1ffef1527bdb556dff79338f4052d1b49ae6bc42..5f324894bd861fe92ec7fad24b6687876b0e1919 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,8 +60,8 @@ case $host in
lt_cv_deplibs_check_method="pass_all"
;;
esac
-dnl Require C++11 compiler (no GNU extensions)
-AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
@laanwj
laanwj / moonphase.py
Last active September 15, 2022 14:46
#!/usr/bin/python3
import datetime
import bisect
import ephem
DAY = 1.0/29.33
MOONPHASE = [
(0.0/4.0 + DAY, '🌑', 'New moon'),
(1.0/4.0 - DAY, '🌒', 'Waxing crescent moon'),
(1.0/4.0 + DAY, '🌓', 'First quarter moon'),
From b12050e430f6bf37334dd7b6995dd8c97d8aa68a Mon Sep 17 00:00:00 2001
From: "Wladimir J. van der Laan" <laanwj@gmail.com>
Date: Thu, 13 Jul 2017 15:43:09 +0000
Subject: [PATCH] etnaviv: NEON implementations of tiling/untiling
Experiemental NEON implementation of tiling/untiling that adds
specialized NEON function for tiling 8, 16, 32 bit per element
4x4 tiles. To optimize memory read/write sizes, there are functions that
process multiple horizontically adjactent tiles as well. These
are automatically used for the part that consists of whole tiles.
#!/usr/bin/python3
import json
class notreallydict(dict):
def __init__(self, x):
dict.__init__(self, x)
self.x = x
def items(self):
return self.x
@laanwj
laanwj / fds.c
Created November 30, 2017 20:28
Check fd assignment
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
close(STDIN_FILENO);
int fd = open("/dev/null", O_RDWR);