Skip to content

Instantly share code, notes, and snippets.

View JayBazuzi's full-sized avatar

Jay Bazuzi JayBazuzi

View GitHub Profile
class DateTimeHelpers
{
public static readonly DateTime Tomorrow;
static DateTimeHelpers()
{
Thread.Sleep(24*60*60*1000);
Tomorrow = DateTime.Now;
}
}
#
# keep this in synch with TeamBuild.proj
#
$ResharperCltVersion='8.2.0.2151'
# UseBasicParsing is required if IE has never been run on the machine.
wget -UseBasicParsing chocolatey.org/install.ps1 | iex
if (!$?) { throw "failed to install chocolatey"}
cinst resharper-clt.portable -version $ResharperCltVersion
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionPath>InspectCodeExample\InspectCodeExample.sln</SolutionPath>
</PropertyGroup>
<PropertyGroup>
<!-- keep this in synch with Tools\PreBuild.ps1 -->
<ResharperCltVersion>8.2.0.2151</ResharperCltVersion>
@JayBazuzi
JayBazuzi / ValueTypeAssertions.cs
Created May 27, 2014 04:32
Asserts that this type correctly implements "value" equality semantics.
static class ValueTypeAssertions
{
class C
{
}
/// <summary>
/// Asserts that this type correctly implements "value" equality semantics.
/// </summary>
/// <param name="a">An example of T</param>
using (progress.Start(4 + items.Count()))
{
DoWork();
progress.ReportWork();
DoHeavyLifting(items);
progress.ReportWork(items.Count());
DoMoreWork();
progress.ReportWork(3);
@JayBazuzi
JayBazuzi / ExpensiveFactAttribute.cs
Last active August 29, 2015 13:57
Mark certain XUnit tests as "expensive" so they don't get run by default.
class ExpensiveFactAttribute : FactAttribute
{
public ExpensiveFactAttribute()
{
// remove this line to run these expensive tests
base.Skip = "Expensive";
}
}
Feature: Standard rules of Conway's Game of Life
Background:
Given Standard Conway's Game of Life Rules
Scenario Outline: A live cell
Given There are <neighborCount> live neighbors of a living cell
When the timer ticks
Then the cell will be <result>
@JayBazuzi
JayBazuzi / FizzBuzz4.cs
Created January 2, 2014 22:58
Using a delegate instead of a single-method interface
public string FizzBuzz(int i)
{
Func<int, string> number = x => x.ToString();
Func<int, string> fizz = x => "Fizz";
Func<int, string> buzz = x => "Buzz";
Func<int, string> fizzBuzz = x => "FizzBuzz";
return new[]
{
fizzBuzz, //15
@JayBazuzi
JayBazuzi / FizzBuzz3.cs
Created January 2, 2014 22:32
Replaced all conditionals with polymorphism
interface I
{
string Get(int i);
}
private class Fizz : I
{
public string Get(int i)
{
return "Fizz";
new Dictionary<int, string>
{
{ 3, "Fizz"},
{ 5, "Buzz"},
{15, "FizzBuzz"},
}
.Where(item => i % item.Key == 0)
.Select(item => item.Value)
.LastOrDefault() ?? i.ToString();