Skip to content

Instantly share code, notes, and snippets.

@benbarnett
benbarnett / raphael-svg-buildjson
Created June 3, 2010 12:59
loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
// loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
buildJSON = function(paper) {
var svgdata = [];
svgdata.push({
width: 390,
height: 400
});
$.each(paper,
@benbarnett
benbarnett / preloadimages.js
Created November 30, 2012 16:08
Preload multiple images
function loadImgs(urls, doneCallback) {
var remaining = total = urls.length;
var imgs = [];
function imgLoad(url) {
if (!--remaining) {
doneCallback(imgs);
}
}
@benbarnett
benbarnett / jquery.fn.translation.js
Created December 22, 2010 11:55
Calculate translation from transform matrix
function translation(elem) {
var cssPrefixes = ["", "-webkit-", "-moz-", "-o-"],
cStyle = window.getComputedStyle(elem, null),
translation = {
x: 0,
y: 0
};
for (var i = cssPrefixes.length - 1; i >= 0; i--){
var transform = cStyle.getPropertyValue(cssPrefixes[i] + "transform");
@benbarnett
benbarnett / vines.txt
Created May 9, 2013 16:09
Vine's from @ben_cameron
Fun times with @mrnickharvey https://vine.co/v/b29EtOb6nw6
Quick message of thanks to everyone for the Vine feedback https://vine.co/v/b2EHtJTpvYv
Vining for the sake of vining https://vine.co/v/b20lwHiPzHD
The truth about my Vines https://vine.co/v/b20xKdM6Xxm
Tough love (the outtake) https://vine.co/v/b20Up1QvJXX
Tough love https://vine.co/v/b20U7ipjZlA
Bus face https://vine.co/v/b211O6QxnE6
I don't like cheesy poofs https://vine.co/v/bQPBI5x5MdK
I don't like cheesy poofs https://vine.co/v/bQPBibOj17A
Wake up! https://vine.co/v/bQHQAjLMUPi
@benbarnett
benbarnett / jquery-animate-enhanced-demo.js
Created November 8, 2010 12:16
demo code on jquery anim enhanced plugin home
$('button#start').click(function() {
var results = $('p#results').html("Animating..."),
button = $(this).attr('disabled', 'disabled');
// CSS3 Container
$('.target-css').animate({left: "+=200px", width:320 }, 1500, function() {
results.html('first callback() fired, reversing...');
$(this).animate({left: "-=200px", width:280 }, 1500, function() {
results.html("second callback() fired");
button.removeAttr('disabled');
@benbarnett
benbarnett / GroupsToPNG.jsx
Created January 17, 2012 15:19
Groups to PNG Photoshop Script
#target photoshop
var sizes = {
'xlarge': [1490, 730],
'large': [1160, 568],
'medium': [890, 436],
'small': [760, 372]
};
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="2988.895px" height="1885.335px" viewBox="0 0 2988.895 1885.335" enable-background="new 0 0 2988.895 1885.335"
xml:space="preserve">
<text transform="matrix(1 0 0 1 117.5674 193.3823)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Amersham</text>
<text transform="matrix(1 0 0 1 285.0654 207.4351)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Chorleywood</text>
<text transform="matrix(1 0 0 1 1316.9741 261.0347)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Mill Hill East</text>
<text transform="matrix(1 0 0 1 306.2056 236.7271)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Rickmansworth</t
@benbarnett
benbarnett / app.js
Created October 15, 2013 11:29
Include cookie sessions
var cookieSessions = require('./modules/cookieSessions');
app.configure(function() {
app.use(express.cookieParser('a9e687e0-a1e0-11e2-9e96-0800200c9a66'));
app.use(cookieSessions('ucheckout'));
});
@benbarnett
benbarnett / cookieSessions.js
Created October 15, 2013 11:28
NodeJS Signed cookies
/**
* Signed session cookies used for persistence
* @param {[type]} name [description]
* @return {[type]} [description]
*/
module.exports = function(name) {
return function(req, res, next) {
req.session = req.signedCookies[name] || {};
@benbarnett
benbarnett / gist:1555873
Created January 3, 2012 17:15
Example friend
<a href="http://twitter.com/benpbarnett" rel="contact">@benpbarnett on Twitter</a>