Skip to content

Instantly share code, notes, and snippets.

View ericelliott's full-sized avatar
💭
https://leanpub.com/composingsoftware

Eric Elliott ericelliott

💭
https://leanpub.com/composingsoftware
View GitHub Profile
@ericelliott
ericelliott / localStorage-polyfill.js
Created September 22, 2012 07:33
localStorage polyfill
// Polyfill localStorage for older browsers
(function () {
'use strict';
if (!window.localStorage) {
window.localStorage = {
getItem: function (sKey) {
if (!sKey || !this.hasOwnProperty(sKey)) { return null; }
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
},
key: function (nKeyId) {
@ericelliott
ericelliott / localStorage-polyfill.js
Created October 5, 2012 01:10
localStorage polyfill
// Polyfill localStorage for older browsers
(function () {
'use strict';
if (!window.localStorage) {
window.localStorage = {
getItem: function (sKey) {
if (!sKey || !this.hasOwnProperty(sKey)) { return null; }
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
},
key: function (nKeyId) {
@ericelliott
ericelliott / copy.js
Created October 23, 2012 01:02
copy
var copy = function copy(source) {
if (source === undefined) { return undefined; }
return JSON.parse(JSON.stringify(source));
};
@ericelliott
ericelliott / getenv.js
Created November 9, 2012 00:54
dump environment settings to console from node
var env = process.env;
Object.keys(env).forEach(function(key) {
console.log('export ' + key + '="' + env[key] +'"');
});
@ericelliott
ericelliott / env-examples.md
Last active March 7, 2025 23:39
env-examples

Most configuration really isn't about the app -- it's about where the app runs, what keys it needs to communicate with third party API's, the db password and username, etc... They're just deployment details -- and there are lots of tools to help manage environment variables -- not the least handy being a simple .env file with all your settings. Simply source the appropriate env before you launch the app in the given env (you could make it part of a launch script, for instance).

env files look like this:

SOMEVAR="somevalue"
ANOTHERVAR="anothervalue"

To source it:

$ source dev.env # or staging.env, or production.env, depending on where you're deploying to

@ericelliott
ericelliott / top-down-render.js
Created December 4, 2012 00:23
Backbone Top Down Render
/*
# Top down render
To prevent issues where you get errors trying to
render because your element needs to be attached to the
DOM and visible in order to manipulate without errors,
it is possible to always use a top-down rendering approach.
There are two ways to do it: The parent view can render the
@ericelliott
ericelliott / collection-data-objects.json
Created December 21, 2012 05:47
Evaluating Collection+JSON for hypermedia APIs - this is a comparison of an original object and it's equivalent representation with Collection+JSON
[
{
"name": "uid",
"value": "nim3x1"
},
{
"name": "text",
"value": "LOL everyone is soooooo excited #Backstage today! VIDEO:"
},
{
@ericelliott
ericelliott / body.json
Last active December 10, 2015 03:28
Collection+JSON .findItems()
{ "collection" :
{
"href" : "/touts/pending/",
"items": [
{
"href": "/touts/fk9abg",
"body": {
"uid": "fk9abg",
"text": "It's safe to say that this was the best moment today. LOL #KellyandMichael",

Siren Samples

Siren is a hypermedia type designed for entity representation in JSON. These are some ideas on how you might represent tout collections using Siren.

window.example.pendingToutsSiren = {
  "class": [ "collection" ],
  "properties": {
    "pagination": {
      "offset": 0,
/*global module*/
var pkgData = require('./package.json');
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
pkg: '<json:package.json>',
lint: {
all: ['./grunt.js', './dist/*.js', './test/test.js']
},
jshint: {