Skip to content

Instantly share code, notes, and snippets.

@vrdhn
vrdhn / setup.md
Created February 27, 2024 06:02
Linux laptop setup notes.

Usage Pattern

@vrdhn
vrdhn / hanoi.py
Created April 13, 2023 15:12
hanoi.py
from collections import namedtuple
## Convention
## 4 3 2 1 size discs are stored as [ 4,3,2,1 ]
## name -> string
## discs -> sparse reverse sorted array of number
Peg = namedtuple('Peg', ['name', 'discs'])
Create ssh host <username>-<vmname> for libvirt
#1. Add this to TOP of ~/.ssh/config
Include ~/.ssh/config.d/*
Top means top, specifically, do not add after a Host entry
#2. This bash function:
```bash
vmssh ()
{
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
qemu-img create -f qcow2 arch-root.qcow2 64G
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 arch-root.qcow2
sudo cfdisk -z /dev/nbd0
# make dos partition table
# make a new partition, make it bootable
sudo mkfs.ext4 /dev/nbd0p1
sudo mount /dev/nbd0p1 /mnt/
implementation("org.apache.logging.log4j:log4j-api:2.19.0")
implementation("org.apache.logging.log4j:log4j-core:2.19.0")
private static final Logger LOG = LogManager.getLogger(Main.class);
private static void setLogLevel(Level level) {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
@vrdhn
vrdhn / tmux-run.sh
Created July 7, 2022 12:54
ensure a named windows on tmux exists, and run commands in it.
#!/bin/sh
## tmux-run <window-name> <cmd args ...>
## start if session not running
if [ "x$TMUX" = "x" ] ;
then
tmux new -As0 \; detach-client
fi
@vrdhn
vrdhn / disposable-postgres.sh
Created July 3, 2022 14:13
Disposable postgres installtions for testing .. don't bother with docker etc.
#!/bin/bash
PGDATADIR=pgdata
mkdir -p $PGDATADIR
usage () {
echo "** Disposable postgres installtions for testing **"
echo ""
echo "$0 <cmd> [ args .... ] "
echo " =cmd= =args...="
@vrdhn
vrdhn / this.js
Last active March 21, 2022 11:37
What is this
const root = (typeof window === 'undefined') ? global : window;
function LambdaClosure() {
return () => {
if ( this == root )
console.log('Closure: this is global/window');
else
console.log('Closure: this is ', this.name);
@vrdhn
vrdhn / st.html
Last active March 16, 2022 12:25
Sierpiński triangle
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sierpiński triangle</title>
<link rel="stylesheet" href="style.css">
<script>
document.addEventListener('DOMContentLoaded', (event) => {
const canvas = document.getElementById('canvas');
var ctx = canvas.getContext("2d");