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 ENABLED = false // Keep this false while testing to verify that it's working correctly | |
const DELETE_INTERVAL = 1000 // Amount of time in MS to wait between deletion (more likely to fail with a small number) | |
// This filter should return a boolean (true == delete video, false == keep video) | |
const MIN_DURATION_MS = 1000 * 60 * 1.5 // 1:30 mins | |
const SHOULD_DELETE = videoElement => { | |
try { | |
// Get the duration string |
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
// Resolves once the check function returns true | |
// You optionally specify the interval at which to poll the check function. Default = 1000ms | |
// TODO: add timeout functionality | |
class PollingPromise extends Promise { | |
constructor(check, interval = 1000){ | |
super(resolve => { | |
if(this.check()){ return resolve() } | |
const interval = setInterval(async () => { |
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
class Pipe { | |
constructor(){ | |
this.onChangeHandler = null | |
this.cache = [] | |
} | |
onChange(fn){ | |
this.onChangeHandler = fn | |
this.flush() | |
} |
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 function chunkArray(array, size) { | |
const chunked_arr = []; | |
let index = 0; | |
while (index < array.length) { | |
chunked_arr.push(array.slice(index, size + index)); | |
index += size; | |
} | |
return chunked_arr; | |
} |
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
// Utility for running recurring tasks | |
// Uses setInterval and setTimeout | |
// Has ability to schedule the first run instantly or wait for a fixed MS | |
export default class RecurringTask { | |
constructor({ | |
task, // can be async | |
intervalMs = 1000, // interval in milliseconds | |
lastRun = 0, // 0 == run immediately |
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
// Returns promise that resolves in ms milliseconds | |
export async function sleep(ms) { | |
return new Promise(resolve => { | |
setTimeout(resolve, ms) | |
}) | |
} |
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
# (use docker droplet) | |
# Install node and npm: | |
sudo apt update | |
sudo apt install nodejs | |
sudo apt install npm | |
# Now, docker + node + npm should be ready. | |
# Yarn, optional: |
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 axios from 'axios' | |
// Extend me! | |
export default class ApiClient { | |
constructor(endpoint, token){ | |
this.endpoint = endpoint | |
this.token = token | |
} | |
async post(path, data){ |
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
// Get all records from { page, limit } style pagination | |
// NOTE: this class assumes that the first page value is 1 (NOT 0) | |
// Tweak the class if your system begins pagination with page 0. | |
class PaginationTraverser { | |
constructor({ limit, getPage }){ | |
// Limit must not exceed server's clamp range or this breaks | |
// very badly (infinite while loop) | |
this.limit = limit | |
this.getPage = getPage |
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
// Very simple item cache (easily add .flush/dump and/or .delete functions if needed) | |
class ItemCache { | |
constructor({ get, init }){ | |
this._items = {} | |
this.getItem = get | |
// use init to initialize the cache: init(set){ getItems, then set(key, | |
// item) for each } | |
this._init = init | |
this._initialized = false |
OlderNewer