Skip to content

Instantly share code, notes, and snippets.

View stephanh42's full-sized avatar

Stephan Houben stephanh42

  • Heythuysen, The Netherlands
View GitHub Profile
@stephanh42
stephanh42 / stddev.fs
Created October 29, 2014 19:24
Computing mean and population standard deviation in Forth.
\ Computing mean and population standard deviation in Forth.
\ Tested on Gforth 0.7.0
16 constant FRAC \ number of bits behind fixed-point
\ convert from/to fixed point representation
: s>fix FRAC lshift ;
: fix>s FRAC rshift ;
\ fixed-point arithmetic
@stephanh42
stephanh42 / hexutil.py
Last active July 12, 2022 17:02
Utility functions for hex grids, in Python 3.
"""
Utility functions for hex grids.
"""
from math import sqrt
from heapq import heappush, heappop
import numpy
import numpy.random
neighbours = numpy.array(((2, 0), (1, 1), (-1, 1), (-2, 0), (-1, -1), (1, -1)))
@stephanh42
stephanh42 / libscratch.scala
Created July 18, 2013 19:50
A collection of small utility functions to scratch some common itches.
package libscratch
object `package` {
def floorDiv(p : Int, q : Int) : Int =
if (p < 0) {
if (q < 0) {
p / q
} else {
(p - q + 1) / q
@stephanh42
stephanh42 / collision-detection.rkt
Created November 28, 2012 19:14 — forked from jbclements/collision-detection.rkt
Unbelievably primitive image detection for 2htdp/image
#lang racket
(require 2htdp/image
(only-in mred make-bitmap bitmap-dc%)
(only-in 2htdp/private/image-more render-image)
rackunit)
(define star1 (star-polygon 40 5 2 "solid" "seagreen"))
(define star2 (rotate 20 (star-polygon 40 5 2 "solid" "seagreen")))