This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adds query params to existing URLs (inc merging duplicates) | |
* @param {string} url - src URL to modify | |
* @param {object} params - key/value object of params to add | |
* @example | |
* // returns /guides?tag=api | |
* addQueryParamsToUrl('/guides?tag=hardware', { tag:'api' }) | |
* @example | |
* // returns https://orcascan.com/guides?tag=api | |
* addQueryParamsToUrl('https://orcascan.com/guides?tag=hardware', { tag: 'api' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disable DPMS. | |
xset s off # don't activate screensaver | |
xset -dpms # disable DPMS (Energy Star) features. | |
xset s noblank # don't blank the video device | |
# Create a RAM disk to use as a FIFO for streaming. | |
if [ ! -d /iwk ]; then | |
mkdir /tmp/rdisk | |
fi | |
mount -t tmpfs -o size=25M tmsfs /tmp/rdisk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a URL into a readable filename safe string | |
* - sort query params | |
* - remove protocol | |
* - replace / with ! | |
* - replace ? with !! | |
* - replace remaining illegal characters with - | |
* @example | |
* INPUT: convertUrlToReadableFilename('https://orcascan.com/guides/how-to-scan-barcodes-into-microsoft-excel-59fd67f9'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Executes an array of functions that return a promise in sequence | |
* @example | |
* promisesInSequence([ | |
* function() { return Promise.resolve(1); } | |
* function() { return Promise.resolve(2); }, | |
* function() { return Promise.resolve(3); } | |
* ]) | |
* .then(function(result) { | |
* console.log(result.join(',')); // output = 1,2,3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wait for the browser to fire an event (including custom events) | |
* @param {string} eventName - Event name | |
* @param {integer} seconds - number of seconds to wait. | |
* @returns {Promise} resolves when event fires or timeout is reached | |
*/ | |
async function waitForEvent(eventName, seconds) { | |
seconds = seconds || 30; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Waits for multiple DOM events to fire | |
* @example | |
* waitForEvents(window, [ | |
* 'DOMContentLoaded', | |
* 'online' | |
* ]) | |
* .then(function(result) { | |
* // do stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fileStorage = { | |
/** | |
* Saves a file on the device | |
* @param {string} name - filename (can include sub folders) | |
* @param {string} data - file contents | |
* @param {boolean} useSandbox - uses protected sandbox if true, otherwise external (default false) | |
* @returns {Promise} executes .then with saved file path as first param | |
*/ | |
write: function (name, data, useSandbox) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* local storage helper (takes care of casting types) | |
*/ | |
var localStorageHelper = { | |
/** | |
* Check if item exists in local storage. | |
* @param {string} key - variable name | |
* @return {boolean} true if key exists, otherwise false | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trimSvgWhitespace() { | |
// get all SVG objects in the DOM | |
var svgs = document.getElementsByTagName("svg"); | |
// go through each one and add a viewbox that ensures all children are visible | |
for (var i=0, l=svgs.length; i<l; i++) { | |
var svg = svgs[i], | |
box = svg.getBBox(), // <- get the visual boundary required to view all children |