Skip to content

Instantly share code, notes, and snippets.

@brenoferreira
brenoferreira / fakehttpcontext.cs
Created July 23, 2012 16:31
Fake HttpContext.Current
class PrincipalStub : IPrincipal
{
public IIdentity Identity
{
get { return new IdentityStub(); }
}
public bool IsInRole(string role)
{
@brenoferreira
brenoferreira / ObservableCollection
Created January 24, 2013 18:54
Incomplete ObservableCollection with Rx
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
namespace ReactiveExtensions.Rx
{
public class ObservableCollection<T> : IList<T>, System.IObservable<T>
{
private IList<T> list;
private IList<IObserver<T>> observers;
def test():
T = []
T.append("it is what it is")
T.append("what is it")
T.append("it is a banana")
ii = inverseIndex(T)
for i in ii:
print(i)
@brenoferreira
brenoferreira / ResharperNUnitTestClassTemplate
Last active December 20, 2015 02:18
NUnit Test method and class template for Resharper
public class $ClassName$
{
[NUnit.Framework.Test]
public void $name$()
{
$END$
}
}
static class EnumEx
{
public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> list, int maxItemsByPart)
{
return SplitImpl(list, maxItemsByPart, 0, new List<IEnumerable<T>>());
}
public static IEnumerable<IEnumerable<T>> SplitImpl<T>(
IEnumerable<T> list,
int maxItemsByPart,
class Async
{
static IEnumerable<Uri> uris = new List<Uri>()
{
new Uri("http://www.google.com"),
new Uri("http://www.bing.com"),
new Uri("http://www.yahoo.com")
};
public static void DownloadStringAsync()
@brenoferreira
brenoferreira / ShuffleIEnumerable.cs
Created November 4, 2013 18:19
Shuffle IEnumerable extension method using Fisher–Yates shuffle algorithm (http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle)
public static class EnumerableEx
{
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> enumerable)
{
var array = enumerable.ToArray();
var random = new Random(DateTime.Now.Millisecond);
for (int i = array.Length - 1; i >= 1; i--)
{
@brenoferreira
brenoferreira / propnotif
Created November 5, 2013 13:31
Resharper template for INotifyPropertyChanged class property
private $Type$ $FieldName$;
public $Type$ $PropertyName$
{
get
{
return $FieldName$;
}
set
{
@brenoferreira
brenoferreira / TDC2014.scala
Created August 20, 2014 21:12
Demo for presentation given at TDC2014 SP. Simply paste it into a Scala Worksheet.
import scala.util.{Try, Success, Failure}
def div = (x:Int, y:Int) => x / y
div(4, 2)
type Enumerable[T] = () => () => Option[T]
def empty[T]:Enumerable[T] = {
() => () => None
}
//use read-only properties
class MyClass {
public int Prop1 { get; private set; }
public float Prop2 { get; private set; }
}
//GENERATED
class MyClass {
public int Prop1 { get; private set; }