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 bucketSort(arrToSort) { | |
const buckets = {} | |
for (let num of arrToSort) { | |
buckets[num] = buckets[num] ?? []; | |
buckets[num].push(num); | |
} | |
let newArr = [] | |
for (let i of Object.keys(buckets)) { |
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 Cup { | |
contents = "water"; | |
consume() { | |
console.log( | |
"You drink the ", | |
this.contents, | |
". Hydrating!" | |
); | |
} |
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
/** | |
* This is similar to how React tracks hook's data under-the-hood | |
*/ | |
const state = []; | |
let idx = 0; | |
function useState(init) { | |
const id = ++idx; | |
state[id] = state[id] ?? {val: init}; |
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
let Listener = undefined; | |
function readSignal() { | |
if (Listener) { | |
this.observers.push(Listener) | |
} | |
return this.value; | |
} |
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 passwordValidator(control: AbstractControl): ValidationErrors | null { | |
let errors: ValidationErrors = {}; | |
const value = control.value; | |
if (!/[0-9]/.exec(value)) { | |
errors['hasNoNum'] = true; | |
} | |
if (!/[A-Z]/.exec(value)) { | |
errors['hasNoUppercase'] = true; | |
} |
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 path = require("path"); | |
const CopyPlugin = require("copy-webpack-plugin"); | |
const BundleAnalyzerPlugin = | |
require("webpack-bundle-analyzer").BundleAnalyzerPlugin; | |
const root = path.resolve(__dirname, "./"); | |
module.exports = { | |
name: "seaside-react", | |
entry: "./src/index.tsx", | |
externals: { |
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 promisify = (fn) => { | |
return (...args) => { | |
return new Promise(resolve => { | |
fn(...args, (...data) => resolve(...data)) | |
}) | |
} | |
} | |
promisify((one, cb) => cb(one))(1).then(one => console.log(one)) |
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
// NaN also, but `typeof NaN` === number | |
type Falsy = false | null | undefined | 0 | -0 | 0n | ""; | |
type AnyArray<T> = Array<T> | ReadonlyArray<T> | |
type DeepReplaceKeysPartialObj<Obj extends object, T> = { | |
[key in keyof Obj]: | |
Obj[key] extends AnyArray<infer Q> ? | |
DeepReplaceKeys<Q, T> : | |
Obj[key] extends object ? |
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 python3 | |
# get_keypress.py | |
import sys | |
import os | |
def main(): | |
try: | |
print("press ctrl+c to exit") |
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
str = 'a/b/c/d/e/f' | |
p = [] | |
toCount = str.length; | |
for (let n = 0; n < toCount; n++) { | |
if (str[0] !== '/') { | |
p.push(str[0]); | |
} | |
str = str.slice(1, str.length); | |
} |