Skip to content

Instantly share code, notes, and snippets.

View mcgwiz's full-sized avatar
🛠️

Mike McGranahan mcgwiz

🛠️
View GitHub Profile
@mcgwiz
mcgwiz / pre-push.git-msys
Last active October 31, 2020 00:03
pre-push hook to block force-pushing to certain branches on Git for Windows MSYS bash
#!/bin/sh
# based on https://gist.github.com/stefansundin/d465f1e331fc5c632088#file-pre-push
BRANCH=`git rev-parse --abbrev-ref HEAD`
# customization for cygwin/msys
PID=`ps | grep ' /cmd/git$' | sort -n | tail -n 1 | tr -s ' ' | cut -d ' ' -f 2`
PUSH_COMMAND=`cat /proc/$PID/cmdline | tr '\000' ' '`
@mcgwiz
mcgwiz / sb-filesModel.js
Created June 10, 2017 23:23
Simple file input model binding for AngularJS
angular.module("sb", [ ]).directive('filesModel', FilesModel);
FilesModel.$inject = [ "$parse"];
function FilesModel($parse) {
return {
restrict: 'A',
link: function (scope, element, attr) {
var model = $parse(attr.filesModel);
@mcgwiz
mcgwiz / PlaintextSecureDataFormat.cs
Last active July 15, 2017 19:18
A plaintext implementation of ISecureDataFormat<AuthenticationTicket> for educational purposes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
namespace ScrambledBrains {
public class PlaintextSecureDataFormat : ISecureDataFormat<AuthenticationTicket> {
public string Protect(AuthenticationTicket data) {
@mcgwiz
mcgwiz / profile.cmd
Last active March 31, 2020 17:16
bash-like `cd` behavior in Windows command interpreter
@echo off
:: Adds support for
:: `cd` change to user profile directory
:: `cd -` change to previous directory
doskey cd=^
set PD="%%CD%%" ^& ^
if [$*]==[] ( ^
cd /d %%userprofile%% ^
OWNER=$(echo ${TRAVIS_REPO_SLUG} | grep -Po '\w*' | head -n 1)
# Get the tags
TAGS="$(curl -s -u ${OWNER}:${SECRET} https://api.github.com/repos/${TRAVIS_REPO_SLUG}/git/refs/tags | grep -Po '(ref|sha)":.*' | paste -d" " - -)"
# Get the most recent tag number
VER=$(echo "${TAGS}" | sed 's/ref": "refs\/tags\/v//g' | sed 's/", sha":.*//g' | sort -V | tail -n 1)
# Get the associated tag ref
TAG_SHA=$(echo "${TAGS}" | grep $VER | sed 's/.*sha": "//g' | sed 's/",//g')
@mcgwiz
mcgwiz / inherited-state-pattern.js
Last active November 3, 2015 03:03
Pattern for JavaScript prototypical inheritance with private and protected state
var Modal = (function() {
function createType(subTypeBox) {
var subTypeBox = subTypeBox || { };
var internal = { }; // "protected" state bag
var stack = [ ]; // "private" field
// Name the constructor function strictly for debug purposes, in a way that doesn't spill throughout this scope.
var Type = (function() { return function Modal(id) { this.id = id; }; })();
@mcgwiz
mcgwiz / keybase.md
Created May 27, 2015 03:02
keybase.md

Keybase proof

I hereby claim:

  • I am mcgwiz on github.
  • I am mcgwiz (https://keybase.io/mcgwiz) on keybase.
  • I have a public key whose fingerprint is 5D4D 6C42 EEC9 1AF2 07E0 6223 D32E 7D0C 3CDA B00F

To claim this, I am signing this object:

@mcgwiz
mcgwiz / ToTitleFromPascalCase
Last active August 29, 2015 14:05
ToTitleCaseFromPascal
static string ToTitleFromPascalCase(string s) {
var sb = new StringBuilder();
for (var i = 0; i < s.Length; i++) {
var c = s[i];
if (c == ' ') { continue; }
if (i == 0) { sb.Append(c); continue; }
if (!char.IsUpper(c)) { sb.Append(c); continue; }
if (!char.IsUpper(s[i - 1])) { sb.Append(' ').Append(c); continue; }
@mcgwiz
mcgwiz / pre-commit
Last active November 28, 2018 08:49
Simple git pre-commit hook for detecting a do-not-commit token (e.g. "NOSHARE").
#!/bin/sh
git diff-index --cached --quiet HEAD
_ANY=$?
if ((0 == $_ANY)); then
exit 0
fi
_TOKEN_FOUND=`git diff --cached --name-only | xargs -L1 -I{} sh -c "echo {}; git diff --cached {} | grep -v '^-' | grep -H NOSHARE"`
@mcgwiz
mcgwiz / .gitattributes
Last active April 23, 2017 20:19
Super simple JavaScript git diff hunk header config
*.js diff="javascript"