Skip to content

Instantly share code, notes, and snippets.

View funkjunky's full-sized avatar
🏳️‍🌈

Sophie McCarrell funkjunky

🏳️‍🌈
View GitHub Profile
@funkjunky
funkjunky / flatten.js
Created October 24, 2016 20:33
Flatten's an array any level deep. (for Citrus Byte) [written in ES6 JS]
//Mutable version
const flatten = (arr) =>
arr.reduce((c, v) =>
(Array.isArray(v))
? c.concat(flatten(v))
: [...c, v]
, []);
//or more effecient, in place
const flatten_in = (arr) =>
if(module.hot) {
module.hot.accept(() => {
window.store.replaceReducer(reducer)
window.cancelAnimationFrame(window.raf);
window.raf = window.requestAnimationFrame(step)
});
}
function step(dt) {
graphics(window.ctx, window.store.getState(), dt);
@funkjunky
funkjunky / chunkedFileStreaming.js
Created July 28, 2018 20:03
This is some fun code I had written to handle uploading any number of files of any size, using compression and streaming. (Note: Node doesn't require you convert a stream to an iterator)
export const webFileToResumableDescriptor = (file, uploadId) => async function(chunkSize) {
uploadId = uploadId || file.name;
return {
bytesCount: file.size,
uploadId: uploadId,
filename: file.name,
generator: async function*() {
let chunkIndex = 0;
// While starting byte is less than the file size, continue.