Skip to content

Instantly share code, notes, and snippets.

pub trait Parser<'a,I:?Sized> {
type O;
fn parse(&self, ctx: &Context<'a,I>, src: &mut &'a [u8]) -> Option<Self::O>;
}
@hclarke
hclarke / Swizzle.cs
Last active December 19, 2019 02:41
swizzle operators for unity
using UnityEngine;
public static class Swizzle {
public static Vector2 xx(this Vector2 v) {
return new Vector2(v.x, v.x);
}
public static Vector2 xy(this Vector2 v) {
return new Vector2(v.x, v.y);
}
public static Vector2 yx(this Vector2 v) {
@hclarke
hclarke / recursive_sequences_audio.c
Created November 13, 2017 00:03
making audio from recursive sequences
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <math.h>
void putu32(FILE* f, uint32_t x) {
for(int i = 0; i < 4; ++i) {
putc(x&0xFF, f);
#include <iostream>
#include <math.h>
#if ( (defined(__MACH__)) && (defined(__APPLE__)) )
#include <stdlib.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
#else
#include <stdlib.h>
#include <GL/glew.h>
#include <iostream>
#include <math.h>
#if ( (defined(__MACH__)) && (defined(__APPLE__)) )
#include <stdlib.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
#else
#include <stdlib.h>
#include <GL/glew.h>
protected delegate State State(bool? prev);
protected readonly State PASS = x => PASS;
protected readonly State FAIL = x => FAIL;
protected readonly State TICK = x => TICK;
Stack<State> stateStack = new Stack<State>();
protected abstract State GetBaseState(); //put your behaviour here
protected void Update() {
bool? prev = null;
if(stateStack.Count == 0) stateStack.Push(GetBaseState());
@hclarke
hclarke / NFA.rs
Created March 5, 2017 18:50
nondeterministic finite automata implementation
#![allow(dead_code)]
use std::collections::{HashMap,HashSet};
struct NFA {
state_count : usize, //0 is start state, -1 is accept
alphabet : HashMap<char, HashMap<i64, HashSet<i64>>>,
empty_transitions : HashMap<i64, HashSet<i64>>,
}
@hclarke
hclarke / Swizzle.cs
Created September 8, 2016 15:13
Swizzle extension methods for Unity
/*
Copyright (c) 2016 Harrison Clarke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE U
@hclarke
hclarke / RandomThings.cs
Created October 28, 2015 15:49
random points on meshes
public class RandomThings {
public void CalculateRandomPointsOnMeshes(MeshFilter[] meshFilters, Vector3[] dst, Vector3? direction) {
//find all the meshes
float weight = 0;
foreach (var filter in meshFilters) {
var mesh = filter.sharedMesh;
var vs = mesh.vertices;
for(int i = 0; i < vs.Length; ++i) {
vs[i] = filter.transform.TransformPoint(vs[i]);
*.suo
*.sln
*.unityproj
*.csproj
/Library
/obj
/Temp