Skip to content

Instantly share code, notes, and snippets.

View jagomf's full-sized avatar

Jago jagomf

View GitHub Profile
@jagomf
jagomf / open-file-on-click.js
Last active September 29, 2018 17:34
Retrieve a file and convert to base64 upon clicking on something
/**
* Prompts to choose a file from filesystem, converts to base64 (in background), and returns base64 when conversion ends.
* @param {number} maxFileSize Maximum size of file.
* @param {boolean} multiple Indicates whether to accept one or more files.
* @param {string} contentType MIME type of media to require from filesystem (can be 'image/*', etc).
* @param {string} source (For mobile devices only) If set to 'camera', tells device to capture image from camera.
* @returns {Promise} A Promise that resolves when files are read; rejects with error text if files are heavier than allowed.
*/
onClickSendMedia(maxFileSize, multiple = false, contentType = '*/*', source) {
return new Promise((resolve, reject) => {
@jagomf
jagomf / listJoiner.js
Last active August 29, 2015 14:20
Turns an array of items into a String of items separated by middleJoiner and endJoiner
/*
var fruits = ['apple', 'orange', 'banana', 'pear'],
middleJoiner = ', ',
endJoiner = ' and ',
result = listJoiner(fruits, middleJoiner, endJoiner);
*/
// result will be this string: 'apple, orange, banana and pear'
//Iterative way
function listJoinerIter(elems, middleJoiner, endJoiner) {