Skip to content

Instantly share code, notes, and snippets.

View MLKrisJohnson's full-sized avatar

Kris Johnson MLKrisJohnson

View GitHub Profile
@MLKrisJohnson
MLKrisJohnson / Makefile
Created July 9, 2024 17:29
A Makefile which will process all Mermaid and Graphviz files in a directory
# Makefile for Mermaid and Graphviz files in this directory
#
# `make all` - (default target) 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 input files to be processed
# `make listtargets` - print list of all output files
@MLKrisJohnson
MLKrisJohnson / homebrew-bashrc.sh
Created November 8, 2023 15:37
Homebrew shell setup for Intel and Apple silicon or Rosetta
# Init Homebrew shell environment
if [ "$(arch)" = 'i386' ]; then
[ -e /usr/local/bin/brew ] && eval "$(/usr/local/bin/brew shellenv)"
# Force use of Intel dotnet binaries
export PATH="/usr/local/share/dotnet/x64:$PATH"
echo 'Initialized i386 environment'
else # arch = arm64
[ -e /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)"
echo 'Initialized arm64 environment'
fi
@MLKrisJohnson
MLKrisJohnson / hexdump.swift
Created July 20, 2023 13:50
Swift hexdump function
import Cocoa
func printHexdump(data: Data) {
print("\n 0 1 2 3 4 5 6 7 8 9 a b c d e f")
print("-----------------------------------------------------------------------------")
var i = 0
var bytes: [UInt8] = []
while i < data.count {
if i % 16 == 0 {
// Write ASCII at end of previous line
@MLKrisJohnson
MLKrisJohnson / mermaid.ipynb
Last active October 1, 2024 22:06
Displaying Mermaid Diagrams in a Jupyter Notebook Using Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MLKrisJohnson
MLKrisJohnson / unzipped.sh
Created March 24, 2023 19:54
Bash/Zsh function to decompress a set of files into a subdirectory
# Unzip a set of files to an "unzipped" subdirectory
#
# Example:
#
# unzipped *.zip *.tar.gz
#
# will create the "unzipped" directory if not present, and decompress all the files into that directory.
function unzipped {
for f in "$@" ; do
directory=$(dirname "$f")
@MLKrisJohnson
MLKrisJohnson / argparse_test.py
Created October 17, 2022 13:26
Test program for Python argparse module
#!/usr/bin/env python3
"""Test program for argparse module."""
import argparse
def main():
parser = argparse.ArgumentParser(
description='Test Python argparse module.',
epilog='This script doesn\'t do anything useful.'
@MLKrisJohnson
MLKrisJohnson / wrap_text.py
Created October 17, 2022 13:24
Demonstration of Python standard library textwrap module.
#!/usr/bin/env python3
"""
Demonstration of Python standard library textwrap module.
Run "python3 wrap_test.py -h" for command-line options.
"""
import argparse
import sys
@MLKrisJohnson
MLKrisJohnson / Makefile
Last active February 22, 2022 23:51
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
@MLKrisJohnson
MLKrisJohnson / timestampString.m
Last active October 6, 2020 17:43
Objective-C: Return current date/time in "yyyy-MM-dd HH:mm:ss.SSS Z" format
// Returns current date/time in "yyyy-MM-dd HH:mm:ss.SSSS Z" format using the
// system timezone.
//
// Note that this includes fractional seconds, unlike the system log, so it
// is useful when precise times are desired in log output.
static NSString* timestampString()
{
// Re-use one NSDateFormatter instance for all calls.
// NSDateFormatter is thread-safe for iOS 7+.
static NSDateFormatter* df;
@MLKrisJohnson
MLKrisJohnson / Makefile
Created August 5, 2020 17:47
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