Skip to content

Instantly share code, notes, and snippets.

View serialhex's full-sized avatar
😸
Pondering language design...

serialhex

😸
Pondering language design...
View GitHub Profile
@serialhex
serialhex / normal-random.lisp
Last active September 14, 2022 15:51
Generate normal (gaussian) random numbers in lisp!
(defun normal-random (mean std-dev)
"Normal random numbers, with the given mean & standard deviation."
(do* ((rand-u (* 2 (- 0.5 (random 1.0))) (* 2 (- 0.5 (random 1.0))))
(rand-v (* 2 (- 0.5 (random 1.0))) (* 2 (- 0.5 (random 1.0))))
(rand-s (+ (* rand-u rand-u) (* rand-v rand-v))
(+ (* rand-u rand-u) (* rand-v rand-v))))
((not (or (= 0 rand-s) (>= rand-s 1)))
(+ mean
(* std-dev
(* rand-u (sqrt (/ (* -2.0 (log rand-s)) rand-s))))))))
@serialhex
serialhex / containers.md
Last active December 2, 2021 19:44
My Views on Containers

My Thoughts on Containers, Containerization and Virtual Machines in general

I am writing this to express my thoughts on containers in general. I have briefly stated my surface-thoughts on them to a few people, and because it is difficult to articulate all of my thoughts at once to someone, I thought I would write a blog-post / article thing. First of all, all the opinions expressed here are mine and mine alone. There is a good chance nobody else in the world has these same thoughts, so I am alone. I'm fine with that though, as it makes me unique.

Containers are Virtual Machines

Yes. Full stop. They are. I don't care if you say they are "small" virtual machines. They are none the less, a virtual machine. From [Wikipedia, Virtual Machine]:

In computing, a virtual machine (VM) is the virtualization/emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized hardware, softwar

@serialhex
serialhex / derpyhash.c
Last active August 18, 2021 17:07
some fibonacci hash functions. 64 and 32 bit.
// this runs nicely on SMHasher
// fails a few tests, but overall is fast and passes most tests
size_t derpy_hash(const char *key, int len, uint32_t seed) {
const uint64_t *data = (const uint64_t *)key;
const uint64_t fib = 11400714819323198485llu;
// 8 bytes in a 64-bit value, so take the last 7 bits
uint8_t m = len & 7;
// initialize
@serialhex
serialhex / Makefile
Created October 12, 2016 15:00
Makefiles on Windows!!!
#define macros
EXE = executable.exe
SRC = src
BIN = bin
INT = obj
INCL = include
OCV_INC = "$(OPENCV_DIR)\..\..\include"
OCV_LIB = "$(OPENCV_DIR)\lib\opencv_world310.lib"
@serialhex
serialhex / dprism.html
Created January 3, 2020 16:37
A Damage per Round calculator for use in comparing the relative strengths of different Pathfinder 2e characters.
<!DOCTYPE html>
<html lang="en-US">
<!--
Copyright 2020 serialhex <serialhex@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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@serialhex
serialhex / struct-slots.lisp
Last active August 12, 2018 11:11
Get slots from a random struct. Can you do that in (Objective-)C(++|#)???
(defun struct-slots (struct)
"Quick & dirty hack to get the slot names of a given struct"
(let ((data (cdr (read-from-string (string-left-trim "#S" (format nil "~S" struct))))))
(labels ((pull-slot (s k)
(if s
(pull-slot (cddr s) (cons (car s) k))
k)))
(pull-slot data nil))))
;; it's not the prettiest/most efficient code, but it works!
@serialhex
serialhex / note.md
Created June 9, 2012 18:05
GRC's UHE PRNG Ultra-High Entropy Pseudo-Random Number Generator.

I did not write this software; Gibson Research did. Sounds like it's pretty spiffy!

param (
[string]$src = ".",
[string]$dst = ".\reencode"
)
# Add-Type -AssemblyName System.Windows.Forms
function time($block) {
$sw = [Diagnostics.Stopwatch]::StartNew()
defmodule Foobot.Repo do
# use JSON and some awesomesauce to make a database of sorts.
# in-memory it will be just a map...
# on disk JSON
# reads simply read all the data, writes do the write & also write
# a copy to disk
require Logger
@repo :repo_registry
@serialhex
serialhex / cond-<>.lisp
Last active May 18, 2017 16:39
A Common Lisp macro that threads a value through a handful of forms, updating that value if the predicate returns true.
;; from On Lisp
(defun single (lst)
(and (consp lst) (not (cdr lst))))
(defmacro cond-<> (data &body body)
"A combination of this: https://clojuredocs.org/clojure.core/cond-%3E
and this: https://github.com/rplevy/swiss-arrows#a-generalization-of-the-arrow
returns last value of <>"
(let ((<> (intern "<>")))
`(let ((<> ,data))