Skip to content

Instantly share code, notes, and snippets.

View codereflection's full-sized avatar

Jeff Schumacher codereflection

View GitHub Profile
/// <summary>
/// Convert to ISO 8601 Date time format (Required by Sqlite)
/// </summary>
/// <param name="dateTime">date to convert</param>
/// <returns>date converted to ISO8601 datetime format</returns>
public static string ToISO8601(this DateTime dateTime)
{
return dateTime.ToString("u").Replace("Z", "");
}
@codereflection
codereflection / gist:1948217
Created March 1, 2012 08:08
Here's another WTF gem
// OK, WTF is with ALL of these damn usings that are NOT EVEN USED. IMPORT ALL THE THINGS!
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
@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";
@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: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;
}
<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: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 = "";
@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: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: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);