Skip to content

Instantly share code, notes, and snippets.

try
{
return IsTrue(val);
}
catch
{
return IsFalse(val);
}
// moar koad
@skoon
skoon / IRoboCop.cs
Created September 9, 2011 08:15 — forked from grumpydev/IRoboCop.cs
public interface IJudgeDread
{
void IAmTheLaw();
}
public interface IRoboCop : IJudgeDread
{
void ServeThePublicTrust();
using System;
using System.Collections.Generic;
namespace MostlyScottish {
//This is what I think we should move towards
public interface IRepository<T> {
void Save(T entity);
}
@skoon
skoon / GenericTryParse.cs
Created May 10, 2011 06:16
First crack at trying a generic TryParse method.
public static T TryParse<T>(this string stringToParse) {
if (typeof(T).HasMethod("TryParse")) {
var m = typeof(T).GetMethod("TryParse", new Type[] { typeof(string), typeof(T).MakeByRefType() });
T outParam = Activator.CreateInstance<T>();
object[] ps = new object[] { stringToParse, outParam };
bool result = (bool)m.Invoke(null, ps);
if (result)
return (T)ps[1];
}
return default(T);
@skoon
skoon / ScrewturnPageKeyword.cs
Created March 16, 2011 19:45
So this is what I had to do to get a composite key to work
public class ScrewturnPageKeyword
{
private int? _hashCode;
public virtual string Page { get; set; }
public virtual string Namespace { get; set; }
public virtual int Revision { get; set; }
public virtual string Keyword { get; set; }
public override bool Equals(object obj)
@skoon
skoon / Fluent Nhibernate composite key problem
Created March 16, 2011 18:57
When I try to save an entity using this mapping, I'm told that the CompositeId class must override "Equals". Which seems like a pain.
public class PageKeywordMappings : ClassMap<ScrewturnPageKeyword>
{
public PageKeywordMappings()
{
Table("PageKeyword");
CompositeId()
.KeyProperty(m => m.Page)
.KeyReference(m => m.Keyword)
.KeyReference(m => m.Namespace);
Map(m => m.Namespace);
@skoon
skoon / find.js
Created December 27, 2010 23:39 — forked from creationix/find.js
function find(root, obj) {
var seen = [];
function search(root, name, depth) {
if (root === obj) {
console.log(name);
return;
}
if (!depth) { return; }
if (seen.indexOf(root) >= 0) { return; }
if (typeof root !== "object") { return; }
using Xunit;
using VirtualRoundtableData;
using System;
using Models;
namespace UnitTests
{
public class when_using_the_user_repository: TestBase
{
// I'm implementing a reusable library for the Scheduler-Agent-Supervisor pattern blogged about by Clemens Vaster's here:
// http://vasters.com/clemensv/2010/09/28/Cloud+Architecture+The+SchedulerAgentSupervisor+Pattern.aspx
// I'm starting my work on the communication between the Scheduler and the Agent's. This will be (for now) done via
// WCF and leverage MSMQ for elasticity. The Scheduler has a request queue and a response queue. This is the first
// draft of the Scheduler class which implements both queue WCF endpoints as well as some helper functions for client creation.
// Because of Task<T> this helps facilitate the DataContractResolver away from the user of the library.
using System;
using System.Messaging;
@skoon
skoon / aspHide
Created October 15, 2010 00:17 — forked from buzzedword/gist:627318
jQuery.fn.aspHide = function() {
$(this).each(function() {
var elem = $(this);
elem.data('height', elem.height());
elem.height('0');
elem.css('visibility', 'hidden');
});
};
jQuery.fn.aspShow = function() {