Skip to content

Instantly share code, notes, and snippets.

@craigtp
craigtp / GuidToShortGuid.cs
Created Feb 20, 2012
Convert a GUID to a smaller (unique) GUID
View GuidToShortGuid.cs
public static string GuidToShortGuid(Guid gooid)
{
string encoded = Convert.ToBase64String(gooid.ToByteArray());
encoded = encoded.Replace("/", "_").Replace("+", "-");
return encoded.Substring(0, 22);
}
@craigtp
craigtp / remove_svn.bat
Created Mar 13, 2012
Recursively remove all .svn folders - Windows
View remove_svn.bat
for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (
rd /s /q "%%i"
)
@craigtp
craigtp / .hgignore
Last active Dec 5, 2017
Standard Visual Studio .hgignore file for Mercurial
View .hgignore
syntax: glob
*.suo
*.obj
*.pdb
*.user
*.vspscc
*.bak
*.cache
*.log
*.lib
@craigtp
craigtp / LargestDBs
Last active Aug 30, 2016
List the largest databases on a SQL Server instance
View LargestDBs
SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024 SizeMB
FROM sys.master_files
ORDER BY SizeMB DESC
@craigtp
craigtp / FizzBuzz.cs
Last active Oct 8, 2015
FizzBuzz - 3 ways
View FizzBuzz.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
@craigtp
craigtp / ShortCodes.cs
Last active Mar 21, 2017
Short code generator.Converts a long integer to a "short code" (a seemingly random string of characters - as seen on many popular URL Shortener utilities.) and vice-versa.See: http://stackoverflow.com/a/529852/57477
View ShortCodes.cs
using System;
namespace ShortCodes
{
public static class ShortCodes
{
// You may change the "shortcode_Keyspace" variable to contain as many or as few characters as you
// please. The more characters that are included in the "shortcode_Keyspace" constant, the shorter
// the codes you can produce for a given long.
private static string shortcodeKeyspace = "abcdefghijklmnopqrstuvwxyz0123456789";
@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
@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 / 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
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;
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.