Skip to content

Instantly share code, notes, and snippets.

View csauve's full-sized avatar
⌨️
doot doot

Connor Sauve csauve

⌨️
doot doot
View GitHub Profile
@csauve
csauve / thing_convert.py
Created July 22, 2022 16:47
The Thing (2002) msh to obj converter
import struct
import sys
verts_start = 0xA4
vert_count = 0x2B
vert_format = "<I 3f 3f 2f"
vert_size = struct.calcsize(vert_format)
indices_start = 0x6B8
indices_count = 0x84
@csauve
csauve / gen-yaml.js
Created May 11, 2020 06:14
BREAK GLASS IF NEW C20 YAML FILES NEEDED
function buildYamlFiles(invaderStructDefs, basicTags) {
const describeStruct = (invaderStructName, name) => {
const struct = invaderStructDefs[invaderStructName];
if (!struct) {
return {
...(name && {name}),
md: "...",
};
} else if (struct.type == "enum") {
return {
const R = require("ramda");
//state operations
const updStack = R.curry((prop, updater, state) => R.over(R.lensProp(prop), updater, state));
const updCall = (stackOp) => updStack("callStack", stackOp);
const updData = (stackOp) => updStack("dataStack", stackOp);
//stack operations
const pop = R.curry((num, stack) => {
if (stack.length < num) throw new Error("Stack underflow!");
@csauve
csauve / trimbytes.groovy
Created October 1, 2019 22:52
Safely trims a String to a max length of bytes in a desired encoding without cutting multi-byte characters in half.
static String trimBytes(String input, int lengthBytes, Charset charset) {
if (input == null) return null
if (input.getBytes(charset).length <= lengthBytes) return input
def bytes = charset.encode(input)
bytes.limit(Math.min(lengthBytes, bytes.limit()))
def chars = charset.newDecoder()
.onMalformedInput(CodingErrorAction.IGNORE)
.onUnmappableCharacter(CodingErrorAction.IGNORE)
.decode(bytes)
@csauve
csauve / graph-game.js
Last active March 10, 2019 07:19
Plots win rates for optimal play of a randomly generated graph-based game
/* In this game, alice and bob take turns removing any vertex of nonzero even
* degree from an undirected graph, which also removes all connected edges.
* The winner is the last player able to do so.
*/
//compactify vertex indices to improve memoization cache hit rates
function simplify(edges) {
const mappings = edges
.flat()
.reduce((uniq, v) => uniq.includes(v) ? uniq : [...uniq, v], [])
// error[E0502]: cannot borrow `window` as mutable because it is also borrowed as immutable
// --> src/main.rs:14:9
// |
// 14 | window.poll(|event| {
// | ^ ---- ------- immutable borrow occurs here
// | | |
// | _________| immutable borrow used by call, in later iteration of loop
// | |
// 15 | | match event {
// 16 | | WindowEvent::Close => {
@csauve
csauve / git-lines.sh
Created June 21, 2018 22:18
List line contributions to all git repos in CWD
for d in ./*/ ; do (cd "$d" && git log --author="<name here>" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -); done
#!/bin/sh
set -ex
mkdir -p /opt/jdk
tar zxvf jdk.tar.gz -C /opt/jdk --strip-components=1
rm jdk.tar.gz
rm /opt/jdk/lib/src.zip
/opt/jdk/bin/jlink \
--module-path /opt/jdk/jmods \

Functional JS & Ramda


What is functional JS?

JavaScript is a multi-paradigm language, supporting imperative, object-oriented, and functional styles. This presentation is intended to add some tools to your toolbelt. With familiarity of its patterns, functional JS can be very expressive. These patterns often follow from JS best practices:

  • Don't extend Array.prototype or Object.prototype with nonstandard functionality; use utility functions
  • Avoid shared or global state
  • Prefer pure functions without side-effects
@csauve
csauve / jordan-curves.html
Created September 12, 2017 07:39
Visualize inscribed lines in jordan curves
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jordan Curve Inscribed Lines</title>
<style>
body { font-family: monospace; }
.canvas-section { display: inline-block; }
canvas { border: 1px solid black; }