Skip to content

Instantly share code, notes, and snippets.

View jchadwick's full-sized avatar

Jess Chadwick jchadwick

View GitHub Profile
@jchadwick
jchadwick / ControlCommand.cs
Created April 20, 2012 19:11
Facade for Cross-Queue MSMQ communication
public struct ControlCommand
{
public static readonly ControlCommand Message = 0;
private readonly int _value;
public ControlCommand(int value)
{
_value = value;
}
@jchadwick
jchadwick / JsonMessageFormatter.cs
Created April 20, 2012 18:47
MSMQ Message JSON Formatter
using System;
using System.IO;
using System.Messaging;
using System.Text;
using Newtonsoft.Json;
public class JsonMessageFormatter : IMessageFormatter
{
private static readonly JsonSerializerSettings DefaultSerializerSettings =
new JsonSerializerSettings {
@jchadwick
jchadwick / ConcurrentList.cs
Created April 19, 2012 18:11
Thread-safe List (ConcurrentList<T>)
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
public class ConcurrentList<T> : ICollection<T>
{
private readonly ConcurrentDictionary<T, object> _store;
@jchadwick
jchadwick / EventHandlerExtensions.cs
Created April 18, 2012 20:55
Extension Methods to make triggering event handlers easier
using System;
public static class EventHandlerExtensions
{
public static void SafeInvoke(this EventHandler handler, EventArgs args = null, object sender = null)
{
if (handler != null)
handler(sender, args ?? EventArgs.Empty);
}
@jchadwick
jchadwick / gist:2345865
Created April 9, 2012 19:25
IsAppHarbor
bool IsAppHarbor
{
get { return !string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["appharbor.commit_id"]); }
}
@jchadwick
jchadwick / HtmlHelperEnumExtensions.cs
Created April 5, 2012 20:55
ASP.NET MVC Enum Drop-Down List
using System.Web.Mvc;
using System.Web.Mvc.Html;
public static class HtmlHelperEnumExtensions
{
public static IHtmlString EnumDropDownListFor<TModel, TEnum>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TEnum>> field, TEnum selectedValue = default(TEnum))
where TEnum : struct
{
var name = (field.Body as MemberExpression).Member.Name;
@jchadwick
jchadwick / JsonRoleProvider.cs
Created April 4, 2012 19:36
Json Role Provider
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Script.Serialization;
public class Roles : List<Role>
{
public Roles(IEnumerable<Role> roles = null)
: base(roles ?? Enumerable.Empty<Role>())
@jchadwick
jchadwick / status.ps1
Created April 4, 2012 02:15
PowerShell Source Control Status
function status() {
if(Test-Path .svn) {
Write-Host
svn status
Write-Host
}
if(Test-Path .git) {
git status
}
@jchadwick
jchadwick / install.ps1
Created March 23, 2012 18:51
NuGet install.ps1 script that overwrites existing file
param($installPath, $toolsPath, $package, $project)
Write-Host "Setting Application to DowJones.Web.Mvc.HttpApplication..."
# Read the transformed text from the custom template included in the package
$customGlobalAsax = $project.ProjectItems | where { $_.Name -eq "Global.asax.cs.custom" }
$customGlobalAsax.Open()
$customGlobalAsax.Document.Activate()
$customGlobalAsax.Document.Selection.SelectAll();
$replacementGlobalAsax = $customGlobalAsax.Document.Selection.Text;
@jchadwick
jchadwick / UrlExtensions.cs
Created March 7, 2012 18:32
External URL Helpers
using System;
using System.Web;
using System.Web.Mvc;
public static class UrlExtensions
{
public static string ExternalAction(this UrlHelper url, string actionName, string controllerName, object routeValues = null)
{
var requestUrl = url.Action(actionName, controllerName, routeValues);
return ExternalUrl(url, requestUrl);