Skip to content

Instantly share code, notes, and snippets.

View AdamLJohnson's full-sized avatar

Adam Johnson AdamLJohnson

View GitHub Profile
@AdamLJohnson
AdamLJohnson / postal-codes.json
Created September 14, 2017 14:53 — forked from matthewbednarski/postal-codes.json
Global postal codes regex formats
[{ "Note": "The first two digits (ranging from 10–43) correspond to the province, while the last two digits correspond either to the city/delivery zone (range 01–50) or to the district/delivery zone (range 51–99). Afghanistan Postal code lookup", "Country": "Afghanistan", "ISO": "AF", "Format": "NNNN", "Regex": "^\\d{4}$" }, { "Note": "With Finland, first two numbers are 22.", "Country": "Åland Islands", "ISO": "AX", "Format": "NNNNN", "Regex": "^\\d{5}$" }, { "Note": "Introduced in 2006, gradually implemented throughout 2007.", "Country": "Albania", "ISO": "AL", "Format": "NNNN", "Regex": "^\\d{4}$" }, { "Note": "First two as in ISO 3166-2:DZ", "Country": "Algeria", "ISO": "DZ", "Format": "NNNNN", "Regex": "^\\d{5}$" }, { "Note": "U.S. ZIP codes (range 96799)", "Country": "American Samoa", "ISO": "AS", "Format": "NNNNN (optionally NNNNN-NNNN or NNNNN-NNNNNN)", "Regex": "^\\d{5}(-{1}\\d{4,6})$" }, { "Note":
@AdamLJohnson
AdamLJohnson / KubernetesOnWindows.md
Last active September 4, 2023 07:28
How to get Kubernetes running on Windows 10

Kubernetes On Windows

Early in August 2016 Microsoft released the Windows 10 Anniversary Update. There were a number of changes, but the one that got me to actually take the time to install the update was "Bash on Ubuntu on Windows". This feature would install Ubuntu Linux without the kernel. It would run linux in user-mode. Linux would run the commands while Windows does all the work/processing.

For an upcoming project I needed to get Kubernetes running. Being as Kubernetes is not able to be run in Windows the normally accepted way to procees is to create a virtual Linux box and run it from there. I wanted to see if Kubernetes would run in Bash on Ubuntu on Windows.

This is how I got it to work:

Install the Windows 10 Anniversary Update

@AdamLJohnson
AdamLJohnson / OpenWithSublimeText3.bat
Created August 2, 2016 16:33 — forked from roundand/OpenWithSublimeText3.bat
Open folders and files with Sublime Text 3 from windows explorer context menu (tested in Windows 7)
@echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@AdamLJohnson
AdamLJohnson / RecursiveSetProperty.cs
Last active February 29, 2016 18:59
Recursive SetProperty
using System;
using System.Linq;
using System.Reflection;
public class RecursiveSetProperty
{
/// <summary>
/// Sets the property of an object recursively.
/// </summary>
/// <param name="target">The target object.</param>
@AdamLJohnson
AdamLJohnson / FullDBBackup.ps1
Created February 9, 2016 17:57
Powershell script to backup all SQL Databases on a server. Useful for SQL Express.
$serverName = ".\SQLExpress"
$backupDirectory = "D:\backupSQL"
$daysToStoreDailyBackups = 7
$daysToStoreWeeklyBackups = 28
$monthsToStoreMonthlyBackups = 3
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null
@AdamLJohnson
AdamLJohnson / SetupASPvNext.sh
Last active December 30, 2015 17:15
Script to setup ASP.Net vNext on Ubuntu
#!/bin/sh
##https://docs.asp.net/en/latest/getting-started/installing-on-linux.html#installing-on-debian-ubuntu-and-derivatives
## Install the .NET Version Manager (DNVM)
sudo apt-get --assume-yes install unzip curl
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
# Install the .NET Execution Environment (DNX)
## Install the DNX prerequisites:
@AdamLJohnson
AdamLJohnson / GetAge.js
Created September 10, 2013 16:23
This function returns age when given a DOB.
//This function returns age when given a DOB. getAge(DOB)
//You can also get the age on a given date. getAge(DOB, onDate)
function getAge(d1, d2) {
d2 = d2 || new Date();
var diff = d2.getTime() - d1.getTime();
return Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25));
}
@AdamLJohnson
AdamLJohnson / proxy.cs
Created April 25, 2013 23:14
Create a proxy action to help with handling cross site scripting issues. Got the idea from: http://encosia.com/use-asp-nets-httphandler-to-bridge-the-cross-domain-gap/
public void proxy(string url)
{
WebClient wc = new WebClient();
string baseUrl = url;
string response = wc.DownloadString(baseUrl);
HttpContext.Response.ContentType = "application/json";
HttpContext.Response.Write(response);
}
@AdamLJohnson
AdamLJohnson / fizbuzz.cs
Created August 6, 2012 06:14
My FizzBuzz Test
private static string FizzBuzz(int i)
{
if ((i % 3 == 0) && (i % 5 == 0)) return "FizzBuzz";
else if (i % 3 == 0) return "Fizz";
else if (i % 5 == 0) return "Buzz";
else return i.ToString();
}
@AdamLJohnson
AdamLJohnson / T4TemplateChanges.cs
Created January 31, 2012 17:49
DBContext T4 Template changes for Key Required StringLength Attributes
// Add at the top with the other Usings
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
//Add following methods inside the file
private bool IsNullable(TypeUsage usage)
{
return (bool)usage.Facets.First(facet => facet.Name == "Nullable").Value;
}