Skip to content

Instantly share code, notes, and snippets.

@catkins
catkins / output
Last active August 29, 2015 14:00
Ember Data Issue #1254

Referenced in Ember Data issue #1254

I put some breakpoints in the findHasMany method for the REST serializer, and noticed that the trace was quite different on subsequent recursions.

@catkins
catkins / toy-robot.md
Last active August 29, 2015 14:08
Toy Robot

toy-robot

toy-robot is a simulator of a toy robot that moves on a tabletop.

usage

toy-robot reads instructions from STDIN, executing them one at a time until EOF is reached. (On a Linux or OSX system, type C-d to generate an EOF character).

valid commands

PLACE X,Y,FACING

@catkins
catkins / localstorage-strings.js
Last active August 29, 2015 14:09
Local Storage example
if (!window.localStorage) {
alert("Your browser doesn't support local storage!");
}
// method based approach
localStorage.setItem('textSize', 'giant');
localStorage.getItem('textSize'); // => "giant"
// index accessor approach
localStorage['selectedTab'] = 'preferences'
@catkins
catkins / localstorage-complex-types.js
Created November 16, 2014 05:00
Local Strorage with complex types
localStorage.setItem('numbers', [1, 2, 3]);
localStorage.getItem('numbers') // => "1,2,3"
var hash = { hello: 'world' }
localStorage.setItem('myHash', hash);
localStorage.getItem('myHash') // => "[object Object]"
@catkins
catkins / localstorage-json.js
Created November 16, 2014 05:01
Local Storage with JSON support
function saveItem(key, value) {
var json = JSON.stringify(value);
localStorage.setItem(key, json);
}
function loadItem(key) {
var json = localStorage.getItem(key);
return JSON.parse(json);
}
App.StorageService = Ember.Object.extend({
persistence: window.localStorage,
namespace: 'ember-storage-service',
// ...
});
unknownProperty: function(key) {
var namespacedKey = this._key(key);
var payload = this.get('persistence').getItem(namespacedKey);
return this._deserialize(payload);
},
_deserialize: function(value) {
return JSON.parse(value);
},
setUnknownProperty: function(key, value) {
var namespacedKey = this._key(key);
var payload = this._serialize(value);
this.get('persistence').setItem(namespacedKey, payload);
this.notifyPropertyChange(key);
return true;
},
_serialize: function(value) {
return JSON.stringify(value);
Ember.Application.initializer({
name: "storageService",
initialize: function(container, application) {
application.register('service:storage', application.StorageService, {
singleton: true
});
application.inject('route', 'storage', 'service:storage');
{{input value=storage.name placeholder='Enter your name'}}
<h3>Welcome back {{storage.name}}!</h3>