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
export const fetchAsBlob = url => fetch(url) | |
.then(response => response.blob()); | |
export const convertBlobToBase64 = blob => new Promise((resolve, reject) => { | |
const reader = new FileReader; | |
reader.onerror = reject; | |
reader.onload = () => { | |
resolve(reader.result); | |
}; | |
reader.readAsDataURL(blob); |
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
import Ember from 'ember' | |
const { Component } = Ember | |
export default Component.extend({ | |
// props | |
availableItems: undefined, | |
selectedItem: undefined, | |
onSelectItem: undefined, | |
}) |
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
import Ember from 'ember' | |
const { Component } = Ember | |
export default Component.extend({ | |
// properties | |
options: undefined, | |
selectedOption: undefined, | |
onChange: undefined, | |
}) |
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
export const once = (func: Function): Function => { | |
let called = false | |
let cachedValue = undefined | |
return (...args) => { | |
if (!called) { | |
cachedValue = func(...args) | |
called = true | |
} | |
return cachedValue | |
} |
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
const createEmitter = () => { | |
const handlersByEvent = new Map() | |
const on = (event, handler) => { | |
let handlers = handlersByEvent.get(event) | |
if (!handlers) { | |
handlers = [] | |
handlersByEvent.set(event, handlers) | |
} | |
handlers.push(handler) |
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 rmrf (fs, directory, callback) { | |
fs.readdir(directory, function (err, list) { | |
if (err) return callback(err); | |
async.everySeries(list, function (item, callback) { | |
var filename = path.join(directory, item); | |
var stats = fs.stat(filename, function (err, stat) { | |
if (err) return callback(err); | |
if (filename === '.' || filename === '..') return callback(); | |
if (stat.isDirectory()) return rmrf(fs, filename, callback); | |
fs.unlink(filename, callback); |
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
import knex from 'knex' | |
import knexConfig from 'SUMWHERE' | |
const prepareDatabase = async () => { | |
const migrationTables = [`knex_migrations`, `knex_migrations_lock`] | |
const knexInstance = knex(knexConfig) | |
const closeConnection = pify(knexInstance.destroy) | |
const tableNames = await knexInstance(`pg_tables`) | |
.select(`tablename`) | |
.where(`schemaname`, `public`) |
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
const pLimit = require('p-limit'); | |
const os = require('os'); | |
const fs = require('fs'); | |
const fsLimit = pLimit(process.env.UV_THREADPOOL_SIZE || 64); | |
const processLimit = pLimit(os.cpus().length); | |
const mkdir = (...args) => fsLimit(() => promisify(fs.mkdir)(...args)); | |
const writeFile = (...args) => fsLimit(() => promisify(fs.writeFile)(...args)); | |
const readFile = (...args) => fsLimit(() => promisify(fs.readFile)(...args)); |
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
import { useEffect, useState } from "react"; | |
const useDebouncedInputValue = ( | |
initialValue: string, | |
debounceDuration: number = 200 | |
): [string, string, (val: string) => void] => { | |
const [currentValue, setCurrentValue] = useState(initialValue); | |
const [debouncedValue, setDebouncedValue] = useState(currentValue); | |
useEffect(() => { |
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
if (!window.OffscreenCanvas) { | |
window.OffscreenCanvas = class OffscreenCanvas { | |
constructor(width, height) { | |
this.canvas = document.createElement("canvas"); | |
this.canvas.width = width; | |
this.canvas.height = height; | |
this.canvas.convertToBlob = () => { | |
return new Promise(resolve => { | |
this.canvas.toBlob(resolve); |