Skip to content

Instantly share code, notes, and snippets.

@reidev275
reidev275 / CommandExecutor.cs
Created October 5, 2012 15:58
Decouple command execution from command creation to allow full unit testing of each.
using System.Data;
public interface ICommandExecutor
{
void ExecuteNonQuery(IDbCommand command);
}
public class CommandExecutor : ICommandExecutor
{
public void ExecuteNonQuery(IDbCommand command)
@reidev275
reidev275 / .gitignore
Created January 25, 2013 15:51
gitignore file for azure git deployment
# don't ignore myself!
!.gitignore
# Visual Studio build objects
![Bb]in/
csx/
obj/
# Visual Studio user-specific files
## Useful whenever working as part of a team or on software (like open source) that others will download
@reidev275
reidev275 / PenTool.js
Last active December 12, 2015 08:08
given <canvas id="canvas"></canvas> allow the user to draw on the canvas
var DT = (function(dt, $) {
dt.PenTool = function(id) {
var canvas = $(id);
var context = canvas[0].getContext("2d");
var isMouseDown = false;
canvas.mousedown(function (e) {
isMouseDown = true;
context.moveTo(e.offsetX, e.offsetY);
}).mouseup(function() {
using NUnit.Framework;
[TestFixture]
public class Given_we_are_creating_an_object_with_a_single_string_parameter
{
[Test]
public void We_sould_test_for_null_or_whitespace_parameters()
{
TestHelpers.NullOrWhitespaceTest((s) => new ObjectWithStringParameter(s));
}
@reidev275
reidev275 / Timed.cs
Created October 14, 2013 21:11
simple List with max item count and age out capability
public class Timed<T>
{
readonly DateTime _time;
readonly T _item;
public Timed(T item)
{
if (item == null) throw new ArgumentNullException("item");
_item = item;
}
@reidev275
reidev275 / MaxItemList.cs
Last active December 27, 2015 18:59
IList<T> decorator holding a max number of items using FIFO
using System;
using System.Collections.Generic;
namespace Reid.Collections
{
public class MaxItemList<T> : IList<T>
{
readonly IList<T> _list;
readonly int _maxItems;
@reidev275
reidev275 / ClientError.cs
Last active August 29, 2015 13:55
ClientError
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web.Http;
namespace DocSol.Webservice.Controllers
{
public class ClientError : HttpResponseException
{
@reidev275
reidev275 / arraySearch.js
Last active August 29, 2015 13:56
Simple javascript searching
var MyNamespace = (function(namespace) {
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp */) {
"use strict";
if (this == null) throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
@reidev275
reidev275 / ajax.js
Last active August 29, 2015 14:01
ajax without jQuery
var ajax = (function (ajax, json) {
ajax.send = function (obj) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status >= 200 && xmlhttp.status < 300 && obj.complete) {
obj.complete(json.parse(xmlhttp.responseText));
}
if (xmlhttp.status < 200 || xmlhttp.status >= 300) {
@reidev275
reidev275 / app.config
Last active August 29, 2015 14:01
network logging
<system.diagnostics>
<sources>
<source name="System.Net" tracemode="protocolonly" maxdatasize="1024">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>