Skip to content

Instantly share code, notes, and snippets.

View michael-lettona's full-sized avatar

Mike Lettona michael-lettona

  • DigiCert Inc
  • Los Angeles, CA / Lehi, UT
  • 22:16 (UTC -06:00)
  • LinkedIn in/mlettona
View GitHub Profile
@michael-lettona
michael-lettona / waitForKeyElements.js
Created March 8, 2016 01:10 — forked from BrockA/waitForKeyElements.js
A utility function, for Greasemonkey scripts, that detects and handles AJAXed content.
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
@michael-lettona
michael-lettona / README.md
Created February 9, 2016 20:12 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@michael-lettona
michael-lettona / blob-filereader-localStorage.js
Last active September 2, 2015 01:20 — forked from robnyman/blob-filereader-localStorage.js
Get file as a blob, read through FileReader and save in localStorage
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR and FileReader objects
var xhr = new XMLHttpRequest(),
// IndexedDB
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB,
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction,
dbVersion = 1;
/*
Note: The recommended way to do this is assigning it to window.indexedDB,
to avoid potential issues in the global scope when web browsers start
removing prefixes in their implementations.
@michael-lettona
michael-lettona / Create-IndexedDB-objectStore.js
Last active September 2, 2015 01:20 — forked from robnyman/Create-IndexedDB-objectStore.js
Create IndexedDB objectStore
// Create an objectStore
console.log("Creating objectStore")
dataBase.createObjectStore("elephants");
@michael-lettona
michael-lettona / Open-IndexedDB-transaction.js
Last active September 2, 2015 01:20 — forked from robnyman/Open-IndexedDB-transaction.js
Open IndexedDB transaction
// Open a transaction to the database
var transaction = db.transaction(["elephants"], IDBTransaction.READ_WRITE);
// Put the blob into the dabase
transaction.objectStore("elephants").put(blob, "image");
@michael-lettona
michael-lettona / retrieve-indexeddb-file-create-object-url.js
Last active September 2, 2015 01:19 — forked from robnyman/retrieve-indexeddb-file-create-object-url.js
Retrieve stored file from IndexedDB and create an ObjectURL
// Retrieve the file that was just stored
transaction.objectStore("elephants").get("image").onsuccess = function (event) {
var imgFile = event.target.result;
console.log("Got elephant!" + imgFile);
// Get window.URL object
var URL = window.URL || window.webkitURL;
// Create and revoke ObjectURL
var imgURL = URL.createObjectURL(imgFile);
(function () {
// IndexedDB
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB,
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction,
dbVersion = 1.0;
// Create/open database
var request = indexedDB.open("elephantFiles", dbVersion),
db,
createObjectStore = function (dataBase) {