Skip to content

Instantly share code, notes, and snippets.

@DoggettCK
DoggettCK / gist:1305566
Created Oct 22, 2011
Code from "Enumerations and Strings - Stop the Madness!" (modified and added over time)
View gist:1305566
using System;
using System.Collections.Generic;
using System.Linq;
namespace Util
{
public static class Enums
{
#region Parse Methods
/// <summary>
@DoggettCK
DoggettCK / gist:1591307
Created Jan 10, 2012
GamersWithJobs.com Ignore Users Chrome User Script
View gist:1591307
// ==UserScript==
// @name I Didn't Hear Anything
// @namespace gamerswithjobs
// @description Increases the number of potential Tannhauserings
// @include http://www.gamerswithjobs.com/node/*
// @author Chris Doggett
// ==/UserScript==
// Special thanks to Jeremy Banks at http://stackoverflow.com/a/6834930/64203
var load,execute,loadAndExecute;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+")();":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function(){return execute(b)})};
View sludgehammer.user.js
// ==UserScript==
// @name SludgeHammer
// @namespace gamerswithjobs
// @description Replaces marketing speak with English
// @exclude /github/
// @author Chris Doggett
// ==/UserScript==
// Special thanks to Jeremy Banks at http://stackoverflow.com/a/6834930/64203
var load,execute,loadAndExecute;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+")();":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function(){return execute(b)})};
View hodor.user.js
// ==UserScript==
// @name Hodor
// @namespace gamerswithjobs
// @description Makes everything sound the same
// @exclude /github/
// @author Chris Doggett
// ==/UserScript==
// Special thanks to Jeremy Banks at http://stackoverflow.com/a/6834930/64203
var load,execute,loadAndExecute;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+")();":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function(){return execute(b)})};
View bloomfilter.py
from bitarray import bitarray
import mmh3
from math import log, pow, ceil
class BloomFilter:
def __init__(self, size, hash_count):
self.size = size
self.hash_count = hash_count
self.bit_array = bitarray(size)
self.bit_array.setall(0)
@DoggettCK
DoggettCK / elixir_ddr_gen.py
Created Feb 12, 2013
Creates DDL from generated Elixir Models
View elixir_ddr_gen.py
from inspect import getmembers, isclass
from sqlalchemy.schema import CreateTable
from elixir import metadata, setup_all, Entity, EntityMeta
from sys import modules
def generate_ddl(module, tablenames=[]):
prev_bind = metadata.bind
metadata.bind = "sqlite://"
setup_all()
View gist:e6da2981096968b43e15
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Hosting;
using System.Web.Http;
using System.Web.Http.Description;
using NLog;
namespace Project.Controllers.API {
///
@DoggettCK
DoggettCK / gist:a54f49718d5ac2c74019
Created Oct 1, 2014
API self-documentation output
View gist:a54f49718d5ac2c74019
{
RelativePath: "api/products/get?sort_by={sort_by}&sort_order={sort_order}",
Method: "GET",
SupportedResponseFormats: [
"application/json",
"text/json"
],
SupportedEncodings: [
"utf-8",
"utf-16"
View profile.ps1
# Make sure we're installing into user's own Powershell Module path, and not the global one
$PSModuleDir = "$($ENV:PsModulePath)".Split(";") | Select-String "$ENV:UserName" | foreach {$_.Line } | Select-Object -First 1
function ModuleInstalled([parameter(Mandatory=$true)][string] $moduleName) {
return ((Get-Module "$moduleName") -ne $null)
}
function InstallPlugins([parameter(Mandatory=$true)][string[]] $moduleNames) {
if (-NOT (Test-Path "$PSModuleDir\PsGet\PsGet.psm1")) {
New-Item -ItemType Directory -Force -Path "$PSModuleDir\PsGet" | Out-Null
@DoggettCK
DoggettCK / Hasher.cs
Last active Aug 29, 2015
ASP.NET HMACSHA256 Password hashing
View Hasher.cs
/// <summary>
/// Given a password and salt string, along with an algorithm (MVC4 defaults to HMACSHA256), calculates the password's
/// hash value as stored in the DB.
/// </summary>
/// <param name="password">Plaintext password</param>
/// <param name="salt">Base64 string containing user's salt value</param>
/// <param name="hashingAlgorithm">Known .NET crypto algorithm name. Defaults to MVC4's default of HMACSHA256.</param>
/// <returns>Base64-encoded password hash string</returns>
/// <exception cref="CryptographicException">If hashingAlgorithm is unknown to .NET</exception>
private string HashPassword(string password, string salt, string hashingAlgorithm = "HMACSHA256") {