Skip to content

Instantly share code, notes, and snippets.

View simoneb's full-sized avatar

Simone Busoli simoneb

View GitHub Profile
@simoneb
simoneb / 1 - Test.cs
Last active September 3, 2015 21:44
KataPotter
[TestFixture]
public class Test : Calculator
{
[Test]
public void No_books_are_0()
{
Assert.AreEqual(0, Price());
}
[Test]
public static class Extensions
{
public static bool And(this IEnumerable<bool> bools)
{
return bools.Foldr(Expression.AndAlso, true);
}
public static T Foldr<T>(this IEnumerable<T> enumerable, Func<Expression, Expression, BinaryExpression> fold, T v)
{
foreach(var b in enumerable)
@simoneb
simoneb / costura.xml
Created November 21, 2011 15:57
Costura task
<UsingTask
TaskName="Costura.EmbedTask"
AssemblyFile="$(SolutionDir)[path to]\Costura.dll" />
<Target Name="AfterBuild">
<Costura.EmbedTask />
</Target>
@simoneb
simoneb / gist:1562857
Created January 4, 2012 23:36
Anagrams
IEnumerable<string> Anagrams(IEnumerable<char> input)
{
foreach (var c in input)
{
var except = input.Except(new[]{c});
if(except.Any())
foreach (var element in Anagrams(except))
yield return c.ToString() + element;
else
@simoneb
simoneb / gist:2508758
Created April 27, 2012 12:20
Async IO the simple way
using(var c = new WebClient())
{
c.DownloadStringCompleted += (_, r) => Console.WriteLine(r.Result);
c.DownloadStringAsync(new Uri("http://www.google.at"));
}
@simoneb
simoneb / parser.cs
Last active January 7, 2020 07:34
Simple dynamic command line arguments parser
class Options : DynamicObject
{
readonly IDictionary<string, object> inner = new ExpandoObject();
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (!inner.TryGetValue(binder.Name, out result))
result = false;
else
result = result != null ? new OptionValue(result.ToString()) : (dynamic)true;
@simoneb
simoneb / linqpad-nunitlite.cs
Created October 29, 2012 00:42
NUnitLite in LINQPad
void Main()
{
new NUnitLite.Runner.TextUI().Execute(new[]{"-noheader"});
}
// Define other methods and classes here
[Test]
public void SomeTest()
{
Assert.Pass();
@simoneb
simoneb / nunit-simple-test.cs
Last active December 11, 2015 08:48
A simple test
[Test]
public void OneSimpleTest()
{
var eightBall = new EightBall();
var answer = eightBall.ShouldIChangeJob();
Assert.That(answer, Is.True);
}
@simoneb
simoneb / nunit-simple-async-test.cs
Last active December 11, 2015 08:48
A simple async test
[Test]
public async void OneSimpleTest()
{
var eightBall = new EightBall();
var answer = await eightBall.ShouldIChangeJob();
Assert.That(answer, Is.True);
// why am I still here?
}
@simoneb
simoneb / nunit-simple-test-workaround.cs
Last active December 11, 2015 08:48
A simple test - workaround for async
[Test]
public void OneSimpleTest()
{
var eightBall = new EightBall();
Task<bool> answer = eightBall.ShouldIChangeJob();
answer.Wait();
Assert.That(answer.Result, Is.True);
}