Skip to content

Instantly share code, notes, and snippets.

@jaburns
jaburns / vec.h
Created November 7, 2018 23:43
Generic variable size array in C
#pragma once
#include <stddef.h>
#include <stdlib.h>
#define Vec( T ) struct { \
size_t count; \
T *items; \
}
@jaburns
jaburns / genindex.cpp
Last active March 10, 2023 18:10
Generational indices in C++ vs Rust
/*
Copyright 2021 Jeremy Burns
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 USE OR O
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
if (!(Test-Path -Path "$Profile")) {New-Item -ItemType File -Path "$Profile" -Force}
Add-Content -Value "Set-PSReadlineOption -BellStyle None" -Path "$Profile"
#!/usr/bin/env bash
find_files() {
ag "$1" | cut -d: -f1 | sort | uniq
}
do_replace() {
echo "Finding files matching orignial string $1"
for f in $(find_files "$1"); do
echo " -> Replacing string in file $f"
@jaburns
jaburns / FlattenMeshNormalsMenu.cs
Last active January 23, 2018 18:04
Create a copy of a mesh where each triangle has vertices with normals outward from the triangle
using UnityEngine;
using UnityEditor;
static public class FlattenMeshNormalsMenu
{
[MenuItem("GameObject/Flatten Mesh Normals", true)]
static bool GameObject_FlattenMeshNormals_validate()
{
var go = Selection.activeObject as GameObject;
if (go == null) return false;
@jaburns
jaburns / .gitconfig
Last active April 25, 2021 05:21
Using VS as mergetool on WSL
[merge]
tool = vs
[mergetool "vs"]
cmd = /home/XXX/win_merge.sh merge $LOCAL $REMOTE $BASE $MERGED
trustExitCode = false
[mergetool]
keepBackup = false
[diff]
tool = vs
[difftool "vs"]
@jaburns
jaburns / fixed32.cpp
Created August 23, 2017 16:31
C++ fixed-point 32 bit type
#include "fixed32.hpp"
#include <cmath>
static const int32_t DECIMAL_BITS = 16;
const fixed32 fixed32::ZERO = fixed32(0);
const fixed32 fixed32::ONE = fixed32(1);
const fixed32 fixed32::MINUS_ONE = fixed32(-1);
const fixed32 fixed32::TWO = fixed32(2);
@jaburns
jaburns / webpack.config.js
Created April 11, 2017 22:35
Example of building only sass with webpack for legacy project
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
context: __dirname,
entry: {
styles: ['./sass/main.scss']
},
output: {
filename: 'build.css'
},
@jaburns
jaburns / quat2rot.shader
Created March 1, 2017 18:01
Convert quaternion to rotation matrix
float3x3 quaternionToRotationMatrix(float4 q)
{
return float3x3(
1 - 2*q.y*q.y - 2*q.z*q.z , 2*q.x*q.y - 2*q.z*q.w , 2*q.x*q.z + 2*q.y*q.w,
2*q.x*q.y + 2*q.z*q.w , 1 - 2*q.x*q.x - 2*q.z*q.z , 2*q.y*q.z - 2*q.x*q.w,
2*q.x*q.z - 2*q.y*q.w , 2*q.y*q.z + 2*q.x*q.w , 1 - 2*q.x*q.x - 2*q.y*q.y
);
}
@jaburns
jaburns / rand.js
Last active February 7, 2021 18:29
Linear congruential random-number generator.
const M = 4294967296;
const A = 1664525;
const C = 1013904223;
// seed is an integer in the range [0, M)
const next = seed => (A * seed + C) % M;
const value = seed => seed / M;