Skip to content

Instantly share code, notes, and snippets.

@sorensen
sorensen / danish-heart.css
Created June 28, 2011 16:27
Danish woven heart
/**
Danish woven heart
**/
.heart {
position: absolute;
left: 77px;
width: 3em;
height: 3em;
font-size: 16px;
@sorensen
sorensen / demo.js
Created July 12, 2011 20:21
Raphael icon factory
// If underscore is included on the page it will be added as a mixin,
// otherwise, it will be added to the global namespace
// Basic usage
icon('star', 'some-id-selector');
// Basic underscore usage
_.icon('home', 'home-id-selector');
// Advanced underscore usage
@sorensen
sorensen / fonts.js
Created October 21, 2011 21:45
Google Font API
// Google Font API
// ---------------
(function() {
// Font family definitions to be loaded, this should
// be trimmed to only the families used in production
WebFontConfig = {
google : {
families : [
@sorensen
sorensen / viewport.js
Created October 21, 2011 21:48
Viewport calculation
// Viewport calculations
function viewport() {
var e = window,
a = 'inner';
if (!('innerWidth' in window)) {
a = 'client';
e = document.documentElement || document.body;
}
return {
@sorensen
sorensen / iPad.js
Created October 21, 2011 21:50
iPad and iPhone detection
// iPad - iPhone detection
function iMobile() {
return (
(!!~navigator.platform.indexOf("iPhone")) ||
(!!~navigator.platform.indexOf("iPad"))
);
};
@sorensen
sorensen / push-button.css
Created October 21, 2011 21:55
CSS Push Button
/* =============================================================================
Red push button
========================================================================== */
.push-button {
display: inline-block;
width: 50px;
height: 50px;
background-color: #ff0000;
@sorensen
sorensen / gist:1365458
Created November 14, 2011 22:44
markModified
model.findOne({ name: msg.control.name }, function(err, doc) {
_.extend(doc, {
lifetime: {}
})
Object.keys(msg.data).forEach(function(k) {
doc.lifetime[k] || (doc.lifetime[k] = 0)
doc.lifetime[k] += msg.data[k]
})
@sorensen
sorensen / example.js
Created November 21, 2011 05:12
Modularize
;(function(Room) {
// Dependencies
var Message = module("message")
Room.Model = Backbone.Model.extend({
initialize: function() {
this.set({ messages: new Message.List() })
}
})
@sorensen
sorensen / custom-dnode-session.js
Created December 8, 2011 23:07
DNode/Express Mongoose Authentication
// DNode Session
// =============
var connect = require('connect')
module.exports = function(opt) {
var key = opt.key || 'connect.sid'
, store = opt.store
, interval = opt.interval || 120000
@sorensen
sorensen / hexRGB.js
Created March 20, 2012 17:20
Hex / RGB translation helpers
// http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
hexToRgb = (function() {
var cache = {}
return function(hex) {
if (cache[hex]) return cache[hex]
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
return result ? cache[hex] = {
r: parseInt(result[1], 16)
, g: parseInt(result[2], 16)