Skip to content

Instantly share code, notes, and snippets.

// CM: forked to address key size (not just value size), swapping between KB and MB, ordering by size and logging total localstorage size.
// based on answer to question
// http://stackoverflow.com/questions/4391575/how-to-find-the-size-of-localstorage
(function showLocalStorageSize() {
threshold = 256; // the point where we stop displaying KB and start with MB
function stringSizeBytes(str) {
return str.length * 2;
}
@pixelthing
pixelthing / feature-detection.js
Last active February 14, 2017 10:22
browser feature detection
// Screen orientation:
if (typeof screen.orientation !== 'undefined') {
data.orientation = screen.orientation.angle;
} else if (typeof window.orientation !== 'undefined') {
  data.orientation = window.orientation;
}
// screen width/height
@pixelthing
pixelthing / gist:8a33f3f783d7d3eca1ca
Created March 14, 2015 01:30
VHN: local storage json speed-up
Using local storage and webworkers to speed up the UX for the homepage ajax requests, and possibly local caching of search results.
- Why use local storage? For subsequent page loads, it makes the homepage load feel instant if the ajax calls don't need to happen (but are instead deferred)
- Why use webworkers? It offloads the ajax calls to another thread (minor win), plus the intensive work of diffing cached and new json data to see if it's been updated is offloaded and doesn't slow the main thread (major win - I guess).
** Angular controller (eg recommendedController)
- wants a json feed of items.
- calls getcacheitems() on a promise
- getcacheitems() returns error or data
- does angular stuff to display data
@pixelthing
pixelthing / gist:9955793
Last active August 29, 2015 13:58
uStyle mixin to modify the select menu with different colours/dimensions (simplifies the SVG stuff)
/* mixin to extend the us select box and allow colour/size tweaks */
@mixin us-form-select($base-color: $select-base-color, $text-color: inherit, $bg-color: white, $height: 2.4em, $padding: 0.3em 0.6em, $hover-color: $select-hover-color, $active-color: $select-active-color)
@extend .us-form-select
height: $height
padding: $padding
border-color: $base-color
background-color: $bg-color
@if $text-color != inherit
color: $text-color
+transition(border-color 200ms,color 200ms)
@pixelthing
pixelthing / gist:9782842
Last active August 29, 2015 13:57
SASS CSS animation mixin
/* animation mixins */
@import "compass/css3/shared"
@mixin animation ($animation_name, $duration: 500ms, $fill_mode: forwards, $iteration_count: 1, $delay: 0, $direction: normal, $timing_function: ease)
+experimental(animation-name, $animation_name)
+experimental(animation-duration, $duration)
@if $fill_mode != none
+experimental(animation-fill-mode, $fill_mode)
@if $iteration_count != 1
+experimental(animation-iteration-count, $iteration_count)
@if $delay != 0