Skip to content

Instantly share code, notes, and snippets.

@colelawrence
colelawrence / Methodder.coffee
Last active December 27, 2015 12:09
Create functions, methods, with custom specified scopes to be called anywhere in your project.
Methodder = (method, scope) ->-> method.apply(scope, arguments)
@colelawrence
colelawrence / rotation.js
Created December 1, 2013 22:14
Snap.svg animate rotation.js
function rotationAnimation(elem, degrees, pointX, pointY, time){
elem.animate({transform:"r"+[degrees,pointX,pointY]}, time);
}
@colelawrence
colelawrence / client.js
Created February 23, 2014 02:40
Javascript window resize timeout
// Do stuff after 100ms of no resizing
var resizeTimeout;
$(window).on("resize", function () {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function () {
// Do stuff
}, 100);
});
@colelawrence
colelawrence / utils.js
Last active August 29, 2015 13:58
Incrementing object properties
// Ensure object obj[prop] = {}
function _obj(obj, prop) {
if (obj[prop] == null) obj[prop] = {}
return obj[prop]
}
// Ensure number obj[prop] (+= val or = val)
function _diff(obj, prop, val) {
if (obj[prop] == null) obj[prop] = val
else obj[prop] += val
}
@colelawrence
colelawrence / jquery.swap.js
Last active August 29, 2015 14:01
Swapping elements in jQuery
function swapContainers (name1, name2) {
var btn1 = $(".button-"+name1)[0]
var cont1 = $("#"+name1)[0]
var btn2 = $(".button-"+name2)[0]
var cont2 = $("#"+name2)[0]
var btn1CN = btn1.className
btn1.className = btn2.className.replace(name2, name1)
btn2.className = btn1CN.replace(name1, name2)
var cont1CN = cont1.className
cont1.className = cont2.className
@colelawrence
colelawrence / cson.js
Created June 4, 2014 19:28
Eval JSON, JS, CSON
var coffee = require("coffee-script")
var vm = require("vm")
// Based on https://github.com/bevry/cson/blob/master/src/lib/cson.coffee
exports.parse = function (src, isJson) {
try {
result = JSON.parse(src)
} catch (err) {
if (isJson)
throw err
try {
@colelawrence
colelawrence / passhash.coffee
Created June 4, 2014 19:33
Password hashing for nodejs
# check out https://github.com/visionmedia/node-pwd
# Module dependencies.
crypto = require('crypto');
# Bytesize.
len = 128;
@colelawrence
colelawrence / layout.jade
Last active August 29, 2015 14:02
Nodemon and devreload for debugging web applications
doctype html
html
head
title= title
link(rel='stylesheet' href='/vendors/bootstrap-3.1.1/bootstrap.min.css')
link(rel='stylesheet' href='/css/style.css')
link(rel='stylesheet' href='/css/helpers.css')
block head
body
block content
@colelawrence
colelawrence / compile.cmd
Created June 4, 2014 19:36
Compile and watch all coffee files
coffee -o ./ -cbw ./
@colelawrence
colelawrence / cm_config.coffee
Last active August 29, 2015 14:02
CodeMirror 4 use spaces instead of tabs
cm_config = {}
cm_config['extraKeys'] = {
"Tab": checkToUseSpacesInsteadofTabs
}
CodeMirror($(".code")[0], cm_config)