Skip to content

Instantly share code, notes, and snippets.

View geddski's full-sized avatar

Dave Geddes geddski

View GitHub Profile
@geddski
geddski / test
Created July 7, 2011 20:39
Test
View test
alert("test");
@geddski
geddski / splice-demo.js
Created August 6, 2011 05:31
Removing elements from an array
View splice-demo.js
var books = ["Ender's Game", "The Hobbit", "The Alliance"];
books.splice(1,1);
console.log(books);
//["Ender's Game", "The Alliance"]
@geddski
geddski / nesting.js
Created January 14, 2012 05:08
helper function for nesting backbone collections.
View nesting.js
function nestCollection(model, attributeName, nestedCollection) {
//setup nested references
for (var i = 0; i < nestedCollection.length; i++) {
model.attributes[attributeName][i] = nestedCollection.at(i).attributes;
}
//create empty arrays if none
nestedCollection.bind('add', function (initiative) {
if (!model.get(attributeName)) {
model.attributes[attributeName] = [];
@geddski
geddski / rAF.js
Created January 20, 2012 21:35 — forked from paulirish/rAF.js
requestAnimationFrame polyfill
View rAF.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@geddski
geddski / npminstall.js
Created March 16, 2012 19:35
test programmatic npm install
View npminstall.js
var npm = require('npm');
npmInstall(['http://dl.dropbox.com/u/3098507/sample.tar.gz'], function () {
console.log('yay');
});
/*
programmatically install some libs with npm
working in OSX but not windows
*/
function npmInstall(libs, callback){
@geddski
geddski / cf.less
Created April 18, 2012 20:06
micro clearfix LESS mixin
View cf.less
/* Micro ClearFix Mixin */
.clearfix{
zoom:1;
&:before, &:after{ content:""; display:table; }
&:after{ clear: both; }
}
@geddski
geddski / base.css
Created August 2, 2012 19:11
mobile (base) stylesheet example
View base.css
body{
background: orange;
}
View vars.json
{
"bg" : "purple",
"spacing" : 0,
"gutter" : "10px",
"queries": {
"small": "screen and (min-width:1px) and (max-width:400px)",
"large": "screen and (min-width:1501px)"
},
"animate": {
"special": {
@geddski
geddski / manual.js
Created December 14, 2012 23:38
example of gzipping files manually in Node
View manual.js
var http = require('http');
var fs = require('fs');
var zlib = require('zlib');
http.createServer(function (req, res) {
// var img = fs.readFileSync('./bird.jpg');
var img = fs.createReadStream('./public/bird.jpg');
// res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.writeHead(200, { 'content-encoding': 'gzip' });
@geddski
geddski / express.js
Created December 14, 2012 23:40
example of using express middleware to gzip xml files
View express.js
var express = require('express');
var connect = require('connect');
var zlib = require('zlib');
var fs = require('fs');
var app = express();
var compressOptions = {
filter: function(req, res) {
return /json|text|xml|javascript/.test(res.getHeader('Content-Type'))
}