Skip to content

Instantly share code, notes, and snippets.

@jonsagara
jonsagara / SampleStruct.cs
Created May 7, 2011 21:02
Sample immutable struct that shows how to override Equals and GetHashCode, as well as the == and != operators
/// <summary>
/// Sample struct that shows how to override GetHashCode and Equals, as well as the == and !=
/// operators.
/// </summary>
/// <remarks>
/// This type is immutable.
/// </remarks>
public struct SampleStruct
{
#region Private Backing Fields
@jonsagara
jonsagara / Pinger.ps1
Created May 26, 2011 06:02
Pinger - Repeatedly pings the specified server until the ping is successful.
# -------------------------------------------------------------------------------------------------
# Pinger.ps1
#
# Repeatedly pings the specified server until the ping is successful.
# -------------------------------------------------------------------------------------------------
# Script params
param([String]$server)
# Script param validation
@jonsagara
jonsagara / SystemTime.cs
Created June 16, 2011 17:51
Abstracting DateTime.Now and DateTime.UtcNow
public static class SystemTime
{
public static Func<DateTime> Now = () => DateTime.Now;
public static Func<DateTime> UtcNow = () => DateTime.UtcNow;
}
@jonsagara
jonsagara / EmptyGuid.sql
Last active December 3, 2023 09:15
Generating Guid.Empty in SQL Server
--
-- 2021-11-24: suggestion from comments:
--
DECLARE @EmptyEmpty UNIQUEIDENTIFIER = CAST(0x0 AS UNIQUEIDENTIFIER)
SELECT @EmptyEmpty
--
-- Original
--
@jonsagara
jonsagara / .gitignore
Last active April 7, 2022 15:10
My minimalist .gitignore file for Visual Studio 2010
# Visual Studio
*.[Oo]bj
[Bb]in/
[Oo]bj/
*.suo
*.user
*.[Pp]ublish.xml
*.dbmdl
Import Schema Logs/
src/{DATABASE_PROJECT_NAME}/sql/*
@jonsagara
jonsagara / LuceneNetDemo.cs
Created December 20, 2011 17:31
Bare bones Lucene.net console application
using System;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
@jonsagara
jonsagara / PsSvnBackup.ps1
Created April 12, 2012 19:42
PowerShell Hot Copy Backup of Subversion repositories
# -------------------------------------------------------------------------------------------------
# Does a hot copy backup of all Subversion repositories.
# -------------------------------------------------------------------------------------------------
$hotCopySource = "C:\Subversion\Repositories"
$hotCopyDest = "C:\SubversionBackups"
$svnadmin_exe = "C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe"
$7za_exe = "C:\Subversion\7za.exe"
if ([IO.Directory]::Exists($hotCopyDest)) {
/// <summary>
/// Checks to see if source is in the items collection.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="items"></param>
/// <returns></returns>
public static bool In<T>(this T source, params T[] items)
{
if (items == null)
@jonsagara
jonsagara / LinqExtensions.cs
Created September 16, 2012 17:16
IQueryable<T> Extensions
public static class LinqExtensions
{
public static IOrderedQueryable<TSource> OrderBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, bool isAscending)
{
return isAscending
? source.OrderBy(keySelector)
: source.OrderByDescending(keySelector);
}
public static IOrderedQueryable<TSource> ThenBy<TSource, TKey>(this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, bool isAscending)
@jonsagara
jonsagara / SqlVersionToByteArray.cs
Created July 3, 2013 15:55
Convert a SQL Server version to a byte array in C#
var hexNum = "0x000000000000E295";
long result;
long.TryParse(
hexNum.Substring(2),
System.Globalization.NumberStyles.HexNumber | System.Globalization.NumberStyles.AllowHexSpecifier,
System.Globalization.CultureInfo.CurrentCulture,
out result
);
//result.Dump();
var resultBytes = BitConverter.GetBytes(result);