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 format = (format: string, ...args: Serializable[]): string => { | |
args.forEach((arg, i) => { | |
assert( | |
typeof arg === 'string' || | |
(typeof arg === 'number' && !isNaN(arg)) || | |
(Array.isArray(arg) && arg.every((v) => typeof v === 'string' || !isNaN(v))), | |
`The argument #${i + 1} must be a valid number, a string, or an array of valid numbers or strings, got a ${typeof arg === 'number' ? 'NaN' : typeof arg} instead (${String(arg)})`, | |
); | |
}); |
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 step = Math.PI / 20; // step in radians | |
const raduus = 2.0; | |
const center = { x: 3.0, y: 2.0 }; // [x, y] | |
const points = []; | |
for (let angle = 0; angle < Math.PI * 2; angle += step) { | |
const initPoint = { x: 0.0, y: raduus }; | |
const rotatedPoint = { |
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
async function checkAvgPerf() { | |
const numberOfReads = 100000; | |
const numberOfTests = 100; | |
const eps = 0.000001; | |
const mapAvg = []; | |
const objAvg = []; | |
let mapSlowerOnAvgTimes = 0; | |
let objSlowerOnAvgTimes = 0; | |
let equalTimes = 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
// `ReadonlyArrayView` class allows to avoid copying when creating array slices | |
// It can be used as a drop-in replacement instead of an array but only gives read access to the original array | |
// Worth remembering that this class doesn't track index change, element reordering, etc., so use it at your own risk | |
// | |
// Demo: | |
// https://www.typescriptlang.org/play?module=1#code/C4TwDgpgBASghgOwObQLxQN4FgBQUoBmATgPYC2AkggCYQAeAXFAgK5kBGERA3LvsCSq1GzNpx64Avrxy56YEkWBQAxgBs4AZ02wIcaiQRqQAQSJE4IAGoBLCAHcAPABUAfFBtkwaiGQgJgHTMLEAAZGwBrCBd3bDwoIj0DIxAoAG0EJlYOLgBdJmdcPigwIhsANzhgaBVDTWAiFhUBIgAKUoqq6ET9Q2MoOHNLArTcgBoSssrqhKS+1ItkCCZ4JYBKTEki+PqqmxUoEgIY1sGQkfGExBQV64g1lbmU4MtbBxjMYvxahHqocrs9ig6AQDl0vWeQ2sgJOZ0sE0WKDWMi+qjqygQhgAwnA1Bp2D5gVBWhtULFUfwABakIGgoEAUXMilaAHIcQhMcoVLi1FBgJSbDotANCCwEM0bIYWcjUdJtvh8IlgCwiAhmGCAAqkOggVoAhwTOIKhVwMDeEBZbE8uAEiBjClo34NJrAS0IHF4m0+e3xY20Ag2UFakiQJQW5hWz22n3G-C0HzVYOh0Buj3470Okj2BAAaQgIE0TBJwPcaRZPmQ-JZExZUQL1agLMqahYEE0DZZAgAyg1A0gWeMHShXcTgINhxMwBMAPqk8m+2M2AjEsAeNVjojDjZG2PGpUq9f |
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 generateRegexp = (str: string): string => { | |
const ranges = uniq( | |
uniq([...str]).map((char) => { | |
if (char.match(/[a-z]/) != null) { | |
return 'a-z'; | |
} | |
if (char.match(/[A-Z]/) != null) { | |
return 'A-Z'; | |
} |
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
# Add this file to ~/.oh-my-zsh/themes/gentoo-custom.zsh-theme | |
# Then, in your ~/.zshrc, set ZSH_THEME to "gentoo-custom" like this: | |
# ZSH_THEME=gentoo-custom | |
function prompt_char { | |
if [ $UID -eq 0 ]; then echo "#"; else echo $; fi | |
} | |
git_branch() { | |
local branch=$(git rev-parse --abbrev-ref HEAD 2>&1) |
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
#!/usr/bin/env bash | |
chooseConsole() { | |
declare -a consoles=('PS4' 'PS4 Pro' 'Xbox One' 'XBox One S', 'Nintendo Switch', 'PS5', 'Xbox Series X') | |
local index=$(( $[$RANDOM % ${#consoles[@]}] )) | |
echo "${consoles[$index]}" | |
} | |
echo "You should get $(chooseConsole)" |