Skip to content

Instantly share code, notes, and snippets.

@dkarzon
dkarzon / StringExtensions.cs
Created April 13, 2011 04:36 — forked from lukencode/StringExtensions.cs
String Extensions
public static class StringExtensions
{
/// Like linq take - takes the first x characters
public static string Take(this string theString, int count, bool ellipsis = false)
{
int lengthToTake = Math.Min(count, theString.Length);
var cutDownString = theString.Substring(0, lengthToTake);
if (ellipsis && lengthToTake < theString.Length)
cutDownString += "...";
@dkarzon
dkarzon / AppEventsRuleTest
Created June 10, 2011 02:27
Testing Some AppEvents Rules
//Create a rule called "adsandrate"
//Run Do action when "appstart" is run more than 3 times
// and first run is over 5 days ago
//Run AskToRate() and ActivateAds() on rule fire
EventClient.New()
.Add(Rule.When("adsandrate",
el => el.Any(e => e.Name == "appstart"
&& e.Occurrrences.Count > 3
&& e.Occurrrences.Min() < DateTime.Now.AddDays(-5)))
@dkarzon
dkarzon / WCFDate.cs
Created June 29, 2011 03:08
Better handling of JSON formated DateTime in WCF
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
/// <summary>
/// Class to help get around the craziness of WCF DateTime formats (Use this class instead of DateTime for WebService Models)
/// </summary>
public class WCFDate
//in app.xaml.cs
public App()
{
//blah blah
BlobCache.LocalMachine = new IsolatedBlob();
}
//my blob class
public class IsolatedBlob : PersistentBlobCache
public interface IValueProvider
{
object GetValue();
}
public interface IProviderSelector
{
IValueProvider GetProvider(System.Reflection.PropertyInfo prop, List<IValueProvider> providers);
}
public class DataGen
@dkarzon
dkarzon / BlendDead.txt
Created October 15, 2012 02:01
Blend error
Application: Blend.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.UnauthorizedAccessException
Stack:
at System.Security.AccessControl.Win32.SetSecurityInfo(System.Security.AccessControl.ResourceType, System.String, System.Runtime.InteropServices.SafeHandle, System.Security.AccessControl.SecurityInfos, System.Security.Principal.SecurityIdentifier, System.Security.Principal.SecurityIdentifier, System.Security.AccessControl.GenericAcl, System.Security.AccessControl.GenericAcl)
at System.Security.AccessControl.NativeObjectSecurity.Persist(System.String, System.Runtime.InteropServices.SafeHandle, System.Security.AccessControl.AccessControlSections, System.Object)
at System.Security.AccessControl.NativeObjectSecurity.Persist(System.String, System.Security.AccessControl.AccessControlSections, System.Object)
at System.Security.AccessControl.NativeObjectSecurity.Persist(System.String, System.Security.AccessControl.AccessContro
@dkarzon
dkarzon / StackTraceFormatter.cs
Created January 8, 2013 23:29
Function to format a stack trace to HTML
public static string FormatStackTrace(string stacktrace)
{
try
{
var response = string.Empty;
var lines = stacktrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var rawline in lines)
{
var line = rawline.Trim();
@dkarzon
dkarzon / TFSBuild.proj
Created February 6, 2013 23:03
MSBuild script to create Octopus packages
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<DeployFiles>$(MSBuildStartupDirectory)\DeployFiles.msbuild</DeployFiles>
<VersionMajor>0</VersionMajor>
<VersionMinor>1</VersionMinor>
<VersionPatch></VersionPatch>
<BuildOutputDirectory>C:\Builds\Temp\RedStrike.Web</BuildOutputDirectory>
</PropertyGroup>
@dkarzon
dkarzon / BaseController.Helper.cs
Created June 11, 2013 23:20
Helper method for automatically returning a View or Json
protected ActionResult ViewOrJson(object model)
{
return ViewOrJson(null, model);
}
protected ActionResult ViewOrJson(string viewName, object model)
{
var useJson = false;
//check if its an API call
if (Request.Headers["Something"] != null)
@dkarzon
dkarzon / scriptthat1.csx
Last active December 27, 2015 15:29
mmbot scriptthat
var robot = Require<Robot>();
robot.Respond("updog", msg => msg.Send("What's up dog?"));