Skip to content

Instantly share code, notes, and snippets.

View imbaker's full-sized avatar

Ian Baker imbaker

View GitHub Profile
@imbaker
imbaker / gist:7585590
Last active December 29, 2015 00:19
UK Phone Numbers Regular Expression
^\s*(\+[0-9]{2} ?|0)2[0-9] ?[1-9][0-9]{3} ?[0-9]{4}|(\+[0-9]{2} ?|0)1[0-9]{3} ?[1-9][0-9]{4,5}|(\+[0-9]{2} ?|0)1[0-9]{4} ?[1-9][0-9]{3,4}|(\+[0-9]{2} ?|0)1[0-9]1 ?[1-9][0-9]{2} ?[0-9]{4}|(\+[0-9]{2} ?|0)11[0-9] ?[1-9][0-9]{2} ?[0-9]{4}|(\+[0-9]{2} ?|0)7[4-9][0-9]{2} ?[0-9]{6}\s*$
@imbaker
imbaker / gist:9110185
Created February 20, 2014 09:45
Single line string to int conversion
int c = int.TryParse("1", out c) ? c : 0;
@imbaker
imbaker / gist:10734755
Last active August 29, 2015 13:59
Method to calculate a person's age at their next birthday
Private Function GetAgeNextBirthday(ByVal dateOfBirth As Date, ByVal asOfDate As Date) As Integer
Dim dateOfBirthmmdd As Integer = Format(dateOfBirth, "yyyyMMdd")
Dim asOfDatemmdd As Integer = Format(asOfDate, "yyyyMMdd")
GetAgeNextBirthday = ((asOfDatemmdd - dateOfBirthmmdd) / 10000) + 1
End Function
@imbaker
imbaker / gist:10745152
Last active August 29, 2015 13:59
Method to calculate a person's age at their next birthday.
function getAgeNextBirthday(dateOfBirth, asOfDate) {
var dateOfBirthyyyymmdd = dateOfBirth.getFullYear().toString() + ('0'+(dateOfBirth.getMonth() + 1).toString()).slice(-2) + ('0'+dateOfBirth.getDate().toString()).slice(-2);
var asOfDateyyyymmdd = asOfDate.getFullYear().toString() + ('0'+(asOfDate.getMonth() + 1).toString()).slice(-2) + ('0',asOfDate.getDate().toString()).slice(-2);
return Math.floor((asOfDateyyyymmdd - dateOfBirthyyyymmdd) / 10000) + 1;
}
@imbaker
imbaker / EncodePassword.cs
Last active August 14, 2018 14:58
Code to encode passwords using the ASP.NET Membership provider method
// http://dotnetfiddle.net/wBqZSX
using System;
using System.Text;
using System.Security.Cryptography;
public class Program
{
public static void Main()
{
Console.WriteLine(EncodePassword("Pa55w0rd", "Gr6NjoLK1t89g4pwjmfC1g=="));
@imbaker
imbaker / IfNotNull
Created July 31, 2014 12:36
IfNotNull extension method
public static U IfNotNull < T, U > (this T t, Func <T, U> function)
{
return t != null ? function (t) : default (U);
}
@imbaker
imbaker / Program.cs
Created October 13, 2014 15:29
Encode Password
using System;
using System.Security.Cryptography;
using System.Text;
public class Program
{
public static void Main()
{
Console.WriteLine(EncodePassword("Pa55w0rd"));
}
@imbaker
imbaker / boxstarter.script
Last active August 29, 2015 14:14
Boxstarter
Update-ExecutionPolicy Unrestricted
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar
cinst -y notepadplusplus
cinst -y brackets
cinst -y dotpeek
cinst -y soapui
cinst -y fiddler4
@imbaker
imbaker / gist:036118c517478ecf83b3
Created April 16, 2015 08:37
Batch syntax to check parameters
rem SET Platform = %2
IF "%2" == "" (
REM Note spacing either side of equals is important (don't have it!)
SET Platform=Any CPU
)
echo 1: %1
echo 2: %2
echo 3: %Platform%
# http://eclipsesource.com/blogs/2014/03/27/mocks-in-jasmine-tests/
window.mock = (constr, name) ->
keys = []
console.log "!" + constr.prototype.length
for key in constr.prototype
keys.push key
if keys.length > 0
return jasmine.createSpyObj(name || "mock", keys)
else