Skip to content

Instantly share code, notes, and snippets.

@SeijiEmery
SeijiEmery / ackerman.txt
Last active November 9, 2021 11:45
ackerman function
ack(x, y) =
(x == 0) ? (y + 1) :
(y == 0) ? ack(x - 1, 1) :
ack(x - 1, ack(x, y - 1));
X
| 0 1 2 3 4 5 6 7 8 9
--+--------------------------------------
Y 0 | 1 2 3
1 | 2 3 5
2 | 3 4 7
@SeijiEmery
SeijiEmery / example.py
Last active June 2, 2021 06:46
format c text blocks
corpus = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae suscipit lectus. Nam faucibus non risus iaculis mattis. Suspendisse ligula massa, porta nec euismod vel, gravida non nisi. Mauris sit amet pulvinar odio, in pharetra dolor. Curabitur non nisi eu nisi cursus elementum nec eget diam. Praesent aliquet vehicula enim eu malesuada. Fusce euismod dolor nec lorem ultricies, ut maximus neque luctus. Maecenas sed augue pretium, condimentum elit eu, feugiat diam.
Nam at est nulla. Vestibulum ac lacus dolor. Morbi ultricies metus diam, et maximus justo rutrum interdum. Suspendisse non metus vitae nulla condimentum eleifend eu a ante. Aenean a ex dui. Sed tempus turpis eu ipsum facilisis, eu ultrices enim condimentum. Vestibulum vehicula est sem, at accumsan leo cursus ac. Pellentesque neque sem, posuere vitae mi eget, convallis convallis augue. Duis vestibulum cursus purus facilisis lacinia. Praesent blandit felis urna, eget suscipit diam rhoncus et. Nam lorem libero, luctus rhoncus posue
@SeijiEmery
SeijiEmery / encoder.py
Last active August 10, 2020 22:35
variable length encoding
'''
data-driven variable length encoder :)
(started as a toy program to encode / decode morse code;
extended to cover any variable-length encodings, and works provided that all
encodings are 1-1, ie. bidirectionally unambiguous, which this encoder assumes
but does not check for)
'''
from utils import fmt_or, ignore_errors
@SeijiEmery
SeijiEmery / collision_tests.d
Last active July 23, 2020 20:16
fast sphere collision tests w/ 128bit simd
/// fast sphere collision checks w/ 128-bit SIMD
/// (d pseudocode; all these intrinsics -should- exist, however,
/// and ofc neon_check_sphere_collision could just be written
/// in armv8 assembly or whatever)
float dist2 (vec3 a, vec3 b) {
return (a - b).dot;
}
float dot (vec3 a) {
return a.x + a.y + a.z;
@SeijiEmery
SeijiEmery / 1 sample output.txt
Last active April 4, 2020 23:35
quick script to inspect unity .shadergraph files, prints out properties, and generates c# scripts wrapping shader properties
loading shader from ./CelShader.shadergraph
Shader CelShader
8 properties:
12412bf8-f58a-4b6f-8bc7-646cc224bb3a
name: Color
ref name: Color_F30DBC55
type: UnityEditor.ShaderGraph.Internal.ColorShaderProperty
04e2ae53-6ac2-4fad-9c9b-da81279a109b
name: MainTex
ref name: Texture2D_B604EE98
@SeijiEmery
SeijiEmery / clean_meta_files.py
Created February 8, 2020 14:09
Utility script: prints out non-file-associated meta files in a given unity directory, with the git command to remove them
import os
import sys
if __name__ == '__main__':
if len(sys.argv) > 1:
os.chdir(sys.argv[1])
target_dir = './Assets'
dir_meta_files = set([
@SeijiEmery
SeijiEmery / high_level_game_lang.txt
Last active November 5, 2019 20:10
Ideas for a high level game lang
num is pub type where
// static properties (ie. <numtype>.zero, etc)
zero: pub value num
one: pub value num
min: pub value option<num>
max: pub value option<num>
inf: optional pub value option<num>
nan: optional pub value
@SeijiEmery
SeijiEmery / stepping_while.cpp
Last active May 19, 2019 00:22
While toy lang, implemented (stepping version) using c++ template metaprogramming
/// Our reduce 'function' (eval-one-step)
/// reduce :: AST -> State -> { Result :: AST, State :: State }
template <typename AST, typename State>
struct reduce;
/// class AST where
/// print :: IO ()
/// reduce :: AST -> State -> { Result :: AST, State :: State }
///
@SeijiEmery
SeijiEmery / 0 pi.py
Last active April 12, 2019 08:03
BBP Pi
# https://en.wikipedia.org/wiki/Bailey–Borwein–Plouffe_formula
# generalize term summation
P = lambda terms: lambda k: 1 / 16 ** k * sum([
a / (8 * k + b) for a, b in terms
])
# bbp function (for one term, at k)
bbp = P(((4, 1), (-2, 4), (-1, 5), (-1, 6)))
# https://en.wikipedia.org/wiki/Bailey–Borwein–Plouffe_formula#BBP_compared_to_other_methods_of_computing_π
# generalize term summation
P = lambda terms: lambda k: 1 / 16 ** k * sum([
a / (8 * k + b) for a, b in terms
])
# bbp function (for one term, at k)
bbp = P(((4, 1), (-2, 4), (-1, 5), (-1, 6)))