Skip to content

Instantly share code, notes, and snippets.

@andy-uq
andy-uq / GuidHelper.cs
Last active September 29, 2015 23:27
Creates GUID combs
using System;
namespace Terabyte.Data
{
/// <summary>Guid utilities</summary>
public static class GuidHelper
{
/// <summary>Given a string returns a Guid. </summary>
/// <remarks> Returns <c>Guid.Empty</c> if s is null.</remarks>
/// <param name="s">Any parsable guid, or the return value from <see cref="GuidToString"/></param>
@andy-uq
andy-uq / umbracoNodeTree.sql
Created February 2, 2012 21:16
Returns the umbraco node tree and all descendants
DECLARE @nodeId uniqueidentifier
SELECT @nodeId = 0 -- Put your node Id here
WITH NodeTree(ID, ParentID, [Level])
AS
(
-- The immediate Node we're getting (which will be excluded in the final query)
SELECT a.ID, a.ParentID, 0
FROM Node a
WHERE ID = @nodeId
@andy-uq
andy-uq / Placeholder.cs
Last active December 28, 2015 07:19
A simple placeholder content generator that can be switched between alternate providers. http://nightmage-blog.azurewebsites.net/simple-content-generator/
public static class Placeholder
{
private static readonly ILoremContent Lorem = new ZombieLorem();
private static readonly ILoremContent AlternateLorem = new KittenLorem();
private static readonly Random _random = new Random();
public static string ImageUrl(int width, int height = 0)
{
if ( height == 0 )
@andy-uq
andy-uq / clone.cmd
Created December 4, 2013 04:04
Create a bare repository
git clone file://%1
@andy-uq
andy-uq / Program.cs
Created July 24, 2014 21:51
Umbraco Security Patch
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace PatchLiveServer
{
class Program
{
@andy-uq
andy-uq / Upsert.sql
Last active August 29, 2015 14:05
SQL Server UPSERT
MERGE CasualRosterAllocation AS D
USING
(
SELECT x.Id, Date, Shift.Id AS ShiftId, Casual.Id AS CasualId, PlaceHolderCount,
(SELECT MAX(RosterAllocationHeader.Id)
FROM RosterDetail
INNER JOIN RosterAllocationHeader ON RosterAllocationHeader.RosterId = RosterDetail.Id
WHERE RosterDetail.Guid=RosterGuid) AS RosterAllocationHeaderId
FROM (VALUES (@0, @1, @2, @3, @4, @5)) x (Id, RosterGuid, Date, ShiftGuid, CasualGuid, PlaceHolderCount)
INNER JOIN Shift ON Shift.Guid = ShiftGuid
@andy-uq
andy-uq / Fix user.sql
Created August 15, 2014 02:34
Repair SQL orphaned users
EXEC sp_change_users_login 'Auto_Fix', 'user'
@andy-uq
andy-uq / README.md
Last active August 29, 2015 14:20 — forked from mbostock/.block
@andy-uq
andy-uq / GetBuildDirectory.cs
Last active August 29, 2015 14:20
Return the current solution directory, useful for tests
public static string GetBuildDirectory()
{
var solution = Environment.GetEnvironmentVariable("NCrunch.OriginalSolutionPath");
if (!string.IsNullOrEmpty(solution))
return Path.GetDirectoryName(solution);
var teamCityLocation = Environment.GetEnvironmentVariable("teamcity.build.checkoutDir");
if (!string.IsNullOrEmpty(teamCityLocation))
{
return teamCityLocation;
CAST(CAST(newid() AS binary(10)) + CAST(GETDATE() AS binary(6)) AS uniqueidentifier)