Skip to content

Instantly share code, notes, and snippets.

Craig Phillips craigtp

Block or report user

Report or block craigtp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@craigtp
craigtp / CleanUpTemporaryASPNETFiles.ps1
Last active Apr 29, 2016
Clean Up Temporary ASP.NET Files with Powershell
View CleanUpTemporaryASPNETFiles.ps1
# Run this as Administrator
net stop w3svc
Get-ChildItem "C:\Windows\Microsoft.NET\Framework*\v*\Temporary ASP.NET Files" -Recurse | Remove-Item -Recurse -Force
net start w3svc
@craigtp
craigtp / HGAutoUpdate
Created Jun 18, 2015
Recurse all folders beneath the current folder for Mercurial repositories and perform a "hg pull -u" on each repo.
View HGAutoUpdate
dir -Directory -Recurse | ? { test-path (join-path $_.FullName ".hg\hgrc") } | % { $_.FullName; Set-Location -Path $_.FullName; iex "hg pull -u" }
@craigtp
craigtp / .gitignore
Last active Nov 29, 2017
Standard Git gitignore file
View .gitignore
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
*.sln.ide/
.vs/
@craigtp
craigtp / BreakIntegerToConstituentDigits.cs
Created Feb 2, 2015
Break an integer number into it's constituent digits.
View BreakIntegerToConstituentDigits.cs
using System;
public class Program
{
public static void Main()
{
var result = BreakToDigits(56);
}
public static int[] BreakToDigits(int startingNumber)
@craigtp
craigtp / LineCount.ps1
Last active Aug 29, 2015
Count number of non-blank lines in files with PowerShell
View LineCount.ps1
(dir -include *.cs -recurse | select-string .).Count
View BubbleBabble.cs
public static class BubbleBabble
{
private static readonly string vowels = "aeiouy";
private static readonly string consonants = "bcdfghklmnprstvzx";
public static string Convert(byte[] bytes)
{
int seed = 1;
int rounds = 1 + bytes.Length / 2;
StringBuilder result = new StringBuilder();
View NotNull
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Bleroy.Helpers {
public static class NotNull {
public static TProp Get<TSource, TProp>(this TSource source, Expression<Func<TSource, TProp>> property) where TSource : class {
if (source == null) return default(TProp);
var current = property.Body;
@craigtp
craigtp / BetterRandom.cs
Last active Jun 13, 2018
BetterRandom - A C# class to produce random numbers which inherits from the .NET framework's System.Random class and so can be a drop-in replacement for usages of the standard Random class, but which uses the RNGCryptoServiceProvider to generate better (and cryptographically secure) random numbers.
View BetterRandom.cs
using System;
using System.Security.Cryptography;
namespace BetterRandomNumbers
{
// BetterRandom.cs
// This class implements a random number generator that is based off the Windows "Next Generation" cryptographically secure
// random number generator. It inherits from the base Random class, so can be used as a "drop-in" replacement for the
// built-in .NET System.Security.Random class, but providing a superior quality of random numbers.
public class BetterRandom : Random, IDisposable
@craigtp
craigtp / NumberFunctions.cs
Last active Dec 20, 2015
A C# IsNumeric function, written as an extension method.
View NumberFunctions.cs
using System;
using System.Globalization;
namespace NumberFunctionUtilities
{
public static class NumberFunctions
{
public static bool IsNumeric(this object expression)
{
if (expression == null)
@craigtp
craigtp / SQLRandom.sql
Created Feb 7, 2013
SQL Server Random Numbers And Other Things!
View SQLRandom.sql
-- Create a temporary table in an in-memory variable simply to allow the
-- select statement to output multiple rows.
DECLARE @TestTable TABLE (uniqueID int)
INSERT INTO @TestTable
SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL
SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
-- The main Select statement that shows different correct (and incorrect) ways to generate
-- "random" things in a set-based select statement.
SELECT
You can’t perform that action at this time.