Skip to content

Instantly share code, notes, and snippets.

View codereflection's full-sized avatar

Jeff Schumacher codereflection

View GitHub Profile
@codereflection
codereflection / Funcs Only Please Redux.cs
Created June 23, 2011 16:24
Which is most readable for determining the business logic?
public IList<Trade> GetComplianceReportTradesBy(ComplianceStatus complianceStatus)
{
return GetBy(
x => x.ComplianceStatus == complianceStatus.ToString()
&& x.RecordType == TradeRecordType.ClientAllocation.ToString()
&& x.ComplianceExported == false
&& x.LineOfBusiness != LinesOfBusiness.SO.ToString()
&& x.Canceled == false
&& x.AddBust == "ADD")
.OrderBy(x => x.Compliance_ParentOrderAcknowledgement).ToList();
#rakefile.rb
require 'rake'
require 'albacore'
task :default => [:full]
task :full => [:clean,:assemblyInfo,:build,:xunitTests,:specifications,:publish]
@codereflection
codereflection / gist:1232851
Created September 21, 2011 18:14
Getting the last friday of the month as an extension method
public static class DateTimeExtensions
{
public static DateTime LastFridayOfMonth(this DateTime value)
{
var days = Enumerable.Range(1, DateTime.DaysInMonth(value.Year, value.Month));
var dates = days.Select(day => new DateTime(value.Year, value.Month, day));
var lastFriday = dates.OrderBy(day => day).Last(day => day.DayOfWeek == DayOfWeek.Friday);
@codereflection
codereflection / gist:1274851
Created October 10, 2011 08:13
Simple.Data - yeah, it works in VB too, who knew? :P
Imports System.Dynamic
Module SimpleVBDataCatz
Sub Main()
Console.WriteLine("Let's see some of this Simple.Data magick in VB")
Dim db = Database.Opener.OpenFile("Data\ICanHazData.sdf")
InsertTimmyCatAsAnonymousObject(db)
@codereflection
codereflection / gist:1274872
Created October 10, 2011 08:34
In line XML in VB - perhaps it's only redeeming quality
Imports Xunit
Imports System.Linq
Imports System.Dynamic
Imports Simple.Data.Mocking
Public Class Mockz
<Fact()>
Public Sub MockMockMock()
Dim mockAdapter As New XmlMockAdapter(<Root>
<Cats Age="System.Int32">
@codereflection
codereflection / gist:1309922
Created October 24, 2011 19:33
Alternative to C#'s out and Tuples
using System;
namespace TuplesSuck
{
class Program
{
static void Main(string[] args)
{
var returnedCount = 0;
var returnedString = "";
<appSettings>
<add key="myDevMachineName" value="Dev" />
<add key="myTestMachineName" value="Test" />
<add key="myUATMachineName" value="UAT" />
<add key="myProdMachineName" value="Prod" />
<add key="Dev.Foo" value="Bar" />
<add key="Test.Foo" value="Baz" />
<add key="UAT.Foo" value="Bin" />
<add key="Prod.Foo" value="BarkBark!" />
@codereflection
codereflection / gist:1401802
Created November 28, 2011 20:05
I don't like this pattern of throwing exceptions
public DirectoryInfo GetDestinationFor(string fileName)
{
Log.InfoFormat("Getting destination for {0}", fileName);
var result = paths.FirstOrDefault(x => x.Key.IsMatch(fileName));
if (result.Key != null)
{
Log.InfoFormat("Destination for {0} is {1}", fileName, result.Value);
return result.Value;
}
@codereflection
codereflection / info.txt
Created February 29, 2012 00:43
Gravity Kata
Gravity Kata
Create a system that shows how stacked ice blocks behave with gravity.
Here are some examples of how the ice blocks behave in this system:
Adding blocks
Before After
@codereflection
codereflection / gist:1948171
Created March 1, 2012 08:01
Another WTF moment...
namespace MyCompany.Data
{
internal class StoredProcedureManager
{
public static string GetStoredProcedureName(StoredProcedure storedProcedure)
{
switch (storedProcedure)
{
case StoredProcedure.GetAllDataByUser:
return "GetClientAccountsByUser";