Skip to content

Instantly share code, notes, and snippets.

View bforrest's full-sized avatar
💭
Red, red, red, GREEN, refactor

Barry Forrest bforrest

💭
Red, red, red, GREEN, refactor
View GitHub Profile
@bforrest
bforrest / truncated_codr.cs
Created January 21, 2012 02:38
truncated_codr.cs
private T HandleItemCacheRetrieval<T>(string cacheKey, object cacheLock, Func<int, T> nonCachedMethod, int arg) where T : new() {
T retVal = default(T);
try {
retVal = (T)CacheManager.Get(cacheKey);
}
catch (InvalidCastException ex) //it didn’t parse properly
{
LoggerManager.Error(ex);
}
@bforrest
bforrest / FlatFileConsoleRunner.cs
Created January 21, 2012 16:17
Use an xsd to transform a flat file into an xml document
using System;
using System.IO;
using System.Xml;
namespace FlatFileToXml
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
@bforrest
bforrest / EF_DbContext.cs
Created February 15, 2012 22:22
EF DbContext
using System.Data.Entity;
using Devtalk.EF.CodeFirst;
using BeerLoversOftheWorld.Models;
[assembly: WebActivator.PreApplicationStartMethod(typeof(BeerLoversOftheWorld.App_Start.DontDropDbJustCreateTablesIfModelChangedStart), "Start")]
namespace BeerLoversOftheWorld.App_Start {
public static class DontDropDbJustCreateTablesIfModelChangedStart {
public static void Start() {
// Uncomment this line and replace CONTEXT_NAME with the name of your DbContext if you are
@bforrest
bforrest / implementation
Created February 28, 2012 00:59
Gravity kata
var iceWorld = new Array();
function IceWorld(){
iceWorld.length = 0;
iceWorld.push(new Array());
}
IceWorld.prototype.Add = function(block){
iceWorld[0].push(block);
block.column = 0;
@bforrest
bforrest / info.txt
Created February 28, 2012 17:26
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
@bforrest
bforrest / NumeralParser.cs
Created April 21, 2012 00:53
Roman Numeral Parser
//
// Copyright 2012 barry forrest
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
/* Scripts dealing with date operations */
// ==================================== */
$('#StartDate').addClass('datepicker');
$('#StartIcon').click(function () {
$('#StartDate').datepicker('show');
});
$('#EndDate').addClass('datepicker');
$('#EndIcon').click(function () {
$('#EndDate').datepicker('show');
/* Scripts dealing with date operations */
// ==================================== */
$('#StartDate').addClass('datepicker');
$('#StartIcon').click(function () {
$('#StartDate').datepicker('show');
});
$('#EndDate').addClass('datepicker');
$('#EndIcon').click(function () {
$('#EndDate').datepicker('show');
@helper Script(dynamic tempData){
<div class="container">
<div id="notifier" class="row span8"></div>
</div>
<script>
var messages = messages || [];
</script>
if (tempData["message"] != null)
{
@bforrest
bforrest / window.console.js
Created July 27, 2012 15:24
console log javascript snippet
if (!window.console) {
(function() {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i) {
window.console[names[i]] = function() {};
}
}());
}