Skip to content

Instantly share code, notes, and snippets.

View jackmott's full-sized avatar

Jack Mott jackmott

  • Olo
  • Texas,USA
View GitHub Profile
@jackmott
jackmott / main.rs
Last active September 9, 2019 01:57
chunk noise example
use minifb::{Key, Window, WindowOptions};
use simdnoise::NoiseBuilder;
use std::{thread, time};
const WIDTH: usize = 640;
const HEIGHT: usize = 640;
fn main() {
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
@jackmott
jackmott / duconverter
Created March 7, 2019 22:11
newtonsoft json DU converter
namespace AlphaFront
module JsonCustomConverters =
open Newtonsoft.Json
open Microsoft.FSharp.Reflection
open System
open System.IO
type DuConverter() =
inherit JsonConverter()
@jackmott
jackmott / pqueue.cs
Created February 3, 2019 22:53
priority queue in c#
using System.Collections.Generic;
using System.Linq;
namespace FB
{
public class PQueue<T>
{
private SortedDictionary<float, Stack<T>> sdict;
@jackmott
jackmott / keybase.md
Created January 16, 2019 16:15
keybase

Keybase proof

I hereby claim:

  • I am jackmott on github.
  • I am jackmott (https://keybase.io/jackmott) on keybase.
  • I have a public key whose fingerprint is DE51 EA3B 8EFA E93E 229C C013 2C5A AAC6 CAD9 92F8

To claim this, I am signing this object:

@jackmott
jackmott / thread.cs
Created January 10, 2019 15:05
What could be thread unsafe about this?
// When this function runs in my program on multiple threads, memory corruption eventually happens
// When it doesn't run, or runs on only 1 thread, no problems
// I can't see what could be thread unsafe about it, am I missing something?
public static float SingleCellular2EdgeSimple(float x, float y, float jitter, int seed)
{
int xr = (x >= 0) ? (int)(x + 0.5f) : (int)(x - 0.5f);
int yr = (y >= 0) ? (int)(y + 0.5f) : (int)(y - 0.5f);
float[] distance = { 999999f, 999999f, 999999f, 999999f };
@jackmott
jackmott / ast.fs
Created December 17, 2018 20:45
AST Cleaned Up
open System
type ASTNode =
| Add of (ASTNode * ASTNode)
| Sub of (ASTNode * ASTNode)
| X
| Constant of int
let rec Evaluate node x =
match node with
@jackmott
jackmott / ConstantFold.fs
Created December 17, 2018 20:28
ConstantFolding
let rec ConstantFolding node =
match node with
| Add (l,r) -> match (ConstantFolding(l),ConstantFolding(r)) with
| (Constant v1,Constant v2) -> Constant(v1+v2)
| (optL,optR) -> Add(optL,optR)
| Sub(l,r) -> match (ConstantFolding(l),ConstantFolding(r)) with
| (Constant v1,Constant v2) -> Constant(v1-v2)
| (optL,optR) -> Sub(optL,optR)
| X -> X
| Constant v -> Constant(v)
@jackmott
jackmott / add.c
Last active November 30, 2018 15:26
add
// Got a minute to revisit this question this morning and cleaned it up a lot
// - Jack
#define MAX(a,b) (((a)>(b))?(a):(b))
int ctoi(char c){
return (int)(c - '0');
}
char itoc(int i){
@jackmott
jackmott / wordwrap.cs
Last active November 11, 2018 20:44
word wrap for monogame
public static string Wrap(string s, int width, Func<string, int> widthMeasure)
{
StringBuilder builder = new StringBuilder(s.Length);
var text = s.AsSpan();
int start = 0;
int len = 0;
for (int i = 0; i < text.Length; i++) {
if (text[i] == ' ')
{
@jackmott
jackmott / pqeueu.cs
Created September 29, 2018 00:14
pqueue
using System.Collections.Generic;
using System.Linq;
namespace FB
{
public class PQueue<T>
{
private SortedDictionary<float, Stack<T>> sdict;