Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / autoload.php
Last active September 13, 2019 08:16
Directory-based autoload function
<?php
/* Directories that contain classes */
$classesDir = array (
ROOT_DIR.'classes/',
ROOT_DIR.'firephp/',
ROOT_DIR.'includes/'
);
function __autoload($class_name) {
global $classesDir;
@gowon
gowon / ob_minify.php
Last active August 29, 2015 14:03
Minify PHP Output Buffer - Compress HTML output to a single line, then attempt gzip compression
<?php
/**
* Smart Tidy/Gzip Output Buffer
* Compress HTML output to a single line, then attempt gzip compression.
* @param string $buffer
* @param int $mode
* @return string|false
*/
function ob_minify($buffer, $mode) {