Skip to content

Instantly share code, notes, and snippets.

View JustSteveKing's full-sized avatar
🐘
Building API tools and educational content

Steve McDougall JustSteveKing

🐘
Building API tools and educational content
View GitHub Profile
@JustSteveKing
JustSteveKing / localStorage.async.js
Created March 2, 2017 15:18
Using JavaScript Promises to stop render blocking with localStorage
class Storage {
get(item) {
const request = new Promise((resolve, reject) => {
let data = localStorage.getItem(item);
console.log(`Start of promise`);
(data) ? resolve(data) : reject();
});
request.then((data) => {
console.log(`promise resolved`);
@JustSteveKing
JustSteveKing / localStorage.size.js
Created March 2, 2017 15:11
A little script to check the size of your localStorage - for management purposes
let total = 0, amount, item;
for (item in localStorage) {
amount = ((localStorage[item].length + item.length) * 2);
total += amount;
}
console.log(`Total = ${(total / 1024).toFixed(2)}KB`);
@JustSteveKing
JustSteveKing / event.js
Created March 2, 2017 15:09
Custom Event Handler
class Event {
constructor() {
this.events = {};
}
fire(event, data) {
const Event = this.events[event];
if( Event ) {
Event.forEach(callback => {
callback.call(null, data);
@JustSteveKing
JustSteveKing / AccountController.php
Last active January 7, 2016 16:22
Using polymorphism in Laravel Auth
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Identity;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class AccountController extends Controller {