Skip to content

Instantly share code, notes, and snippets.

Avatar
🔨
Workin on Halo stuff!

Connor Sauve csauve

🔨
Workin on Halo stuff!
View GitHub Profile
@csauve
csauve / gen-yaml.js
Created May 11, 2020
BREAK GLASS IF NEW C20 YAML FILES NEEDED
View gen-yaml.js
function buildYamlFiles(invaderStructDefs, basicTags) {
const describeStruct = (invaderStructName, name) => {
const struct = invaderStructDefs[invaderStructName];
if (!struct) {
return {
...(name && {name}),
md: "...",
};
} else if (struct.type == "enum") {
return {
@csauve
csauve / trimbytes.groovy
Created Oct 1, 2019
Safely trims a String to a max length of bytes in a desired encoding without cutting multi-byte characters in half.
View trimbytes.groovy
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 Mar 10, 2019
Plots win rates for optimal play of a randomly generated graph-based game
View graph-game.js
/* 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], [])
View borrow-error.rs
// 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 Jun 21, 2018
List line contributions to all git repos in CWD
View git-lines.sh
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
View build-minimal-jre.sh
#!/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 \
View lunch-n-ramda.md

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 Sep 12, 2017
Visualize inscribed lines in jordan curves
View jordan-curves.html
<!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; }
View stack-machine.js
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 / unicode-hide.js
Created Nov 6, 2015
Given some ASCII input text, encodes it in the free codepoint bits of 3-byte unicode characters. Result is fewer characters but more bytes.
View unicode-hide.js
var TextEncoder = require("text-encoding").TextEncoder;
var TextDecoder = require("text-encoding").TextDecoder;
var jsSource = "";
process.stdin.resume();
process.stdin.on("data", function(buf) {
jsSource += buf.toString();
});
process.stdin.on("end", function() {
You can’t perform that action at this time.