Skip to content

Instantly share code, notes, and snippets.

View danstuken's full-sized avatar

Dan Kendall danstuken

View GitHub Profile
@danstuken
danstuken / gist:1328431
Created October 31, 2011 18:47
Powershell Variables that Re-evaluate
PS C:\Program Files\Console2> $global:fred = Set-PSBreakpoint -Variable fred -Mode read -Action { $global:fred = Get-Date }
PS C:\Program Files\Console2> $fred
31 October 2011 18:42:59
PS C:\Program Files\Console2> $fred
31 October 2011 18:43:01
@danstuken
danstuken / gist:1278234
Created October 11, 2011 14:32
Ow My Eyes....
exec sp_executesql N'SELECT
CASE WHEN ([UnionAll26].[C76] = 1) THEN ''1X0X'' WHEN ([UnionAll26].[C77] = 1) THEN ''1X1X'' WHEN ([UnionAll26].[C78] = 1) THEN ''1X2X'' WHEN ([UnionAll26].[C79] = 1) THEN ''1X3X'' WHEN ([UnionAll26].[C92] = 1) THEN ''1X4X'' WHEN ([UnionAll26].[C80] = 1) THEN ''1X5X'' WHEN ([UnionAll26].[C81] = 1) THEN ''1X6X'' WHEN ([UnionAll26].[C73] = 1) THEN ''1X7X'' WHEN ([UnionAll26].[C98] = 1) THEN ''1X8X'' WHEN ([UnionAll26].[C82] = 1) THEN ''1X9X'' WHEN ([UnionAll26].[C99] = 1) THEN ''1X10X'' WHEN ([UnionAll26].[C93] = 1) THEN ''1X11X'' WHEN ([UnionAll26].[C83] = 1) THEN ''1X12X'' WHEN ([UnionAll26].[C84] = 1) THEN ''1X13X'' WHEN ([UnionAll26].[C85] = 1) THEN ''1X14X'' WHEN ([UnionAll26].[C86] = 1) THEN ''1X15X'' WHEN ([UnionAll26].[C87] = 1) THEN ''1X16X'' WHEN ([UnionAll26].[C88] = 1) THEN ''1X17X'' WHEN ([UnionAll26].[C94] = 1) THEN ''1X18X'' WHEN ([UnionAll26].[C74] = 1) THEN ''1X19X'' WHEN ([UnionAll26].[C75] = 1) THEN ''1X20X'' WHEN ([UnionAll26].[C89] = 1) THEN ''1X21X'' WHEN ([Uni
@danstuken
danstuken / gist:1278039
Created October 11, 2011 13:14
Possible caching data reader.
public static SomeEntity Get(string someEntityIdentifier)
{
return Cache.Get(string.Format("MyCacheKey_{0}", someEntityIdentifier), CacheFrequency.Daily, () =>
{
Entity result = null;
DataManager.ReadFromStoredProcedure("some_entity_fetching_stored_proc", new Dictionary<string, object>
{
{"@id", someEntityIdentifier },
}, reader =>
@danstuken
danstuken / gist:1195650
Created September 5, 2011 18:46
Simple Cyclical JsonFx Test
namespace JsonFx.Xml
{
using System.Xml.Serialization;
using Resolvers;
using Serialization;
using Xunit;
public class XmlReaderTests
{
public class Person
@danstuken
danstuken / SimpleJsonFxTest.cs
Created September 5, 2011 18:22
Simple JsonFx Example
[TestFixture]
public class SomeTests{
[Test]
public void SimpleSingleItemDecodeTest()
{
var xml = " <subscription-plan>"
+ " <name>Plan 3</name>"
+ " <id type=\"integer\">3</id>"
+ " </subscription-plan>";
[TestCase("/categoryName/itemname", "/sitebaseaddress/hub/categoryName.aspx")]
public void GetDestinationUrl_ValidUrls_ReturnsCorrectDestionation(string url, string expected)
{
var cacheHandler = new Mock<IMappingCacheHandler>();
var httpContext = new Mock<IHttpContextFacade>();
var target = new DataMap(null, cacheHandler.Object, httpContext.Object);
var mappings = new List<Data>();
string baseUrl = "/sitebaseaddress/";
cacheHandler.Setup(ch => ch.Load<Data>()).Returns(mappings);
cacheHandler.Setup(ch => ch.Save(It.IsAny<List<Data>>()));
@danstuken
danstuken / firstcharuppercase.cs
Created May 13, 2011 09:37
uppercase first char in string
public static string ToBindingTypeName(this string bindingName)
{
var firstChar = new string(new[] {bindingName.First()}).ToUpper();
return firstChar + new string(bindingName.Skip(1).ToArray());
}