Skip to content

Instantly share code, notes, and snippets.

View danb-humaan's full-sized avatar

Dan Barrett danb-humaan

  • Humaan
  • Perth, Australia
View GitHub Profile
/**
* Saves an item in localStorage so it can be retrieved later. This method automatically encodes the value as JSON, so you don't have to. If you don't supply a value, this method will return false immediately.
*
* @example <caption>set localStorage that persists until it is manually removed</caption>
* LocalStorage.setItem('key', 'value');
*
* @example <caption>set localStorage that persists for the next 30 seconds before being busted</caption>
* LocalStorage.setItem('key', 'value', 30);
*
* @kind function
/**
* Fetches the value associated with key from localStorage. If the key/value aren't in localStorage, you can optional provide a callback to run as a fallback getter.
* The callback will also be run if the localStorage cache has expired. You can use {@link LocalStorage#setItem} in the callback to save the results from the callback back to localStorage.
*
* @example <caption>Fetch from localStorage with no callback and get the response returned.</caption>
* var response = LocalStorage.getItem('key');
*
* @example <caption>Fetch from localStorage and handle response in a callback.</caption>
* LocalStorage.getItem('key', function(response) {
* if (response === null) {
removeItem: function (key) {
if (this.supportsLocalStorage()) {
localStorage.removeItem(key);
}
}
var ls = require('lib/LocalStorage');
// These examples assume you are using jQuery for AJAX calls.
// Closure usage
ls.getItem('devices', function(devices) {
if (devices === null) {
$.ajax({
url: '/data/devices.json',
dataType: 'json',
method: 'get'
@danb-humaan
danb-humaan / get_commit_hash.php
Created October 10, 2016 05:41
Helper function to get a git commit hash from a few sources.
<?php
if (!function_exists('get_commit_hash')) {
/**
* Checks to see if we have a .commit_hash file or .git repo and return the hash if we do.
*
* @return null|string
*/
function get_commit_hash()
{