Skip to content

Instantly share code, notes, and snippets.

View ecmjohnson's full-sized avatar

Erik ecmjohnson

View GitHub Profile
@ecmjohnson
ecmjohnson / pcd.hpp
Created July 22, 2025 13:32
Single header file for writing PCD files
#pragma once
#include <fstream>
#include <vector>
#include <array>
class PCD
{
public:
PCD() = default;
@ecmjohnson
ecmjohnson / find_symbol.py
Last active July 15, 2025 15:28
Find a specific symbol in binaries within a directory
import os, subprocess, re
from absl import app, flags
from tqdm import tqdm
import concurrent.futures
import colorama
flags.DEFINE_string(
'dir',
None,
'Directory under which to search'
@ecmjohnson
ecmjohnson / pid.hpp
Created November 4, 2023 16:42
Single header PID controller implementation
#pragma once
template<typename T>
class PID {
public:
PID(T Kp, T Ki, T Kd, T minInt, T maxInt) {
_kp = Kp;
_ki = Ki;
_kd = Kd;
@ecmjohnson
ecmjohnson / scoped_timer.hpp
Last active October 17, 2024 14:20
Time execution of a scope
#include <iostream>
#include <chrono>
class ScopedTimer
{
public:
static size_t total_ns;
ScopedTimer(std::string name) :
name(name),
@ecmjohnson
ecmjohnson / SaveDataHandler.cs
Created February 28, 2022 15:58
Encrypted and asynchronous save data system for Unity
/**
* This class handles save data on the local device:
*
* It writes and reads encrypted data to/from the storage on the target device using
* `Application.persistentDataPath`. This secure data can be read only if its format
* and key are known!
*
* It is the client's responsibility to verify a loaded file exists! This can be done
* with the `DoesFileExist` utility function. Note that this does not guarantee
* success, as the type contained in the file may conflict with that requested.
@ecmjohnson
ecmjohnson / fix.py
Last active October 15, 2021 13:23
Utility for batch modifying images
import sys, os
import numpy as np
import imageio
from absl import app, flags
from tqdm import tqdm
opts = flags.FLAGS
flags.DEFINE_string('input_dir', 'masks', 'Input directory')
flags.DEFINE_string('output_dir', 'results', 'Outut directory')
@ecmjohnson
ecmjohnson / plywriter.py
Last active November 8, 2021 16:12
Writer for .ply geometry files (pointclouds, meshes, lines)
import traceback
"""
A simple writer for .ply geometry files. Very useful for debugging!
Buffers the contents and writes out only on exit (necessary for writing
the header without knowing the vertex/edge/face count in advance).
Closes the fd in the case a with block raises an exception.
We could wait until the exit to even open the fd; however, I decided
against that to match expected behaviour. This could accomodate a
design where the vertex/edge/face count is provided in advance.
@ecmjohnson
ecmjohnson / souptracer.py
Created July 26, 2021 12:46
Python ray-tracer for a triangle soup
import numpy as np
import numba as nb
"""
A small ray-tracer for rendering a triangle soup. It gives all intersections
along the ray (in no particular order) and does not do back-face culling.
Uses a BVH for algorithmic acceleration and numba for low-level optimization.
Usage:
```
@ecmjohnson
ecmjohnson / zoom.bat
Last active July 20, 2021 12:09
Translation of nerdyrodent/VQGAN-CLIP/zoom.sh to Windows Batch Scripting
@echo off
:: needed to modify variables in a for loop
SETLOCAL ENABLEDELAYEDEXPANSION
:: command line options
SET TEXT=%~1
SET FILENAME=%~2
SET MAX_EPOCHS=%~3
:: hardcoded options
@ecmjohnson
ecmjohnson / ObjectPool.cs
Last active June 8, 2021 12:19
Unity object pooling script
/**
* This class implements the object pool pattern:
*
* It can be used for creating objects exactly as if using Unity's `Instantiate` call. Simply
* call `AcquireObject` with a prefab and an instance of that object will be returned, either
* recycled from the pool or allocated if the pool is empty.
*
* It is the responsibility of the object to set itself inactive with `SetActive(false)` at
* lifetime end. This is how objects are recycled by the pool.
*