Skip to content

Instantly share code, notes, and snippets.

View 1j01's full-sized avatar

Isaiah Odhner 1j01

View GitHub Profile
@1j01
1j01 / blob_to_buffer.js
Last active August 24, 2018 20:33 — forked from davemackintosh/blob_to_buffer.js
Electron blob to buffer, I made this to use with the nativeImage class.
function blob_to_buffer(blob, callback) {
const file_reader = new FileReader()
file_reader.addEventListener("loadend", event => {
if (file_reader.error) {
callback(file_reader.error)
} else {
callback(null, new Buffer(file_reader.result))
}
}, false)
@1j01
1j01 / undo-redo-history.js
Last active June 10, 2019 21:26
Undo/redo history pattern example in JavaScript
// first setup our stacks of history states
// (const refers to the reference to the arrays, but they arrays themselves are mutable)
const undos = [];
const redos = [];
// undo and redo are symmetrical operations, so they *could* be factored to use an "undoOrRedo" / "stepHistory" function that takes two stacks as arguments, but it might be clearer as two functions
const undo = () => {
if (undos.length < 1) { return false; }