Skip to content

Instantly share code, notes, and snippets.

@wickedshimmy
wickedshimmy / gist:1690202
Created January 27, 2012 18:34 — forked from petejohanson/gist:1690043
Fun Friday Algorithm!
new[] {
new DateTime (2012, 01, 01, 13, 0, 0),
new DateTime (2012, 01, 01, 9, 0, 0),
new DateTime (2012, 01, 02, 1, 0, 0),
new DateTime (2012, 01, 02, 23, 10, 0),
}.OrderBy (dt => dt.Date)
.ThenByDescending (dt => dt);
class T : IEquatable<T> {
public sealed override int GetHashCode ()
{
return 4; // guaranteed to be random
}
public sealed override bool Equals (object o)
{
var t = o as T;
return t != null && Equals (t);
var $time = $('#details time'),
iso = /^(\d{4}|[+\-]\d{6})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3,}))?)?(?:(Z)|([+\-])(\d{2})(?::?(\d{2}))?))?/;
parse = function (date) {
var timestamp = Date.parse (date),
minutesOffset = 0,
s;
if (isNaN (timestamp) && (s = iso.exec (date))) {
if (s[8] !== 'Z') {
minutesOffset = +s[10] * 6- + (+s[11]);
@wickedshimmy
wickedshimmy / Dingus.cs
Created March 23, 2011 19:55
I think Moq rocks. But it's this far from being perfect:
class Mock<T> : Moq.Mock<T> where T : class {
public static implicit operator T(Mock<T> mock)
{
return mock == null ? null : mock.Object;
}
}
class Dingus<T> : Mock<T> where T : class {
public Dingus ()
{
git diff --name-only
@wickedshimmy
wickedshimmy / Levenshtein.cs
Created June 23, 2010 07:05
Damerau-Levenshtein algorithm in C#.
// Copyright (c) 2010, 2012 Matt Enright
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//