Skip to content

Instantly share code, notes, and snippets.

View kristopherjohnson's full-sized avatar
💭
Huh?

Kristopher Johnson kristopherjohnson

💭
Huh?
View GitHub Profile
@kristopherjohnson
kristopherjohnson / synchronized_value.hpp
Last active May 30, 2025 19:41
C++ SynchronizedValue<T> class
#ifndef KJ_SYNCHRONIZEDVALUE_H
#define KJ_SYNCHRONIZEDVALUE_H
/*
Copyright 2025 Kristopher Johnson
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
@kristopherjohnson
kristopherjohnson / generate_cpp_project.py
Last active March 11, 2025 02:31
Script for generating a new CMake-based C++ project
#!/usr/bin/env python3
"""
generate_cpp_project.py
This script generates a standard C++ project structure with CMake build system.
The generated project includes:
- A main executable
- A library with header files
- Unit tests using Doctest
- CMake configuration with CPack support
@kristopherjohnson
kristopherjohnson / main.cpp
Last active December 2, 2024 15:16
C++ stopwatch, for calculating elapsed time
// Example of using the Stopwatch class to measure elapsed time.
#include <iostream>
#include <thread>
#include "stopwatch.h"
int main(int argc, const char **argv) {
// Construct stopwatch starting at current time.
Stopwatch stopwatch;
@kristopherjohnson
kristopherjohnson / clang-tidy.sh
Last active November 13, 2024 15:39
bash/zsh alias for running clang-tidy from Homebrew llvm formula
if type brew &>/dev/null; then
if brew list llvm &>/dev/null; then
alias clang-tidy="$(ls -1 $(brew --cellar llvm) | sort -V | tail -n 1 | xargs -I {} echo $(brew --cellar llvm)/{}/bin/clang-tidy)"
fi
fi
@kristopherjohnson
kristopherjohnson / open-repo.sh
Last active November 13, 2024 15:19
bash/zsh alias for opening the GitHub page for the current repo on macOS
# Open the current directory's GitHub repo in web browser
alias open-repo="open \"\$(git config --get remote.origin.url | sed -E 's/[email protected]:/https:\/\/github.com\//; s/\.git\$//')\""
@kristopherjohnson
kristopherjohnson / latch.js
Last active November 7, 2024 22:45
Logic Pro Scripter script for a latched MIDI keyboard
// Plays note with infinite sustain when pressed.
// Unlatches note when it is pressed again.
// Initialize an empty set to store latched notes
var latchedNotes = new Set();
function HandleMIDI(event) {
// Check if the event is a note on or note off
if (event instanceof NoteOn) {
if (latchedNotes.has(event.pitch)) {
@kristopherjohnson
kristopherjohnson / monitor_pid.sh
Created August 28, 2024 14:04
Once per minute, collect process CPU and memory-usage in CSV format
#!/bin/bash
# Given a process ID, print time,%cpu,%mem,vsz,rss in CSV format once per minute.
# Check if PID is provided
if [ -z "$1" ]; then
echo "Usage: $0 <PID>"
exit 1
fi
@kristopherjohnson
kristopherjohnson / code_search.ipynb
Last active February 1, 2023 17:00
Search code using OpenAI API
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kristopherjohnson
kristopherjohnson / argparsetest.py
Created July 9, 2022 18:00
Simple example of using the Python argparse module
#!/usr/bin/env python3
"""Tests/examples for the argparse module.
Run "python3 argparsetest.py -h" for help.
"""
from argparse import ArgumentParser
def main():
@kristopherjohnson
kristopherjohnson / Makefile
Created February 22, 2022 23:51 — forked from MLKrisJohnson/Makefile
Makefile for processing Mermaid files in the current directory
# Makefile for Mermaid files in this directory
#
# `make all` - build all targets
# `make png` - build PNGs for all source files
# `make svg` - build SVGs for all source files
# `make pdf` - build PDFs for all source files
# `make clean` - delete all targets
# `make listsources` - print list of all files to be processed
# `make listtargets` - print list of all output files