Skip to content

Instantly share code, notes, and snippets.

@gowon
gowon / AssemblyResolve.cs
Created March 20, 2015 16:53
Loading a library from internal resources instead of external references.
// Place this code in the initialization section of your code.
// http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
String resourceName = "AssemblyLoadingAndReflection." +
new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
@gowon
gowon / open-xml-mime-types
Last active August 29, 2015 14:17
Microsoft Office 2007 OpenXML Mime Types
".manifest", "application/manifest"
".xaml", "application/xaml+xml",
".application", "application/x-ms-application",
".deploy", "application/octet-stream"
".xbap", "application/x-ms-xbap"
".docm","application/vnd.ms-word.document.macroEnabled.12"
".docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"
".dotm","application/vnd.ms-word.template.macroEnabled.12"
".dotx","application/vnd.openxmlformats-officedocument.wordprocessingml.template"
@gowon
gowon / exception-msgs.cs
Last active August 29, 2015 14:19
Grabbing all exception messages from inner exceptions
using System;
using System.Text;
public static class ExceptionExtensions
{
public static string GetAllMessages(this Exception ex)
{
var message = new StringBuilder();
for (var e = ex; e != null; e = e.InnerException)
message.AppendLine(e.Message);
@gowon
gowon / anonymous-enumerable.cs
Last active August 12, 2022 07:06
Create an Enumerable for an Anonymous Type
var list = Enumerable.Empty<object>()
.Select(r => new {A = 0, B = 0}) // prototype of anonymous type
.ToList();
list.Add(new { A = 4, B = 5 }); // adding actual values
Console.Write(list[0].A);
@gowon
gowon / is-element-of-linq.cs
Last active August 29, 2015 14:22
Fairly elegant & performant way to find if object is contained in set without using Linq
using System;
using System.Collections.Generic;
using System.Linq;
public static class GenericExtensions
{
public static bool IsElementOf<T>(this T item, params T[] list)
{
return Array.IndexOf(list, item) != -1;
}
@gowon
gowon / currier.js
Created June 25, 2015 23:33
Javascript Currying Example
// Example of a currying methods
// https://medium.com/@kbrainwave/currying-in-javascript-ce6da2d324fe
var currier = function(fn) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
return fn.apply(this, args.concat(
Array.prototype.slice.call(arguments, 0)));
};
@gowon
gowon / topsort.php
Last active September 25, 2023 14:13
PHP Topological Sorting
<?php
$test = array(
'c' => array(
'depends' => 'b'
),
'a' => array(),
'b' => array(
'depends' => 'd'
),
@gowon
gowon / dhcp-reservations-sop.md
Last active February 11, 2017 22:12
DHCP Reservations "SOP"

DHCP Reservations SOP

  • x.x.x.1 = default gateway (assuming /24)
  • 2-19 = network access devices (switches, etc.)
  • 20-39 = server devices
  • 40-59 = network peripherals (printers, etc.)
  • 60-79 = reserved for special devices
  • 80-99 = static addressed workstations
  • 100-199 = standard DHCP pool of addresses
  • 200-254 = VOIP devices (switch, adapters, etc.)
@gowon
gowon / index.html
Last active November 14, 2016 21:31
HTML5 Boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.js"></script>
<![endif]-->
</head>
@gowon
gowon / detectDataURL.js
Last active June 14, 2021 17:03 — forked from bgrins/detectDataURL.js
Detect if a string is a data URL. Doesn't try to parse it or determine validity, just a quick check if a string appears to be a data URL. See http://jsfiddle.net/bgrins/aZWTB/ for a demo.
// Detecting data URLs
// data URI - MDN https://developer.mozilla.org/en-US/docs/data_URIs
// The "data" URL scheme: http://tools.ietf.org/html/rfc2397
// Valid URL Characters: http://tools.ietf.org/html/rfc2396#section2
function isDataURL(s) {
return isDataURL.regex.test(s);
}
isDataURI.regex = /^\s*data:([a-z]+\/[a-z0-9\-]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;