i'm writing another lil cube thing. if you've ever written a rubik's cube simulator/solver, you will know that some parts can be more akin to data than to code. one way or another, you always end up with lots and lots of tables to select the right pieces and move them to the right places. if good code reads like poetry and bad code reads like a phonebook, this is always easily in the top 10 most mind-numbingly boring programs of all time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sed 'sentence;secede;secede' <<< canter # canter -> cancer -> dancer -> dander | |
sed 'severe;serene;secede' <<< cove # cove -> core -> cone -> done | |
sed 'septette;settee' <<< Capt # Capt -> Catt -> Ca | |
sed 'severe;serene' <<< Iva # Iva -> Ira -> Ina | |
sed 'severe;serene' <<< paves # paves -> pares -> panes | |
sed 'secrete;settee' <<< critter # critter -> titter -> tier | |
sed 'severe;serene' <<< v # v -> r -> n | |
sed 'severe;serene' <<< coves # coves -> cores -> cones | |
sed 'severe;serene' <<< vapes # vapes -> rapes -> napes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | |
/sent/ { stot += sent[s++] = $2 } | |
/recv/ { rtot += recv[r++] = $2 } | |
END { | |
if (r != s) | |
printf "error: s=%d r=%d\n", s, r | |
for (i in sent) | |
if (sent[i] < recv[i]) | |
printf "error: sent[%d]=%d recv[%d]=%d\n", i, sent[i], i, recv[i] | |
printf "sent=%'d avg=%'d\n", stot, stot/s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage () { | |
cat << 'eof' | |
bgcmd manages a long running, interactive command in background | |
usage: | |
bgcmd START command [args...] # starts a command in background |
namerefs (introduced in bash 4.0) act as aliases for other variables
var=meow
declare -n ref=var
echo $ref # prints meow
ref=moo
echo $var # prints moo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if 0 | |
#define _XOPEN_SOURCE 700 | |
#include <aio.h> | |
#include <arpa/inet.h> | |
#include <assert.h> | |
#include <_Complex.h> | |
#include <ctype.h> | |
#include <dirent.h> | |
#include <dlfcn.h> | |
#include <errno.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -f | |
IFS= | |
rpn () { | |
for token do | |
case $token in | |
+|-|\*|/|%|\*\*) (( stack[-2] = stack[-2] $token stack[-1] )); unset stack[-1] ;; | |
=) (( ${stack[-2]} = stack[-1] )); unset stack[-1] stack[-1] ;; | |
*) stack+=($token) ;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <arpa/inet.h> | |
#include <errno.h> | |
#include <netinet/in.h> | |
#include <pty.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <sys/socket.h> | |
#include <sys/wait.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pi=205667 | |
scale=65536 | |
maskf0=-$scale | |
mask0f=$((scale-1)) | |
shift=16 | |
pisq=42389628127 | |
pi2=411775 | |
pi_2=102944 | |
pi_4=51472 |
for the latest chapter of what's becoming a blog on the most cursed bash you can imagine, let's do some maths together
euclid's algorithm for gcd could be written like this in python:
>>> def gcd(a, b):
... if b:
... return gcd(b, a%b)
... return a
NewerOlder