This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup(method) | |
{ | |
method = fake; | |
}; | |
function fake() | |
{ | |
return "faked"; | |
} | |
function real() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The simplest(?!?!) way to get JSON.NET to handle serialization of properties with an interface type. | |
usage: | |
var settings = new JsonSettings(); | |
settings.Converters.Add(new InterfaceConverter<IDataStoreSettings, AccessDataStoreSettings>()); | |
JsonConvert.DeserializeObject<Configuration>(contents, settings); | |
*/ | |
internal class InterfaceConverter<To, From> : JsonConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'zlib' | |
@@cssPath = '../public/stylesheets/' #relative to where the script is running | |
@@imagePath = '../public/images/' #relative to where the script is running | |
@@styleSheets = ['myCssFile1.css', 'AntherCssFile.css'] | |
def crc(fileName) | |
fileName = @@imagePath + fileName.slice(10..-1) | |
contents = File.read(fileName) ; nil | |
Zlib.crc32(contents,0).to_s(16) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//re how I would test it (http://openmymind.net/2010/10/20/My-Slow-Transition-Away-From-Mocks) without a mock | |
[Test] | |
public void CalculatesTheMessagesHash() | |
{ | |
var logger = new LoggingService(new MyRealEncryptor()); | |
var message = new Message{Body = "Some Body", Application = new Application(23) }; | |
Assert.AreEqual("E99A18C428CB38D5F260853678922E03", logger. CalculateHash(message)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//from https://github.com/mongodb/mongo-csharp-driver/blob/master/Driver/Core/MongoDatabase.cs | |
#region public indexers | |
public MongoCollection<BsonDocument> this[ | |
string collectionName | |
] { | |
get { return GetCollection(collectionName); } | |
} | |
public MongoCollection<BsonDocument> this[ | |
string collectionName, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#repeated, inline variables | |
it "should update the email" do | |
put :update, {:id => 1, :email => 'leto@dune.gov'} | |
User.count({:id => 1, :email => 'leto@dune.gov'}).should == 1 | |
end | |
#extracted variables | |
it "should update the email" do | |
id = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data.SqlClient; | |
using NHibernate.Exceptions; | |
public class ExceptionConverter : ISQLExceptionConverter | |
{ | |
public Exception Convert(AdoExceptionContextInfo context) | |
{ | |
var exception = ADOExceptionHelper.ExtractDbException(context.SqlException) as SqlException; | |
if (exception != null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static readonly string[] _ipHeaderOrder = new[] { "HTTP_X_FORWARDED_FOR", "HTTP_X_CLUSTER_CLIENT_IP", "REMOTE_ADDR" }; | |
public static string ClientAddress(this HttpRequest request) | |
{ | |
foreach (string header in _ipHeaderOrder) | |
{ | |
string ipAddress = request.ServerVariables[header]; | |
if (ipAddress != null) | |
{ | |
return ipAddress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Forgive the poor example | |
public ICollection<User> LoadUsersByStatus(ICollection<UserStatus> statuses) | |
{ | |
return _service.LoadUsersByStatus(statuses); | |
} | |
[Test] | |
public void GetsTheUsersFromTheService() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JsonFragment | |
def initialize(value) | |
@value = value | |
end | |
def as_json(o = nil) | |
self | |
end | |
def encode_json(e = nil) | |
@value.blank? ? 'null' : @value |