Skip to content

Instantly share code, notes, and snippets.

@liammclennan
liammclennan / gist:663767
Created November 5, 2010 07:15
Simple Client-Side JavaScript MVC Framework
// full source is at https://github.com/liammclennan/Client-Side-JavaScript-MVC-Framework
// framework makes available two global variables: app and views
// Step 1: Define views. If a requested view is not defined then the framework gets the template from /views/[viewname]
views.welcome = function() {
var template = " \n\
#container \n\
%ul \n\
@liammclennan
liammclennan / gist:707513
Created November 20, 2010 01:28
Validating my immutable object
public bool IsValid()
{
return true;
}
@liammclennan
liammclennan / gist:798133
Created January 27, 2011 05:57
tell-don't-ask vs. no external dependencies on domain objects
// tell don't ask means I might do something like this
var folder = new Folder("foo");
folder.Delete();
// but for that to work the folder class needs to depend on a file IO service (to do the deleting).
// the alternative is procedural
public class FolderService
{
@liammclennan
liammclennan / gist:814007
Created February 7, 2011 04:45
Proposed Advanced JavaScript Screencast
Language Features
Overview
Truthyness
Closure
Lexical Scoping
Function Prototypes
Reflection
JSON
Eval
@liammclennan
liammclennan / gist:861595
Created March 9, 2011 02:45
proposed querying pattern
// setup a specification
var specification = new UserWithClientSpecification(userId);
var userWithClient = userService.RetrieveWithSpecification(specification);
// and the specification class would be...
public class UserWithClientSpecification : ISpecification<User>
{
public UserWithClientSpecification(int userId)
@liammclennan
liammclennan / gist:884704
Created March 24, 2011 07:33
Enumeration Behaviour
[Test]
public void CollectionTests()
{
var letterList = new List<string>
{
"a","b"
};
IEnumerable<string> letters = letterList.Select(l =>
{
@liammclennan
liammclennan / gist:891625
Created March 29, 2011 00:41
JavaScript Class Template
var myNamespace = myNamespace || {};
myNamespace.MyConstructor = function(opts) { this.options = opts; };
(function () {
function myPrivateMethod(t) {
console.log("myPrivateMethod" + t.options.a);
}
@liammclennan
liammclennan / gist:907018
Created April 7, 2011 04:05
Inspecting a JavaScript object
Object.prototype._methods = function() {
var methods = [];
for (m in this) {
if (typeof this[m] === 'function' && m !== '_methods' && m !== '_properties') {
methods.push(m);
}
}
return methods;
}
@liammclennan
liammclennan / gist:921432
Created April 15, 2011 09:04
what I think a JavaScript BDD syntax should look like
story("do a thing", function() {
scenario("when I do something under certain conditions", function() {
given("certain conditions", function() {
console.log("certain conditions");
});
when("I do something", function() {
@liammclennan
liammclennan / gist:951079
Created May 2, 2011 01:38
Basic JavaScript Constructor
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype = {
toString: function() {
return this.name + " is " + this.age + " years old.";
}
};