Skip to content

Instantly share code, notes, and snippets.

View robdodson's full-sized avatar
🏠
Working from home

Rob Dodson robdodson

🏠
Working from home
View GitHub Profile
@robdodson
robdodson / Railscasts.tmTheme
Created June 25, 2012 21:47
Railscast Sublime Theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Railscasts</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@robdodson
robdodson / main.js
Created August 4, 2012 06:41
strategy
var Button = function(id) {
this.id = id;
this.$context = $(id);
this.$context.on('click', $.proxy(this.handleClick, this));
}
Button.prototype.changeAction = function(action) {
this.action = action;
}
Button.prototype.handleClick = function() {
this.action();
@robdodson
robdodson / underscore-mustache-jade-template.jade
Created August 6, 2012 23:19
Mustache, Underscore, Jade template
script(type="text/html", id="modal-service-selection")
.modal-service-selection.modal-centered.modal.stretch.hide.fade
.modal-header
a.button-close(data-dismiss='modal')
img(src="../img/icons/latest/icon-exit.png")
h3 You have selected
span.emphasize {{ service.name }}
p Please select the subcategory that fits your needs:
.modal-body
ul.l-horizontal.clearfix.reservation-entries
@robdodson
robdodson / inherit.js
Created August 9, 2012 18:00
inherit method
// Optimized version of classical inheritance
// Proxy constructor is stored in a closure which is
// returned from a self executing function.
var inherit = (function() {
var F = function() {};
return function(C, P) {
F.prototype = P.prototype;
C.prototype = new F();
C._super = P.prototype;
C.prototype.constructor = C;
(function() {
var klass = function(Parent, props) {
var Child, F, i;
// 1.
// new constructor
Child = function() {
// Call the super class constructor
if (Child._super && Child._super.hasOwnProperty('_construct')) {
@robdodson
robdodson / multi-inherit.js
Created August 9, 2012 18:15
multiple inheritence in javascript
var Parent1 = function() {
this.name = 'foo';
}
var Parent2 = function() {
this.age = '21';
}
var Child = function() {
Parent1.apply(this, arguments);
@robdodson
robdodson / decorators.js
Created August 27, 2012 22:18
method decoration
add = function(amount) {
return function(callback) {
return function() {
var value;
value = callback.apply(this, arguments);
return value + amount;
};
};
};
@robdodson
robdodson / coffee-combinators.js
Created August 27, 2012 22:33
coffee combinators
add(1) \
multiply(2) \
->
1
@robdodson
robdodson / validator.js
Created August 27, 2012 22:43
validator
var validator = new Validator();
validator.decorate('hasName', { length: 5 });
validator.decorate('hasAge', { minimum: 21 });
validator.decorate('hasZipCode');
validator.validate({}); // some form data. in this case just an anonymous object
console.log(validator.errors);
@robdodson
robdodson / validator.js
Created August 27, 2012 22:44
full validation
function Validator () {
this.errors = [];
this.decoratorsList = [];
}
Validator.prototype.decorate = function(name, args) {
this.decoratorsList.push({ name: name, args: args });
};
Validator.decorators = {};