Skip to content

Instantly share code, notes, and snippets.

View davidwhitney's full-sized avatar
🍸
You're all wonderful. That's what's happening.

David Whitney davidwhitney

🍸
You're all wonderful. That's what's happening.
View GitHub Profile
@davidwhitney
davidwhitney / gist:1751946
Created February 6, 2012 13:04
Caching thing for Ian
public class ThingThatGetsMeData : IThingThatGetsMeData
{
public Data GetTheData()
{
// database loading logic
}
}
public class CachingThingThatGetsMeData : IThingThatGetsMeData
@davidwhitney
davidwhitney / JGML
Created February 13, 2012 17:13
Working prototype of JustGiving Markup in an external page
<!DOCTYPE html>
<html>
<head>
<title>JustGiving.Data</title>
</head>
<body>
<div>
<h1>JGM Example</h1>
@davidwhitney
davidwhitney / TypeParsingExtensions
Created January 11, 2013 17:14
A simpler way to parse strings in C# Parsing strings in C# can be verbose and horrible. The last thing you want to do when solving some real problem, is end up with a load of code extracting values from strings and marshalling them between data types. It’s silly, so lets not do it! Instead, I offer you an extension method and some tests. Do with…
public class StringParsingNeedsToBeSimpler
{
public void HereAreSomeExamples()
{
//You know what sucks?
string value = "123";
int outt;
if(!int.TryParse(value, out outt))
{
outt = 12345; // my default!
@davidwhitney
davidwhitney / Settings.cs
Created March 20, 2013 01:00
Html Helper to support CDN Url.Content locations in ASP.NET MVC
public class Settings : ConfigurationSection
{
[ConfigurationProperty("enabled", DefaultValue = "false", IsRequired = true)]
public bool Enabled
{
get { return (bool)this["enabled"]; }
set { this["enabled"] = value; }
}
[ConfigurationProperty("cloudFrontDomainName", DefaultValue = "", IsRequired = true)]
@davidwhitney
davidwhitney / gist:6071383
Created July 24, 2013 15:00
Ninject scope hacking for RSE
public class NinjectActivation : IHandlerActivationStrategy
{
private readonly IEventHandlerResolver _eventHandlerResolver;
private readonly IKernel _singleKernel;
private readonly ConcurrentDictionary<object, IKernel> _scopes;
public NinjectActivation(IKernel singleKernel)
{
_eventHandlerResolver = new EventHandlerResolver();
@davidwhitney
davidwhitney / gist:7263945
Created November 1, 2013 11:05
Fluent builder example
using System;
namespace FleuntExample
{
public class BootstrappingYourLibrariesWithFluentApis
{
public BootstrappingYourLibrariesWithFluentApis()
{
// To make my library, I can instantiate everything independantly
var firstD1 = new Dependency();
@davidwhitney
davidwhitney / js-timers.html
Created November 11, 2013 11:28
Javascript timing
<!DOCTYPE HTML>
<html>
<body>
Hello.
<script type="text/javascript">
console.time("Test");
writeJunk("logging 1");
console.timeEnd("Test");
@davidwhitney
davidwhitney / gist:7551413
Created November 19, 2013 19:51
codedojo29
using System;
using Nancy;
using Nancy.Hosting.Self;
namespace WebServer
{
class Program
{
static void Main()
{
@davidwhitney
davidwhitney / EngineBlock.cs
Created November 26, 2013 18:11
Engine block
public class Engine<T> where T: IEngineComponent
{
private readonly T _component;
protected bool ContinueLooping;
private Thread _thread;
public Engine(T component)
{
_component = component;
}
@davidwhitney
davidwhitney / ID3tag
Created December 9, 2013 11:49
ID3 tag kata
The MP3 file format, didn't provide any means for including metadata about the song. ID3 tags were invented to solve this problem.
You can tell if an MP3 file includes ID3 tags by examining the last 128 bytes of the file. If they begin with the characters TAG, you have found an ID3 tag. The format of the tag is as follows:
TAG song artist album year comment genre
The spec is here: http://id3.org/ID3v1