Skip to content

Instantly share code, notes, and snippets.

ko.bindingHandlers.keyFilter = {
init: function(element, value, allBindings) {
var filter = ko.bindingHandlers.keyFilter[allBindings.keyFilter];
if (!filter) return;
$(element).keypress(function(event) {
if (!filter(event.which)) {
event.stopPropagation();
return false;
jQuery.parseJSON = (function(parse) {
var datePattern = /^\/Date\((\d+)\)\/$/;
return function(data) {
var value = parse(data);
parseDates(value);
return value;
}
function parseDates(obj) {
for (var k in obj) {
// This won't work as you probably want
for (var i = 0; i < 10; i++) {
handlers.push(function() {
use(i);
});
}
// This won't work due to "var yanking"
for (var i = 0; i < 10; i++) {
var j = i;
@andrewdavey
andrewdavey / gist:700607
Created November 15, 2010 17:05
Extending view model wishlist
class CustomerController : Controller {
public ActionResult List() {
var customers = DB.GetAllCustomers();
ViewModel.Customers = customers;
ExtendViewModel<Customer>("Url", customer => Url.Action("details", new { customer.Id }));
return View();
}
@andrewdavey
andrewdavey / gist:704900
Created November 18, 2010 12:02
Potential encoding bug in RavenDB's /static response
static void StaticKeyBug()
{
using (var store = new DocumentStore())
{
store.Url = "http://localhost:8080";
store.Initialize();
store.DatabaseCommands.PutAttachment("test/hello/world", null, new byte[] { 1, 2, 3 }, new JObject());
using (var wc = new WebClient())
@andrewdavey
andrewdavey / gist:964993
Created May 10, 2011 17:55
Witness coffeescript syntax idea
Given loadPage('/login'), [
Given userIsRemembered('johnsmith'), [
When [
'enter correct password': input(password: 'test')
click 'login'
]
Then [
dashboardScreenLoaded()
]
]
@andrewdavey
andrewdavey / gwt-cs.cs
Created May 25, 2011 09:53
Different approach to C# unit testing
// Sorry to stir things up, but I really don't get on with the current *Unit test frameworks
// in C#. I hate creating_long_semi_english method names. I hate then repeating myself
// in code e.g. public void It_sould_equal_10() { Assert.That(it == 10); }
// I think the problem stems from making a method the atom of a test.
// This leads to crap method names and hard to understand tests.
// What follows is a different approach. (Not real code yet, just ideas!)
// One Test class per class under test.
// Inherits framework `Tests` class to provide test-DSL methods.
public class Global : System.Web.HttpApplication {
protected void Application_Start(object sender, EventArgs e) {
var store = new SmartMessageStore();
DependencyResolver.Register(typeof(IMessageStore), () => store);
}
}
@andrewdavey
andrewdavey / semvercompare-output.txt
Created January 21, 2012 16:58
Sample output from SemVerCompare
> SemVerCompare.exe old\Cassette.dll new\Cassette.dll
Type added: Cassette.CassetteApplicationContainer
Type added: Cassette.ICassetteApplicationContainer`1
Type changed: Cassette.IO.IsolatedStorageDirectory
Member added: Void .ctor(System.Func`1[System.IO.IsolatedStorage.IsolatedStorageFile])
Type changed: Cassette.ICassetteApplication
Member added: System.Collections.Generic.IEnumerable`1[Cassette.Bundle] get_Bundles()
Member added: System.Collections.Generic.IEnumerable`1[Cassette.Bundle] Bundles
Type changed: Cassette.IO.IsolatedStorageFile
@andrewdavey
andrewdavey / example.cshtml
Created February 24, 2012 13:26
Nancy razor helper problem
<!DOCTYPE html>
<html>
<head>
<title>Resource</title>
</head>
<body>
@TestHelper()
</body>
</html>