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 / main.cpp
Last active November 19, 2024 15:42
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
@kristopherjohnson
kristopherjohnson / dirs_to_markdown.py
Last active May 27, 2024 18:30
Python script to create a Markdown representation of a directory tree
#!/usr/bin/env python3
# Walks a directory tree, creating a Markdown representation of it.
#
# First command line argumaent is root directory. Defaults to current directory.
import os
import sys
if len(sys.argv) > 1:
@kristopherjohnson
kristopherjohnson / Makefile
Created August 9, 2020 19:14 — forked from MLKrisJohnson/Makefile
Makefile that runs GraphViz Dot utility on all *.gv files in the current directory
# Makefile for GraphViz files in this directory
#
# `make all` - build all targets
# `make clean` - delete all targets
# `make listtargets` - print list of all targets
# `brew install graphviz`, or download from <http://graphviz.org/download/>
# to get the `dot` utility.
DOT?=dot