Skip to content

Instantly share code, notes, and snippets.

public class TestController : Controller
{
public ActionResult Index()
{
return View("Index").WithStatus("Some message");
}
}
public static class StatusResultExtensions
{
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 MainViewModel : ViewModelBase
{
public MainViewModel()
{
ActivityProcessor processor = new ActivityProcessor();
GetUnicornsCommand = processor.CreateCommand(GetUnicorns).WithContinuation(HandleGetUnicornErrors);
}
IEnumerable<IActivity> GetUnicorns()
{
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.
}
@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)
{
@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 / 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 / Cell.cs
Created April 13, 2013 16:21
Game of life in C#
using System.Collections.Generic;
namespace GameOfLife1
{
struct Cell
{
public Cell(int x, int y) : this()
{
Y = y;
X = x;
@joshka
joshka / ExceptionalFibonacciCalculator.cs
Created August 2, 2014 05:17
Calculate Fibonacci by using parallel tasks and aggregate exceptions. I did it for the cookie.
using System;
using System.Threading.Tasks;
namespace Fib
{
class ExceptionalFibonacciCalculator
{
public int Calculate(uint n)
{
try
@joshka
joshka / .AURINFO
Last active August 29, 2015 14:06
plexmediaserver-plexpass archilinux package
pkgbase = plexmediaserver-plexpass
pkgdesc = PlexPass Release of Plex Media Server for Linux
pkgver = 0.9.10.1.585
pkgrel = 1
url = http://www.plexapp.com
install = plexmediaserver.install
arch = i686
arch = x86_64
license = closed
depends = rsync