Skip to content

Instantly share code, notes, and snippets.

@bkw777
bkw777 / DIP_PCB_LEGS.md
Last active December 8, 2025 06:42
DIP PCB LEGS

It's common these days to need to replace obsolete DIP chip parts in vintage electronics with small PCBs that fit where the DIP chips used to go. For instance the infamous SID and PLA chips in Commodore computers.

However the most common types of pin headers available to make the legs are actually too thick and they damage DIP sockets. This includes common machined round pins, which are thinner than the square pins, and ok for use in round sockets, but still technically a bit too thick for leaf sockets. They can compress the wipers and make the socket no longer make a good connection with a real DIP chip any more. Also those pins always have a quite large insulator & shoulder, and in some cases there is not much room where a DIP chip came out of for that much vertical thickness of the pin header shoulders and insulators plus the pcb plus the components soldered to the pcb.

Here are 3 different ways to make DIP legs on PCBs, where the legs are thin enough not to stretch out leaf/wiper style DIP sockets, and

@bkw777
bkw777 / bash_uname.sh
Last active August 7, 2021 00:15
Platform detection in bash without external executables (no /bin/uname)
#!/usr/bin/env bash
# Example to detect OS in bash using bash built-in variable $OSTYPE instead of `uname`
# platform differences
stty_f="-F" SERIAL_TTY_PREFIX=ttyUSB # Default (Linux)
case "${OSTYPE,,}" in
*bsd*) stty_f="-f" SERIAL_TTY_PREFIX=ttyU ;; # FreeBSD/NetBSD/OpenBSD/etc
darwin*) stty_f="-f" SERIAL_TTY_PREFIX=cu.usbserial- ;; # Mac OSX
esac
@bkw777
bkw777 / bin_to_hex_to_bin.sh
Last active July 7, 2022 05:04
binary-safe file-to-ram, ram-to-file, in pure bash
#!/usr/bin/env bash
# file-to-ram, ram-to-file, in pure bash
# binary-safe including nulls, no external tools, no sub-shells
# Brian K. White [email protected]
# read file binary to h[] hex pairs
ftoh () {
local -i i= ;local x= LANG=C ;h=()
while IFS= read -d '' -r -n 1 x ;do printf -v h[i++] '%02X' "'$x" ;done <$1
}
@bkw777
bkw777 / binary_read_tty.sh
Last active February 1, 2026 22:25
Read, store, and reproduce binary data, including nulls, in pure bash with no external executables or even subshells.
#!/usr/bin/env bash
# Read binary data, including null bytes, from a serial port,
# in pure bash with no external executables nor even subshells,
# even though it's not possible to store a null in a shell variable.
# Uses globals to avoid forking subshells.
# Example, echo -e "\0\0\0" |read FOO or printf -v FOO '%b' "\0\0\0"
# FOO will not contain any 0x00 bytes.
# Same goes for mapfile/readarray.
@bkw777
bkw777 / bash_sleep.sh
Last active August 6, 2021 22:02
sleep in pure native bash without /usr/bin/sleep and without even subshell
#!/usr/bin/env bash
# sleep without externals or children
# and without the bash sleep builtin
# mkfifo is not exactly free, but you only do this part once.
# After that it is relatively free to call _sleep all you want even in tight loops.
sleep_fifo=/tmp/.${0//\//_}.$$.sleep.fifo
trap "rm -f $sleep_fifo" EXIT
mkfifo $sleep_fifo || { echo "$0: Error creating sleep fifo \"$sleep_fifo\"" >&2 ; exit 1 ; }
exec 9<>$sleep_fifo
@bkw777
bkw777 / urlencode.sh
Last active August 6, 2021 18:24
urlencode urldecode in pure bash as efficient as possible
#!/bin/bash
# urlencode / urldecode in pure bash without externals
# no backticks or forking, all in-memory ops
# urlencode/urldecode the contents of $x, place results back in $x
# allow bash-isms
# [email protected]
urlencx () {
local LANG=C i b t=$x l=${#x} ;x=''
for ((i=0;i<l;i++)); do
@bkw777
bkw777 / mktmpdir.sh
Last active August 6, 2021 21:27
Example to create an exclusive temp/working dir in bash. Based on the atomicity of mkdir.
#!/bin/bash
# create an exclusive temp dir
# allow bash-isms
# [email protected]
# If you don't need to retain the temp files after execution, and you reliably
# clean up on exit with a trap, and you only need to worry about concurrent
# instances, then you can just use $$ cheaper instead of this "until mkdir" loop.
# Comment this out to retain the temp files after execution (logging, debugging)
@bkw777
bkw777 / http_server.sh
Last active March 4, 2024 17:23 — forked from mbbx6spp/server
http server implemented in socat + bash
#!/usr/bin/env bash
# HTTP web service implemented in socat + bash
# Usage: socat -T 1 -d -d tcp-l:8080,reuseaddr,fork,crlf exec:./http_server.sh
# Purpose: Provide an HTTP server that displays the current server date,
# to validate the artifact structure and play with it.
# Note: socat crlf option is translating all our \n to \r\n on output.
http_version="1.0"
declare -a _http_responses=(