CS:Source setup on Ubuntu
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 { strict as assert } from 'node:assert' | |
import fs from 'node:fs' | |
import path from 'node:path' | |
import { afterEach, beforeEach, describe, it } from 'node:test' | |
import { Readable } from 'node:stream' | |
import { findInStream as _find } from './src/utils/findInStream' | |
const findInStream = (pathname: string, search: string) => { | |
return _find(Readable.toWeb(fs.createReadStream(pathname)), search) |
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 UNITS = [ | |
{ | |
multiplier: 1000, | |
name: 'second', | |
threshold: 45, | |
}, | |
{ | |
multiplier: 60, | |
name: 'minute', | |
threshold: 45, |
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 defaultPredicate = (x) => x === null || x === undefined | |
const deepDefaults = (target, defaults, predicate = defaultPredicate) => { | |
if (Object(target) !== target) return Object.assign({}, defaults) | |
return Object.keys(defaults).reduce((acc, key) => { | |
if (Object(defaults[key]) === defaults[key]) { | |
acc[key] = deepDefaults(target[key] || {}, defaults[key], predicate) | |
} else { | |
acc[key] = predicate(target[key], key) ? defaults[key] : target[key] |
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 loadIframe = (url, attributes = {}, target = document.body) => | |
new Promise((resolve, reject) => { | |
const iframe = document.createElement('iframe') | |
const { | |
height = 0, | |
width = 0, | |
style = { | |
display: 'none', | |
}, |
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 map = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9] | |
const luhnCheck = (input) => { | |
const number = String(input).replace(/\D/g, '') | |
let sum = 0 | |
let digit = 0 | |
let i = number.length | |
let even = true | |
while (i) { |
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
/** | |
* Transform a number to any base based on a provided range. | |
* TODO: doesn't support floats. | |
* @param {number} baseTen A regular, primitive integer number | |
* @param {Array<string>} range And array of characters to represent the positional system. | |
* @returns {string} A representation of the provided number in the positional system provided. | |
*/ | |
const toBase = (baseTen, range = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')) => { | |
if (baseTen % 1 > 0) throw new TypeError('Only integers are supported') | |
if (baseTen === 0) return range[0] |
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
/** | |
* Wrapper around requestAnimationFrame for easier usage. | |
* @param {Function} callback Function to call on each tick, receives last value as only param. | |
* @param {*} [initValue] Optional initial value. | |
* @returns {Function} Clear interval function. | |
*/ | |
const tick = (callback, initValue) => { | |
let unsubscribed = false | |
let lastValue = initValue |
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 * as _ from 'lodash' | |
const exclusion = (...arrays) => | |
_.flatMap(arrays, x => _.difference(x, ..._.without(arrays, x))) |
NewerOlder