Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / gist:1103972
Created July 25, 2011 11:55
canvas draw grid (jquery + kaffeine)
$.fn.grid = (interval) -> {
var canvas = @[0], context = canvas.getContext('2d')
x = y = 0.5
while((x+=interval)<canvas.width) {
context.moveTo(x,0)
context.lineTo(x,canvas.height)
}
while((y+=interval)<canvas.height) {
context.moveTo(0,y)
context.lineTo(canvas.width,y)
@mahemoff
mahemoff / app.jade
Created August 15, 2011 00:04
Simple growl-style notifier (jQuery)
// include the following
.notifier
img.progressor(src='/progressor.gif')
span.message loading fonts and stuff ...
@mahemoff
mahemoff / gist:1163092
Created August 22, 2011 18:22
Kaffeine+Ugly in Express
var kaffeine = new (require("kaffeine"))();
app.register('.k', {
compile: function(str, options) {
return function(locals) { return uglify(kaffeine.compile(str)) };
}
});
function uglify(js) {
var jsp = require("uglify-js").parser;
@mahemoff
mahemoff / emptyDB.coffee
Created August 26, 2011 22:44
Cradle (CouchDB+Node) routine to prepare a new DB, destroying the old one if it already exists. Good for prepping a data dump.
data =
init: () ->
data.emptyDB "animals", () ->
console.log "ready"
# now populate your new DB
emptyDB: (name, done) ->
db = new(cradle.Connection)().database(name);
db.exists (err, exists) ->
@mahemoff
mahemoff / app.coffee
Created August 31, 2011 20:04
DRY "require" of multiple modules in Node
"underscore,connect,express,redis,sys,coffee-script,fs"
.split(',').forEach (lib) -> global[lib] = require lib
# make macros if you like
_ = underscore
@mahemoff
mahemoff / gist:1188756
Created September 2, 2011 14:36
Total page views on Google Analytics (across all domains)
function calc() {
var sum = 0;
$('.profile_list_table > tbody > tr > td:nth-child(2) div div').each(function() {
console.log(this, this.innerHTML);
sum+=parseInt(this.innerHTML.replace(',',''))
});
$('.account_table_header_text').append(' [Total: '+sum+']');
}
setTimeout(calc,3000);
@mahemoff
mahemoff / app.coffee
Created September 5, 2011 18:25
logging with winston
winston = require 'winston'
global[level] = winston[level] for level of winston.config.syslog.levels
debug 'foo'
info 'foo'
notice 'foo'
warning 'foo'
error 'foo'
crit 'foo'
alert 'foo'
@mahemoff
mahemoff / jader.sh
Created September 9, 2011 22:00
convert jade to html
function jader {
scalate tojade $1 | sed 's/" /",/g' > `basename $1 .html`.jade
}
### PRE-REQUISITE: scalate (e.g. "brew install scalate")
@mahemoff
mahemoff / ellipsize.coffee
Created September 12, 2011 10:05
jQuery plugin to simulate css3 ellipsis overflow
# http://stackoverflow.com/questions/3404508/cross-browsers-mult-lines-text-overflow-with-ellipsis-appended-within-a-widthhei/3880955#3880955
$.fn.ellipsize = (maxHeight) ->
i=100 # prevent infinite loop
$(this).each () ->
$this = $(this)
while (--i and $this.outerHeight()>50)
$this.text (index, text) -> text.replace /\W*\s(\S)*$/, '...'
@mahemoff
mahemoff / example.coffee
Created September 12, 2011 14:45
Managing templates with Underscore template
templates = {}
$ () ->
$('.template').each (i,el) -> templates[el.id.replace('Template','')] = _.template(el.innerHTML)
....
# LATER ON, HERE IS HOW WE USE THE TEMPLATE ...
....
$('.storyContainer').html templates.story
title: 'holy crazy!'