Skip to content

Instantly share code, notes, and snippets.

View jstine35's full-sized avatar

Jake Stine jstine35

View GitHub Profile
@jstine35
jstine35 / choco-installer.nsi
Created February 3, 2018 17:57
Chocolatey Web Installer NSIS Script
; Chocolatey Web Installer
; By Jake Stine
;
; This is currently a one-way install. No uninstaller is provided.
; Uninstalling Chocolatey normally consists of deleting the chocolatey dir and removing
; Chocolatey from the PATH.
!include "LogicLib.nsh"
name "Chocolatey Web Installer"
@jstine35
jstine35 / pr.md
Created May 14, 2018 23:41 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@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`:
//
@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
#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 / 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
@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

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
#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
@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