Skip to content

Instantly share code, notes, and snippets.

View daftAnorak's full-sized avatar

Will Bradley daftAnorak

  • Dallas, TX
  • 15:13 (UTC -05:00)
View GitHub Profile
@daftAnorak
daftAnorak / magicNumbers.js
Last active February 8, 2023 17:26
Code Exercise for JS Position - Magic Numbers
/**
* Method which takes a given, natural number and calculates
* a series of magic numbers until a number repeats (returns false),
* or equals 1 (returns true).
*
* EX: fn(1) === true // (1 equals 1)
* EX: fn(7) === true // (7 -> 49 -> 97 -> 130 -> 10 -> 1)
* EX: fn(11) === false // (11 -> 2 -> 4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4 [repeat])
*
* @param {number} x - given, natural number
@daftAnorak
daftAnorak / wildcard-matching.js
Last active February 6, 2023 18:46
Code Exercise for JS position - Wildcard Matching
/**
* Validates if given string matches given pattern
* @param {string} s - given string
* @param {string} p - given pattern
* @return {boolean} string matches pattern
*/
function isMatch(s, p) {
let sIdx = 0;
let pIdx = 0;
@daftAnorak
daftAnorak / number-to-english.js
Created February 1, 2023 18:24
Code Exercise for JS Role - Convert number to English (US) equivalent
const cardinalsMap = new Map([
[0, 'zero'],
[1, 'one'],
[2, 'two'],
[3, 'three'],
[4, 'four'],
[5, 'five'],
[6, 'six'],
[7, 'seven'],
[8, 'eight'],
@daftAnorak
daftAnorak / remove-islands.js
Last active February 2, 2023 03:51
Code Exercise for JS Role - Remove islands from an image matrix
/**
* creates key from coordinates (for mapping)
* @param {number} r - row number
* @param {number} c - column number
*
* @returns {string} string key
*/
const toKey = (r, c) => `${r}|${c}`;
/**
@daftAnorak
daftAnorak / words-in-tiles.js
Created February 1, 2023 16:21
Coding Exercise for JS position
const tilePoints = {
a: 10,
b: 5,
c: 2,
t: 1,
// TODO - add more tile points for different letters
_: 0,
};
/**
@daftAnorak
daftAnorak / utils-type.ts
Created January 30, 2023 16:22
Typescript utility for safely, and quickly, building upon given structures.
/**
* Type for the utility helper
* @paramtype T - type of object the utils are designed around
*/
export type Utils<T> = {
build: (a?: Partial<T>) => T;
} & {
[K in keyof T as `buildOn${Capitalize<string & K>}`]: (a: T[K]) => T;
} & {
[K in keyof T as `get${Capitalize<string & K>}`]: (a: Partial<T>) => T[K] | undefined;
@daftAnorak
daftAnorak / largest-rectangle-from-histogram.js
Created March 6, 2019 20:44
Function which calculates the largest area from a range of histogram points
/**
* Largest Rectangle from Histogram
*
* function which takes a range of histogram points,
* (array of natural numbers [or zero]), and returns the
* largest rectangle area that can fit inside of it.
*
* @param {Array<Number>} points The range of histogram points
* @return {Number} The largest rectangle area
*
@daftAnorak
daftAnorak / .gitattributes
Created February 21, 2017 20:23
Personal Configuration for new Git repo
# convert all text files to unix-style
* text eol=lf
# configure as text files
*.css text
*.eslintignore text
*.eslintrc text
*.foreverignore text
*.gitattributes text
*.gitignore text
@daftAnorak
daftAnorak / v-node-2-ng-component.js
Created February 16, 2017 15:16
Attempting to bind InfernoJS with a pre-existing Angular (v 1.5) app.
/**
* Angular Hook Module
* @module vNode2NgComponent
*/
// ============================================================================
// Imports
//
import R from 'ramda';
import { infernoRender as iRender } from './utils';
@daftAnorak
daftAnorak / lint-on-changed-files-only.sh
Created February 15, 2017 23:55
Run eslint against a git commit (in this case, `HEAD`). Usually needed when migrating code that doesn't already have a lint.
# !/bin/bash
FILES=`{ git diff --name-only HEAD; \
git ls-files --others --exclude-standard; } \
| grep '\.js$' \
| grep -v '^.*exclude-folder.*$'`
node_modules/.bin/eslint $FILES -f table --color --quiet