Skip to content

Instantly share code, notes, and snippets.

View crutchcorn's full-sized avatar
📒
Writing like whoa

Corbin Crutchley crutchcorn

📒
Writing like whoa
View GitHub Profile
@crutchcorn
crutchcorn / bucketsort.js
Created June 3, 2022 06:49
A naive implementation of bucket sort
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)) {
@crutchcorn
crutchcorn / 1-simple-class-usage.js
Last active May 27, 2022 08:27
Explaination of `this` keyword in JavaScript through a series of Tweets
class Cup {
contents = "water";
consume() {
console.log(
"You drink the ",
this.contents,
". Hydrating!"
);
}
@crutchcorn
crutchcorn / index-based-tracking.js
Last active May 18, 2022 22:43
An explaination of how React Hooks work under-the-hood to persist data across function calls (AKA "renders" of FCs)
/**
* 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};
@crutchcorn
crutchcorn / solids-internals.js
Last active November 13, 2023 19:21
A basic reproduction of how SolidJS's internal attribute reactivity works
let Listener = undefined;
function readSignal() {
if (Listener) {
this.observers.push(Listener)
}
return this.value;
}
@crutchcorn
crutchcorn / ng-pass-validator.ts
Created April 3, 2022 14:22
Angular password validator
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;
}
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: {
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))
// 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 ?
@crutchcorn
crutchcorn / get_keypress.py
Last active November 26, 2021 20:43 — forked from gesquive/get_keypress.py
Get keypress for different platforms
#!/usr/bin/env python3
# get_keypress.py
import sys
import os
def main():
try:
print("press ctrl+c to exit")
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);
}