Skip to content

Instantly share code, notes, and snippets.

@ilkerde
ilkerde / gist:838709
Created February 22, 2011 14:08
I wonder whether introducing such an extension is considered a smell. For me it's most likely a smell.
using System;
namespace Is.This.A.Smell {
public static class EnumExtensions {
public static string AsString(this Enum e) {
return Enum.GetName(e.GetType(), e);
}
}
}
@ilkerde
ilkerde / gist:842040
Created February 24, 2011 10:44
A quick, unprofessional and not too serious draft for a triple plus operator in C# :)
public void TriplePlus()
{
int coffee = 0;
// constant linear growth by 1 on every access until reset
IEnumerable<int> drink = coffee+++;
var enjoy =
from slurp in drink
where slurp <= 100
@ilkerde
ilkerde / gist:854714
Created March 4, 2011 14:55
An ordinary mspec using mfakes... however...
using Machine.Fakes;
using Machine.Specifications;
namespace MFakesTest {
public class when_using_mfakes_via_nuget_package_manager : WithSubject<Anything> {
private It should_run_fine
= () => Subject.True.ShouldBeTrue();
Because of_using_mfakes
= () => Subject.True = true;
@ilkerde
ilkerde / powershell_style
Created March 4, 2011 16:06
Finding out the "latest" (highest) revision of a local TFS workspace (aka tfs whereami)
(tf localversions . /recursive|?{$_ -match ".*;C.*"}|%{$_ -replace ".*;C",""}|group|%{$_.name}|sort -desc)[0]
@ilkerde
ilkerde / gist:864508
Created March 10, 2011 17:26
What do you think about the type signature of this method ?!?
public IEnumerable<Answer> GetAll()
{
List<Answer> answers = GetAnswers();
return answers;
}
@ilkerde
ilkerde / gist:884012
Created March 23, 2011 21:18
Canonical (absolute) path of a running BASH script
SCRIPT=$(realname -f $0)
SCRIPTPATH=`dirname $SCRIPT`
@ilkerde
ilkerde / Foo.rb
Created March 25, 2011 22:53
RSpec mocking of existing methods in Ruby?!?
class Foo
def bar(n)
return gin n
end
def gin(n)
return n+1
end
end
@ilkerde
ilkerde / ShouldContainAssertionBehavior.cs
Created March 31, 2011 07:40
What do you expect? Fail or Pass? Me expects Fail!
/* Question:
What do you expect from assertion below? Fail or Pass?
*/
List<string> aList = new List<string> { "any" };
List<string> anEmptyList = new List<string>();
aList.ShouldContain(anEmptyList); // this currently passes!
@ilkerde
ilkerde / omgequals.cs
Created April 15, 2011 22:29
Introducing: The OMG-EQUALS operator!
/*
There's this very pleasant and fulfilling moment in every developer's life
when it comes to comparing values. Especially testing for equality sometimes
is full of emotions. Sometimes, you don't want to "just simply" check if
values are equal. You want more. You want to express enthusiasm! Emotion!
Yeah, right, equals! You want
___ __ __ ____ _____ ___ _ _ _ _ ____
/ _ \| \/ |/ ___| | ____/ _ \| | | | / \ | | / ___|
| | | | |\/| | | _ | _|| | | | | | |/ _ \ | | \___ \
@ilkerde
ilkerde / WithForki.ps1
Created August 26, 2011 14:39
A quick prototype for a shallow copy of an object with changing values ;-)
add-type @"
using System;
using System.Linq;
public class A {
public A() { Age = 40; Name = "DerAlbert"; Type = "Original"; }
public int Age { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public A With(object o) {