Skip to content

Instantly share code, notes, and snippets.

@thejohnfreeman
thejohnfreeman / kill.md
Last active August 23, 2023 12:10
sudo kill

I've got the script below. after running this script, my terminal is broken. my input is not echoed to me, though it is read. I can still run commands. output from commands to stdout is broken: newlines are replaced with long sequences of spaces, so all output is on one very long line. I can use the reset command to fix the terminal.

if I change the SIGKILL to SIGTERM, it is fine. I know that SIGKILL doesn't give the program a chance to shutdown gracefully, but what exactly is going on? what important part of the graceful shutdown is missing that ends up breaking the terminal?

if I remove sudo from the kill command, the same breakage happens. if I remove sudo and change the signal to SIGTERM, then the script hangs on the wait command until the first command exits (presumably the SIGTERM was delivered and ignored).

#!/usr/bin/env bash
sudo sleep 3 >/dev/null 2>&1 </dev/null &
pid=$!
@thejohnfreeman
thejohnfreeman / 01-sudo.sh
Last active August 23, 2023 12:07
terminate background sudo
#!/usr/bin/env bash
psudo() {
sudo --validate
dir=$(mktemp -d)
mkfifo ${dir}/pipe
sudo sh -c "echo \$\$ >${dir}/pipe; exec $*" &
pid=$(cat ${dir}/pipe)
rm -rf ${dir}
}
npm start &
# echo sleep 100 | bash &
pid=$!
gid=$(echo $(ps -o pgid= $pid))
ps -jH -$gid
kill -SIGKILL $pid
ps -jH -$gid
kill -SIGTERM -$gid
reset
@thejohnfreeman
thejohnfreeman / instructions.md
Last active January 5, 2023 02:15
Semantic UI fonts with Webpack in a Chrome extension

To get Semantic UI fonts working:

  1. npm install semantic-ui-css

  2. Import 'semantic-ui-css/semantic.css' in your entry script. The exact syntax for this varies depending on your chosen module format: import for ES6, require for CommonJS, etc. This tells Webpack to pull the CSS into your bundle.

  3. npm install --save-dev style-loader css-loader

secp256k1 is just one popular curve for the Elliptic Curve Digital Signature algorithm (ECDSA).
An ECDSA key is a 256-bit value.
ECDSA will sign a 256-bit value.
If you want to sign a message of arbitrary length, it is customary to first hash the message to a 256-bit value.
One popular hash is SHA-256, but the one XRPL uses is "SHA-512 Half" (SHA-512 truncated to the first half, which is 256 bits).
ECDSA returns a point on a plane, whose coordinates are commonly named `r` and `s`.
Distinguished Encoding Rules (DER) is a popular encoding of a structure called Abstract Syntax Notation One (ASN.1).
ASN.1 can represent types like integers, sequences, and sets.
DER encodes these values to tag-length-value byte sequences.
ECDSA signatures (`r` and `s`) are customarily encoded with DER.
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MTd
compiler.version=17
os=Windows
os_build=Windows
@thejohnfreeman
thejohnfreeman / Dockerfile
Last active February 12, 2022 10:47
Trying to install anything from Visual Studio in a Docker container
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
# Use the latest release channel.
ADD https://aka.ms/vs/16/release/channel C:\TEMP\VisualStudio.chman
# Download the Visual Studio Build Tools bootstrapper.
ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
# Download the Visual Studio Community bootstrapper.
ADD https://aka.ms/vs/16/release/vs_community.exe C:\TEMP\vs_community.exe
semi = false
singleQuote = true
trailingComma = "all"
import asyncio
async def message(delay):
await asyncio.sleep(delay)
print(delay, flush=True)
async def main():
task = asyncio.create_task(message(2))
await message(1)

My last post covered the importance of supplying a RAII type for every pair of balanced functions in an API. Is it possible to write a reusable generic type that can implement that pattern for developers?

We might imagine a type that calls the start function in its constructor and the stop function in its destructor. The constructor would be parameterized by the start and stop functions; let them be callable objects in the general case. The start callable object would not be needed after the constructor returns, and honestly, maybe it shouldn't be passed to the constructor. Maybe the caller of the constructor should be responsible for calling the start function first, and then just constructing the gener

For this technique, we could write a generic type, call it Stopper, that calls an arbitrary function in its destructor.