Skip to content

Instantly share code, notes, and snippets.

ioc('parent', function(component, parentElement){
parentElement.click(function() {
component.parentClicked();
});
});
ioc('component', function(componentElement) {
componentElement.click(function() {
alert('component clicked');
});
ioc.register('parent', function(child, sampleDomElement) {
return {
sayHello: function() {
sampleDomElement.innerHTML = '<h1>Hi There</h1>';
child.doIt(sampleDomElement);
}
};
});
ioc.register('child', function() {
get('/', function() {
var self = this;
articleProvider.findAll(function(error, docs) {
jade.renderFile('./views/blogs_index.html.jade', {
locals: {
title: 'Blog',
articles: docs
}
},
context('a context tester', function() {
var result;
this.when('when async', function() {
var self = this;
sys.puts('starting async');
setTimeout(function() {
sys.puts('2 seconds later');
result = 2;
self.done();
app.use(connect.compiler({
src: pub,
enable: ['scss', 'sass'],
compilers: [{ name: 'scss', compiler: require('scss/compiler') }]
}));
@bmavity
bmavity / objIter.js
Created February 4, 2011 22:24
Object iteration
// Implementation
var iter = function(obj, callback) {
Object.keys(obj).forEach(function(key) {
callback(key, obj[key]);
});
};
// Usage
iter(obj, function(name, val) {
// Do shit here
@bmavity
bmavity / AtomFeed.js
Created February 6, 2011 02:28
Generating an atom feed with a JavaScript DSL
var generateUniqueId = function(post) {
return [
'tag:brianmavity.com,',
post.publishDate.slice(0, 10),
':/blog/',
post.publishDate.replace(/T|Z|\.|:|-/g, '')
];
};
doc(
@bmavity
bmavity / ViewEngine.js
Created February 7, 2011 23:45
Home page using new view engine
doc(
'<!DOCTYPE html>',
html(
head(
title('Software Development, Interaction Design'),
link({ rel: 'alternate', href: 'http://feeds.feedburner.com/brianmavitycomblog', type:'application/atom+xml', title: 'brianmavity.com - Atom' }),
link({ rel: 'stylesheet', href: '/css/reset.css', type: 'text/css', media: 'screen' }),
link({ rel: 'stylesheet', href: '/css/vertical-rhythm.css', type: 'text/css', media: 'screen' }),
@bmavity
bmavity / twoDimArray.js
Created February 11, 2011 17:00
Keesus' two dimensional array
//HaloGame has the title of a particular halo release
HaloGame = new Array("Halo", "Halo 2", "Halo 3", "Halo: ODST", "Halo: Reach");
var haloYearDifferences = new Array (0, 3, 6, 8, 9);
var halo2YearDifferences = new Array (3, 0, 3, 5, 6);
var halo3YearDifferences = new Array (6, 3, 0, 2, 3);
var haloOdstYearDifferences = new Array (8, 5, 2, 0, 1);
var haloReachYearDifferences = new Array (9, 6, 3, 1, 0);
//creating a 2-dimensional array of years between releases
<!DOCTYPE html>
<html>
<head>
<title>Sample Page for Module Intro</title>
</head>
<body>
<h1>Variables added to window object</h1>
<script src="samplePageExternal.js"></script>
<script>
// For IE. You've brought the alert punishment on yourself. ;)