Skip to content

Instantly share code, notes, and snippets.

@joshka
joshka / gist:5361561
Created April 11, 2013 07:59
replace lambda with method / class.method
class Foo
{
List<Person> _people = new List<Person>();
IEnumerable<Person> Drinkers()
{
return people.Where(p => p.Age >= 18);
}
IEnumerable<Person> Drinkers2()
{
@joshka
joshka / GroupingExtensions.cs
Created October 21, 2012 07:20
GroupByCount
// http://devlicio.us/blogs/derik_whittaker/archive/2012/10/20/how-to-split-a-list-into-chunks-fun-code.aspx
static class GroupingExtensions
{
public static IEnumerable<IEnumerable<T>> GroupByCount<T>(this IEnumerable<T> source, int count)
{
if (source == null) throw new ArgumentNullException("source");
return GroupByCountIterator<T>(source, count);
}
@joshka
joshka / StubDataTable.cs
Created March 12, 2011 14:03
A C# implementation of Stub for DataTable creation as a test helper.
using System;
using System.Collections;
using System.Data;
namespace TestDataTableBuilder
{
class Program
{
static void Main(string[] args)
{
public static class ClassToBeTested
{
public static void DoSomething(int input, AnotherCrazyPublicStaticClass staticClass)
{
var result = staticClass.MethodToBeMocked(input); // go hit the database, network, web services, file and everything else you can imagine.
// now some business logic that I want to test
// 400 lines of code
// if result is blah do x otherwise do y
// 20 foreach loops each one with 2 nested loops and 10 if conditions.
}
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
ActivityProcessor processor = new ActivityProcessor();
GetUnicornsCommand = processor.CreateCommand(GetUnicorns).WithContinuation(HandleGetUnicornErrors);
}
IEnumerable<IActivity> GetUnicorns()
{
private static IEnumerable<TSource> SkipWhileImpl<TSource>(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
using (IEnumerator<TSource> iterator = source.GetEnumerator())
{
do
{
if (!iterator.MoveNext())
yield break;
public class TestController : Controller
{
public ActionResult Index()
{
return View("Index").WithStatus("Some message");
}
}
public static class StatusResultExtensions
{