Skip to content

Instantly share code, notes, and snippets.

@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++ ;;
;; A space invaders game in Racket
;; Copyright (c) 2020 Alex Harsányi (AlexHarsanyi@gmail.com)
;; Permission is hereby granted, free of charge, to any person obtaining a
;; copy of this software and associated documentation files (the "Software"),
;; to deal in the Software without restriction, including without limitation
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;; and/or sell copies of the Software, and to permit persons to whom the
;; Software is furnished to do so, subject to the following conditions:
@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"
@alex-hhh
alex-hhh / tetris-4.rkt
Last active November 22, 2023 17:15
Tetris Game, Final Version
;; A tetris game -- partial implementation, part 4
;; Copyright (c) 2020 Alex Harsányi (AlexHarsanyi@gmail.com)
;; Permission is hereby granted, free of charge, to any person obtaining a
;; copy of this software and associated documentation files (the "Software"),
;; to deal in the Software without restriction, including without limitation
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;; and/or sell copies of the Software, and to permit persons to whom the
;; Software is furnished to do so, subject to the following conditions:
@joepie91
joepie91 / random.md
Last active May 19, 2024 18:16
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@brechtm
brechtm / diffpdf.sh
Last active May 17, 2024 15:56
Page-by-page PDF diff tool
#!/bin/bash
# usage: diffpdf.sh file_1.pdf file_2.pdf
# requirements:
# - ImageMagick
# - Poppler's pdftoppm and pdfinfo tools (works with 0.18.4 and 0.41.0,
# fails with 0.42.0)
# (could be replaced with Ghostscript if speed is
# not important - see commented commands below)
@colinvh
colinvh / aws.md
Last active May 8, 2024 15:31
AWS Region Names

Alternative naming schemes for AWS regions

Purpose

The intent is to define terse, standards-supported names for AWS regions.

Schemes

(ql:quickload "cl-ppcre")
(ql:quickload "anaphora")
(defpackage :ini-parser
(:use :common-lisp :anaphora)
(:export :read-config-from-file))
(in-package :ini-parser)
(defparameter +empty-line+ (format nil "~%"))
@fogus
fogus / foo.lisp
Created September 11, 2012 12:31
Guy Steele's FOO language
;; Guy Steele's "FOO" language, as found on the ll1.mit.edu mailing list.
;; ----------------------------------------------------------------------
;; [He said..]
;; If you speak Common Lisp, you might find the following
;; bit of code illuminating. (If you speak Scheme but
;; not Common Lisp, then just delete or ignore all occurrences
;; of the strings "funcall " and "#'").