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 / 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")))
@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 / 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 / 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
import os
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.qt.manager import QtKernelManager
from IPython.qt.inprocess import QtInProcessKernelManager
from IPython.kernel.zmq.ipkernel import Kernel
from IPython.kernel.inprocess.ipkernel import InProcessKernel
from IPython.lib import guisupport
@stephanh42
stephanh42 / emoji.txt
Created June 5, 2016 20:08
Unicode Emoji symbols
U+1f601 😁
U+1f602 😂
U+1f603 😃
U+1f604 😄
U+1f605 😅
U+1f606 😆
U+1f607 😇
U+1f608 😈
U+1f609 😉
U+1f60a 😊
@stephanh42
stephanh42 / class_extend.py
Created February 10, 2017 19:00
Python class extensions a la Objective-C "categories"
#class extensions a la Objective-C "categories"
#using metaclasses
excluded_methods = frozenset(["__module__", "__qualname__"])
def class_extend(cls):
class Meta(type):
def __new__(self, name, bases, attrs, **kwargs):
for name, value in attrs.items():
if name not in excluded_methods:
@stephanh42
stephanh42 / unicode.vim
Last active June 1, 2017 10:10
Allow Unicode characters to be written in Vim using LaTeX-like abbrev's.
iab AE\ Æ
iab Alpha\ Α
iab Angle\ ⦜
iab Beta\ Β
iab Bumpeq\ ≎
iab Cap\ ⋒
iab Chi\ Χ
iab Colon\ ∷
iab Cup\ ⋓
iab DH\ Ð
"""
Support `fake` binary operator
so we can do
a @f@ b
in addition to (and with the same meaning as):
f(a, b)
"""
import collections.abc
@stephanh42
stephanh42 / compose.py
Created October 26, 2017 11:42
Attempt at efficient funciton composition on Python
from functools import lru_cache
def identity(x):
return x
@lru_cache(None)
def _make_compose(n):
if n == 0:
return lambda: identity
elif n == 1: