Skip to content

Instantly share code, notes, and snippets.

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;
///
/// Adds logging to all functions in a JS object.
///
/// Backbone usage example:
/// return Backbone.View.extend({ ... });
/// becomes:
/// return Backbone.View.extend(addLogs({ ... }));
/// and all method invocations are now logged to the console.
///
function addLogs(obj) {
@jaburns
jaburns / cd_to_script.sh
Created June 16, 2016 21:50
cd to the location of the script being run
cd "$(dirname "${BASH_SOURCE[0]}")"