Skip to content

Instantly share code, notes, and snippets.

express.use(connect.static({maxAge: 12345}));
export default function() {
return 'hai';
}
def multiply(x, y)
x * y
end
p [1,2,3].map(&method(:multiply, 2))
# ArgumentError :(
describe('A test', function() {
set('data', function() {
return { some: 'stuff' };
});
set('subject', function() {
return new FooThing(data);
});
it('does stuff', function() {
@appleton
appleton / contents-from-ajax.js
Created November 4, 2014 15:29
contents-from-ajax.js
var d = document.createElement('div');
d.innerHTML = 'a load of html that you got back from the server';
var contents = d.querySelector('div.whatever').innerHTML;
@appleton
appleton / feature-checke.hbs
Created January 20, 2015 10:09
Is it possible to add an {{else}} block to an Ember Component?
{{#feature-check name="awesome-feature"}}
It's enabled
{{else}}
It's disabled
{{/feature-check}}

Coding Rails with Homebrew

Right now, this assumes you are using Snow Leopard.

Install Homebrew

Homebrew is MacPorts (or APT) without the suck. http://github.com/mxcl/homebrew

@appleton
appleton / serve.js
Created January 29, 2012 17:48
Serve a static site from node.js handy for local development
var http = require('http'),
fs = require('fs');
http.createServer(function(req, res){
var path = (req.url === '/' ? './index.html' : '.' + req.url);
fs.readFile(path, 'utf-8', function(err, data){
if(!err){
console.log('Serving: ', req.url);
res.writeHead(200);
res.end(data);
@appleton
appleton / canvas-troll.js
Created February 27, 2012 14:22
Troll any canvas element
var canvas = document.getElementsByTagName('canvas'),
img = new Image();
img.onload = function(){
Array.prototype.slice.call(canvas).forEach(function(el){
el.getContext('2d').drawImage(img, 0, 0);
});
};
img.src = 'http://thegurglingcod.typepad.com/.a/6a00d8341c387d53ef0148c84decb8970c-320wi';
@appleton
appleton / if_equal.coffee
Created April 26, 2012 11:45
Conditional comparison for Handlebars
Handlebars.registerHelper 'if_equal', (val1, val2, fn) ->
if val1 == val2
return fn()
else if fn.inverse
return fn.inverse()