Skip to content

Instantly share code, notes, and snippets.

(defun flesh-to-stone-weight (human-weight)
"Calculate how much a human of HUMAN-WEIGHT pounds would weigh if they were
converted into granite."
(interactive "nHuman weight in pounds: ")
(let* ((human-density 63.1) ; lb/ft^3
(granite-density 168) ; lb/ft^3
(granite-weight (* (/ human-weight human-density) granite-density)))
(message "A human of %f pounds would weigh %f pounds
if converted to granite."
human-weight granite-weight)))
@tkurtbond
tkurtbond / height-mass.el
Last active June 7, 2021 04:48
How much does your giant weigh?
(defun height-mass (start-height start-mass end-height build-ratio)
"How much does your giant weigh?
Calculate from START-HEIGHT, START-MASS, and END-HEIGHT multiplied by
BUILD-RATIO the END-MASS. BUILD-RATIO is a factor to express the difference
in build between different creatures. (The factor for a dwarf might be 2.25,
225% heavier than normal.)
Formula: end-mass = start-mass * (end-height / start-height)^3
See:
https://en.wikipedia.org/wiki/Square%E2%80%93cube_law
https://www.enworld.org/threads/how-much-does-my-giant-weight.106631/post-1846443"
@tkurtbond
tkurtbond / .bashrc_logging
Created July 9, 2021 19:30
bash functions for logging the output of long commands run multiple times
incf () {
# Construct a filename from PREFIX, "_YYYY-MM-DD", optionally _N (where N
# is 1 or greater) if the filename already exists, and optionally SUFFIX.
# Example: "incf file .tar.gz" results in "file_2021-07-07.tar.gz", or
# "file_2021-07-07_N.tar.gz" if "file_2021-07-07.tar.gz" already exists,
# where N is 1 or greater.
local prefix suffix fileprefix i testname sep1 sep2
prefix="$1"
suffix="$2"
sep1="_"
@tkurtbond
tkurtbond / tkb-smart-unicode-mode.el
Last active July 12, 2021 07:10
A small minor mode for easily entering Unicode double and single quotes, em and en dashes, and horizontal ellipses.
;; look at https://github.com/ndw/xmlunicode for xmlunicode.el
;; xmlunicode-character-list.el. xmlunicode.el provides the
;; "smart-unicode-*" functions.
(load-library "unichars")
(load-library "xmlunicode")
(defun tkb-describe-character (before)
"Describe the character after point (before if a prefix was specified)
if it is a unicode character."
(interactive "P")
@tkurtbond
tkurtbond / mod-args.scm
Last active September 13, 2021 22:10
Modify args.scm from the CHICKEN Scheme args egg to not truncate long options and to allow multiple docstrings for multiple lines
;; O is an args:option
(define (usage-line o)
(define (pad-docstring docstring)
(string-append (string-pad "" (+ (args:width) (args:indent)))
docstring "\n"))
(let* ((option-string (commify o))
(docstrings (args:option-docstring o))
(first-docstring (if (string? docstrings) docstrings (car docstrings)))
(rest-docstrings (if (string? docstrings) '() (cdr docstrings)))
(s (string-append
;;;; -*- geiser-scheme-implementation: chicken -*-
;;;; Look at https://wiki.call-cc.org/man/5/Module%20(chicken%20condition)#system-conditions
;;;; for a list of the CHICKEN Scheme system exceptions.
;;;; The original of the example I changed for the gist is in the
;;;; documentation of the module (chicken conditions), which I changed
;;;; to use procedures from the egg condition-utils to find out more
;;;; detail about the error.
(loop for f from -20 to 220
do (let ((c (* (/ 5 9) (- f 32)))
(k (+ 273.15 (* (/ 5 9) (- f 32)))))
(format t "~6,2f℉ ~6,2f℃ ~6,2fK~%" f c k)))
(loop for f from -20 to 220
for c = (* (/ 5 9) (- f 32))
for k = (+ 273.15 (* (/ 5 9) (- f 32)))
do (format t "~6,2f℉ ~6,2f℃ ~6,2fK~%" f c k))
@tkurtbond
tkurtbond / Oberon2_body.atg
Last active May 30, 2022 20:07
Coco/R grammar for Oberon-2, from the body of the Oberon-2 report.
COMPILER Oberon2
CHARACTERS
letter = 'A' .. 'Z' + 'a' .. 'z'.
digit = "0123456789".
hexDigit = digit + 'A' .. 'F'.
sqChar = ANY - '"'.
dqChar = ANY - "'".
TOKENS
@tkurtbond
tkurtbond / Oberon2_app_b.atg
Last active June 3, 2022 14:31
Coco/R grammar for Oberon-2, from Appendix B of the Oberon-2 report.
COMPILER Oberon2_app_b
CHARACTERS
letter = 'A' .. 'Z' + 'a' .. 'z'.
digit = "0123456789".
hexDigit = digit + 'A' .. 'F'.
sqChar = ANY - '"'.
dqChar = ANY - "'".
TOKENS
@tkurtbond
tkurtbond / sort-versions
Last active June 9, 2022 18:13
Sort semantic versions, with things like .rc1, .rc2, .rc11 ending up in the right places.
#! /usr/bin/env bash
# sort-versions -- Sort semantic versions, with things like .rc1, .rc2, .rc11 ending up in the right places.
REVERSE=''
let errors=0
while getopts "?hr" opt
do
case "$opt" in
(\?|h) let errors++ ;;