Skip to content

Instantly share code, notes, and snippets.

View johnnonolan's full-sized avatar

John Nolan johnnonolan

View GitHub Profile
@johnnonolan
johnnonolan / orderdedjobs.sql
Created September 28, 2011 16:39
Orded jobs WIP
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--aligator => crocodile
ALTer procedure OrderJobs
(
@jobs varchar(max)
public static BeforeFilters operator +(BeforeFilters filters, Func<RequestContext, Response> filter)
{
filters.AddFilterToEnd(filter);
return filters;
}
public void AddFilterToEnd(Func<RequestContext, Response> filter)
{
Filters.Add(filter);
}
@johnnonolan
johnnonolan / fowler.txt
Created July 30, 2011 10:47
primitive obsession excerpt
Most programming environments have two kinds of data. Record types allow you to structure data into meaningful groups. Primitive types are your building blocks. Records always carry a certain amount of overhead. They may mean tables in a database, or they may be awkward to create when you want them for only one or two things.
One of the valuable things about objects is that they blur or even break the line between primitive and larger classes. You can easily write little classes that are indistinguishable from the built-in types of the language. Java does have primitives for numbers, but strings and dates, which are primitives in many other environments, are classes.
People new to objects usually are reluctant to use small objects for small tasks, such as money classes that combine number and currency, ranges with an upper and a lower, and special strings such as telephone numbers and ZIP codes. You can move out of the cave into the centrally heated world of objects by using Replace Data Value with Object o
@johnnonolan
johnnonolan / indexFragmentation.sql
Created June 14, 2011 15:10
A couple of useful scripts for non dbas.
--- this one may impact performance run at a quiet time
-- change INSERT YOUR DB NAME HERE to your db name
SELECT object_name(IPS.object_id) AS [TableName],
SI.name AS [IndexName],
IPS.Index_type_desc,
IPS.avg_fragmentation_in_percent,
IPS.avg_fragment_size_in_pages,
IPS.avg_page_space_used_in_percent,
IPS.record_count,
@johnnonolan
johnnonolan / Fake.cs
Created April 23, 2011 13:02
FakeConcreteClass
public class TestingAnAbstractClassWithAFake
{
private class FakeConcreteInstance : MyAbstractClass
{}
[Fact]
public void Should_return_correct_message()
{
@johnnonolan
johnnonolan / AbstractWithAmock.cs
Created April 23, 2011 12:58
Testing Abstract Class with a mock
public class TestingAnAbstractClassWithAMock
{
[Fact]
public void Should_return_correct_message()
{
var mock = new Mock<MyAbstractClass>();
var result = mock.Object.MyMethodOnAbstractClass("fish");
Assert.Equal("I like fish in an abstract sense.", result);
}
}
public abstract class AbstractTestBaseClass
{
protected MyAbstractClass AbstractedVariable;
[Fact]
public void Should_return_correct_message()
{
var result= AbstractedVariable.MyMethodOnAbstractClass("input");
Assert.Equal("I like input in an abstract sense.", result);
}
}
public class MyAbstractClass
{
public string MyMethodOnAbstractClass(string input)
{
return "I like " + input + " in an abstract sense.";
}
}
@johnnonolan
johnnonolan / test.cs
Created April 2, 2011 22:16
SQL.Data is coming
[Subject("SELECT Executing")]
public class When_executing_select_from_users
{
Establish that = () => {
q.ConnectionString = connectionString;
};
Because of = () => result = (q.SELECT * q.FROM.Users).GO(); //Users is dynamic
It should_return_select_star_from_users = () => result.Count.ShouldEqual(0);
static IList<DataRecord> result;
static string connectionString = @"Data Source = |DataDirectory|\TestDb.sdf";
@johnnonolan
johnnonolan / SQL.Data.cs
Created March 27, 2011 10:52
IN Clause now working :)
[Subject("Inspecting SQL")]
public class When_calling_select_from_users_with_predicate_collection
{
Because of = () => result = (q.SELECT * q.FROM.Users.WHERE.UserId.IN(1,2)).ToString();
It should_return_select_star_from_users = () => result.ShouldEqual("SELECT * FROM Users WHERE UserId IN (1,2)");
static string result;
}