Skip to content

Instantly share code, notes, and snippets.

@jasonbrice
jasonbrice / HIDDevice.cs
Last active December 15, 2015 00:38
Simple class to detect insertion/removal of Human Interface Device (e.g., user sticks a thumb drive into a USB port)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace HID
{
public static class Constants
{
@jasonbrice
jasonbrice / example setup
Last active August 1, 2022 08:51
Postgresql example DDL
SET check_function_bodies = false;
-- ddl-end --
-- object: stealthis | type: SCHEMA --
-- DROP SCHEMA stealthis CASCADE;
CREATE SCHEMA stealthis;
-- ddl-end --
SET search_path TO pg_catalog,public,stealthis;
-- ddl-end --
@jasonbrice
jasonbrice / AspNetAuthenticate.js
Created February 25, 2015 20:52
JavaScript implementation of Microsoft.AspNet.Identity.Crypto.VerifyHashedPassword
// Reference https://gist.github.com/trailmax/553ea84d4d0e2e20fcd7
function VerifyHashedPassword(password, hashedPwd) {
// NodeJS implementation of crypto
var crypto = require('crypto');
var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
var hashedPasswordBytes = new Buffer(hashedPwd, 'base64');
var saltString = "";
@jasonbrice
jasonbrice / html_debug_console.js
Last active August 13, 2021 01:37
Show console output as HTML for browsers with no console (e.g., safari on iPad)
// set an identifier for the console div
var consoleId = 'debug_console';
// initialize the debug console, dock to bottom of page
var debugConsole = function () {
var body = document.getElementsByTagName('body')[0];
// since this function also gets called on clear(),
// we'll remove the div if it exists so we can re-add it
@jasonbrice
jasonbrice / CheckWellFormed
Created April 29, 2015 16:07
Check whether a set of curly braces, brackets and parentheses are well-formed
private static bool CheckWellFormed(string input)
{
var stack = new Stack<char>();
// dictionary of matching starting and ending pairs
var allowedChars = new Dictionary<char, char>() { { '(', ')' }, { '[', ']' }, { '{', '}' } };
var wellFormated = true;
foreach (var chr in input)
{
if (allowedChars.ContainsKey(chr))