Skip to content

Instantly share code, notes, and snippets.

🤝
Hiring!

Mike McGranahan mcgwiz

🤝
Hiring!
Block or report user

Report or block mcgwiz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mcgwiz
mcgwiz / sb-filesModel.js
Created Jun 10, 2017
Simple file input model binding for AngularJS
View sb-filesModel.js
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 Jul 15, 2017
A plaintext implementation of ISecureDataFormat<AuthenticationTicket> for educational purposes.
View PlaintextSecureDataFormat.cs
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
Created Aug 25, 2016
bash-like `cd` behavior in Windows command interpreter
View profile.cmd
@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%% ^
View travis-version-snippet.sh
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 Nov 3, 2015
Pattern for JavaScript prototypical inheritance with private and protected state
View inherited-state-pattern.js
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; }; })();
View 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 Aug 29, 2015
ToTitleCaseFromPascal
View ToTitleFromPascalCase
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 Nov 28, 2018
Simple git pre-commit hook for detecting a do-not-commit token (e.g. "NOSHARE").
View pre-commit
#!/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 Apr 23, 2017
Super simple JavaScript git diff hunk header config
View .gitattributes
*.js diff="javascript"
You can’t perform that action at this time.