Skip to content

Instantly share code, notes, and snippets.

View tofumatt's full-sized avatar

Matthew Riley MacPherson tofumatt

View GitHub Profile
@tofumatt
tofumatt / offline.markdown
Last active January 4, 2016 18:09
Offline Storage

localForage: Offline Storage, Improved

Web apps have had offline capabilities like saving large data sets and binary files for some time. You can even do things like cache MP3 files. Browser technology can store data offline and plenty of it. The problem, though, is that the technology choices for how you do this are fragmented.

localStorage gets you really basic data storage, but it's slow and can't handle binary blobs. IndexedDB and WebSQL are asynchronous, fast, and support large data sets, but their APIs aren't very straightforward. Even still, neither IndexedDB nor WebSQL have support from all of the major browser vendors and that doesn't seem like something that will change in the near future.

If you need to write a web app with offline support and don't know where to start, then this is the article for you. If you've ever tried to start working with offline support but it made your head spin, this article is for you too. Mozilla has made a library called

arr = new Uint8Array(8)
dump(arr instanceof Uint8Array) // emits TRUE
localforage.setItem('Uint8Array', arr).then (writeValue) ->
..
// in localstorage.js file
function setItem(key, value, callback) {
__utils__.echo(arr instanceof Uint8Array); // emits FALSE
@tofumatt
tofumatt / test.backbone.coffee
Created March 17, 2014 16:32
Old backbone tests
'use strict'
casper.test.begin "Testing Backbone data adapter", (test) ->
casper.start "#{casper.TEST_URL}test.backbone.html", ->
test.info "Testing using global scope (no require.js)"
test.assertEval ->
typeof Backbone.localforage is 'object'
, "localforage storage adapter is attached to Backbone.localforage"
@tofumatt
tofumatt / manifest.webapp
Created April 4, 2014 18:08
Manifest for IRCCloud
{
"version": "1.0",
"name": "IRCCloud",
"description": "SOME DESCRIPTION",
"icons": {
"32": "/img/icon-32.png",
"60": "/img/icon-60.png",
"64": "/img/icon-64.png",
"90": "/img/icon-90.png",
"120": "/img/icon-120.png",
@tofumatt
tofumatt / podcast.js
Created July 21, 2014 03:33
Backbone Podcasts
/*jshint forin:false, plusplus:false, sub:true */
define([
'zepto',
'underscore',
'backbone',
'app',
'collections/podcasts',
'models/podcast',
'views/dialogs',
'views/episode',
class PostingsController < ApplicationController
after_action :verify_authorized, except: [:index, :archived]
after_action :verify_policy_scoped, only: [:index, :archived]
before_action :require_login
def index
@sortorder = params[:sort]
case @sortorder
when 'date-added'
@method = :order, 'created_at DESC'
Ember.Controller.extend({
actions: {
resort: function(columnName) {
// do stuff with your data here
var stuff = STUFF();
this.set('whatever', stuff);
}
}
});
@tofumatt
tofumatt / models.js
Last active August 29, 2015 14:11
Trying to do offline data with ember-data
import DS from 'ember-data';
var Checkin = DS.Model.extend({
shout: DS.attr('string'),
user: DS.belongsTo('user'),
venue: DS.belongsTo('venue'),
createdAt: DS.attr('date')
});
var User = DS.Model.extend({
i have key/value pairs stored via localforage by the main page, but i cant figure out how to bring up a list of keys for the about page. ng-repeat and ng-option dont seem to work, and i suspect it's because i'm not unwrapping my promises correctly? i dunno.
angular.module('scratchpadApp')
.controller('AboutCtrl', function ($scope, $localForage) {
var getKeys = function() {
localforage.keys()
.then(function(result) {
console.log(result);
$scope.getKeys = result;
@tofumatt
tofumatt / podcast-extract.php
Created July 14, 2015 18:23
Podcast RSS URL Extract
<?php
/*
* Podcast URL Extractor
* implemented at http://itunes.so-nik.com
*
* All code has been re-written by lasavior.
* Original code & inspiration from Michael Sitarzewski, zerologic.com
*
* Ex: http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/viewPodcast?id=269238657