Skip to content

Instantly share code, notes, and snippets.

View jstine35's full-sized avatar

Jake Stine jstine35

View GitHub Profile
@jstine35
jstine35 / colors.sh
Last active May 15, 2024 16:12
Quick snip for injecting ANSI colors into bash scripts
# Quick snip for injecting ANSI colors into bash scripts. Best used inside cat heredoc.
#
# Usage examples:
# cat << BOOKENDS
# ${blue}${bold}${underlined}Getting Started Guide:${nocolor}
# BOOKENDS
nocolor=''
# FIRST VERSION - Outputs UTS formatted timestamp.
# -------------------------------------------------------------------------------------
# handy pipe redirect that appends a datestamp to every line of output. Just paste this into
# the top of a typical BASH script.
s_datestamp() {
while read -r line; do
timestamp=$(date -u '+%Y-%m-%d %H:%M:%S')
@jstine35
jstine35 / run-sh.bat
Created January 15, 2021 14:46
A tool to run BASH shell scripts from Windows/DOS batch command scripts, without requiring .sh extension association configured.
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:: Caveats:
:: * bash.exe in the PATH is often "bogus" -- a few apps, chocolately installers in particular, install stripped-down
:: non-functional versions of bash.exe into the PATH just so they can glob files (making them equivalent to malware imo)
::
:: * No way to know where MSYS2 is installed, so impose a requirement that it be c:\msys64\
::
:: * GIT Bash usually sets up an sh_auto_file association that allows sh files to be run directly. But sometimes it's
#pragma once
// ENABLE_PRINTF_VERIFY_CHECK_ON_MSVC
//
// Microsoft doesn't provide a way to annoate custom-rolled user printf() functions for static analysis.
// Well, ok -- it does provide _Printf_format_string_ but that's only effective when using the Code Analysis
// tool which is both incrediously slow and generates a hundred false positives for every valid issue. In
// other words, useless.
//
// The upside is MSVC does perform automatic lightweight static analysis on printf() builtin functions as part

Setting up mingw64 for MSSYS2, for use in building emulators via Makefile...

pacman -S make
pacman -S autoconf
pacman -S automake
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-clang
pacman -S mingw-w64-x86_64-lld
pacman -S mingw-w64-x86_64-dlfcn
@jstine35
jstine35 / SwapEditorShortcutsOnPlayerFocus.cs
Last active December 3, 2022 08:15
Resolves Editor Keyboard Behavior in Unity Player, so your game can handle CTRL and hotkeys without corrupting your scene
// Summary
// Disables Editor Keyboard Behavior when Unity Player has focus, so your game can handle CTRL and
// without corrupting your scene.
//
// Usage
// * Download or copy/paste and attach this component to a scene management object in your scene.
// * Create a new shortcut profile using Edit->Shortcuts (tedious, you need to pretty much click every
// button and remove every keystroke, one by one).
//
// Remarks
@jstine35
jstine35 / positional_params.sh
Last active December 19, 2021 15:27
Bash Positional Option Parsing with rvalue assignment
#!/bin/bash
POSITIONAL=( )
for item; do
rvalue="${item#*=}"
[[ "$item" == --help ]] && SHOWHELP=1 && continue
[[ "$item" == --force ]] && FORCE=1 && continue
[[ "$item" == --force=* ]] && FORCE=$rvalue && continue
#include <chrono>
// Use some clever syntax to allow GetProcessTimeInSeconds() to work from pre-main() initalizers.
// (in some cases the OS might init s_ProcessStartTimeSecs as 0 prior to invoking the runtime initializer
// that gives it a real value... but probably not. Almost all operating systems will init the boolean
// to zero prior to init() however, so that's what I do this little juggle).
bool s_ProcessStartInit = 0;
double s_ProcessStartTimeSecs = ((s_ProcessStartInit=1), std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
double GetProcessTimeInSeconds()
@jstine35
jstine35 / CaseReturnString.h
Last active July 14, 2019 13:25
Macro to allow rapid creation of enum->string conversion tables in C++, using column editing and switch statements.
#pragma once
/////////////////////////////////////////////////////////////////////////////////////////////////
// CaseReturnString( caseName )
//
// Neat! Returns the case option as a string matching precisely the case label. Useful for logging
// hardware registers and for converting sparse enumerations into strings (enums where simple char*
// arrays fail).
//
#define CaseReturnString(caseName) case caseName: return # caseName
@jstine35
jstine35 / defer.h
Last active July 14, 2019 12:37
Defer-style functionality for C++ (Defer concept borrowed from GoLang)
#pragma once
#include <functional>
// -----------------------------------------------------------------------------------------------
// Defer (macro) / Defer_t (struct)
//
// Inspired by Golang's 'defer' keyword. Allows binding a lambda to be executed when the current
// scope of the deferral's creation is left. This still differs from Golang `defer`:
//