Skip to content

Instantly share code, notes, and snippets.

@appleton
appleton / pngquan_dir.zsh
Created January 30, 2013 15:56
Run all pngs in the current directory and subdirectories through [pngquant](http://pngquant.org/)
function pngquant_dir() {
if (( $+commands[pngquant] )); then
# Using 1000 here because OSX does so this gives consistent results
bytes_per_kb=1000
total_saved=0
for file in **/*.png; do
before_size=`wc -c < $file`
before_size=$(($before_size / $bytes_per_kb))
@appleton
appleton / Rakefile
Created December 18, 2012 09:53
A Rakefile to help managing a Jekyll site. Fill out your own ssh config in the CONFIG hash. Note that publish requires that you have ssh keys set up with your server, this doesn't work with ssh passwords (because I didn't need it).
require 'pty'
CONFIG = {
:remote => {
:host => 'my.ssh-host.com',
:user => 'my-ssh-username',
:path => 'path-to/site/root'
},
:posts => 'local/posts/directory'
}
@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()
@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 / 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);

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