Skip to content

Instantly share code, notes, and snippets.

/*
Fun little experiment with custom attributes
Usage:
<div id="foo" data-foo-bar="awesome" data-whatever="cool"></div>
$('#foo').dataSet() // >> {fooBar: 'awesome', whatever: 'cool'}
or
<div id="foo2"></div>
$('#foo2').dataSet({fooBar: 'awesome', whatever: 'cool'}); // >> <div id="foo" data-foo-bar="awesome" data-whatever="cool"></div>
@gjohnson
gjohnson / signature.js
Created January 18, 2011 22:29
jQuery Ajax Signature
$.ajax(url, options);
@gjohnson
gjohnson / basic.ajax.js
Created January 18, 2011 22:30
Basic Ajax Promise
var jxhr = $.ajax('/foo.php', {type:'get', dataType:'json'});
xhr.success(function(response){
// do something with the resposne
});
xhr.error(function(jxhr){
// do something with jxhr
});
console.log('whats up?');
@gjohnson
gjohnson / json.basic.js
Created January 19, 2011 00:38
Basic getJSON example
$.getJSON('foo.php').then(function(r){
console.log(r);
}, function(jxhr){
console.log(jxhr);
});
console.log('whats up?');
@gjohnson
gjohnson / Chained.Ajax.js
Created January 19, 2011 00:39
Promise Chaining
var jxhr = $.ajax('foo.php', {
type: 'get',
dataType: 'json',
success: function (r) {
console.log('1');
jxhr.success(function(r){
console.log('4');
});
}
});
@gjohnson
gjohnson / Deferred.js
Created January 19, 2011 00:40
Deferred Example
var def = new $.Deferred(), data = [1,2,3,4,5];
setTimeout(function(){
def.resolve(data);
}, 5000);
def.then(function(data){
console.log(data);
});
@gjohnson
gjohnson / tail.js
Created March 18, 2011 15:33
web interface for tail
var sys = require('sys');
var child = require('child_process');
var http = require('http');
var filename = process.ARGV[2];
if (!filename) {
return sys.puts('usage: node tail.js filename');
}
var tail = child.spawn("tail", ["-f", filename]);
@gjohnson
gjohnson / jquery.ga.js
Created July 28, 2011 22:14
fun with jquery, functions, and being too lazy to track google analytic events
$.ga
('use')
('setAccount', 'UA-83919101')
('trackPageview')
('trackPageLoadTime')
('setCustomVar', 1, 'OrderID', 1)
('events')
('click', 'h2', ['Label 1', 'Action 1', 'Value 1'])
('click', '#breadcrumbs', function(){ return ['Label 1', 'Action 1', this.value]; })
;
@gjohnson
gjohnson / testy.php
Created September 6, 2011 05:07
idea for a php 5.4 micro testing framework
<?php
/**
* concept for a new testing framework
*/
Testy\Test::describe('Addition')
->before(function() {
})
@gjohnson
gjohnson / hello.js
Created September 18, 2011 06:01
HTTP Server - NCDEVCON
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-type': 'text/plain' });
res.write('Hello');
res.end('NCDevCon');
});
server.listen(8000);