Skip to content

Instantly share code, notes, and snippets.

View jcdickinson's full-sized avatar
🐵

Jonathan Dickinson jcdickinson

🐵
View GitHub Profile
@jcdickinson
jcdickinson / colorblind.glsl
Last active April 28, 2024 23:27
Colorblind Simulation Shader
/*-----------------------------------------------------------.
/ ColorBlind correction /
'-----------------------------------------------------------*/
// Daltonize (source http://www.daltonize.org/search/label/Daltonize)
// Modified to simulate color blindness.
float4 Daltonize( float4 input, float2 tex )
{
// RGB to LMS matrix conversion
float3 L = (17.8824f * input.r) + (43.5161f * input.g) + (4.11935f * input.b);
float3 M = (3.45565f * input.r) + (27.1554f * input.g) + (3.86714f * input.b);
// Example
State {
x
cond
}
local a = state.x + 1
text a
@jcdickinson
jcdickinson / Parse.cpp
Created October 4, 2018 05:55
hextoint
// Does not reject invalid data. define NO_OVERFLOW to avoid values
// larger than 15, but it will still accept invalid characters.
// MSN(x) = Most-significant nibble
// LSN(x) = Least-significant nibble
// SHL(x, y) = Shift left
// SHR(x, y) = Shift right
// MSN(Digits) = 0011
// MSN(Upper) = 0100
@jcdickinson
jcdickinson / ProcNumberGenerator.cs
Created May 31, 2012 15:15
Proc Number Generator
/// <summary>
/// Represents a way to manage random events that should
/// occur a certain percentage of the time.
/// </summary>
/// <remarks>
/// This generator will correct unfair samples; for example, if it is set up
/// with a 50% chance to proc and 5 nonprocs are sampled; there is a good
/// chance that the next 5 samples will proc.
/// </remarks>
public class ProcNumberGenerator
@jcdickinson
jcdickinson / workstealingstack.h
Last active March 26, 2023 04:15
C++ Lock-Free Work Stealing Stack
#pragma once
#include <atomic>
// A lock-free stack.
// Push = single producer
// Pop = single consumer (same thread as push)
// Steal = multiple consumer
// All methods, including Push, may fail. Re-issue the request
// if that occurs (spinwait).
@jcdickinson
jcdickinson / fix-aoe4.sh
Last active August 3, 2022 21:51
AOE4 Desync Fix
#!/usr/bin/env bash
set -e
STEAM_DIR=$HOME/.steam/steam/steamapps
if [ ! -e "$STEAM_DIR" ]; then
# Possibly flatpak
STEAM_DIR=/var/home/$USER/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps
fi
@jcdickinson
jcdickinson / Shadows.fx
Created April 14, 2012 12:28
Shadows HLSL
uniform extern texture Texture : TXSOURCE;
uniform extern texture ShadowMapTexture : TXSHADOWMAP;
uniform extern float2 RenderTargetSize : SZRT;
sampler inputSampler = sampler_state
{
Texture = <Texture>;
MipFilter = Point;
MinFilter = Linear;
MagFilter = Linear;
@jcdickinson
jcdickinson / readme.md
Last active May 4, 2022 22:14
Templates in C

Based on an idea by Andread Arnold-Bos. Instead of having two files the template instantiations are done within the same file as the template.

@jcdickinson
jcdickinson / Dimension.cs
Created December 29, 2011 15:01
Pattern Tree
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Patterns
{
/// <summary>
/// Represents an array dimension.
/// </summary>
@jcdickinson
jcdickinson / machine.js
Last active July 2, 2021 00:58
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
initial: "dragging",
context: {},
entry: "log",
states: {
dragging: {
on: {
pointerup: "drop",
pointermove: {