Skip to content

Instantly share code, notes, and snippets.

View bradtaniguchi's full-sized avatar
😌
Developing

Brad bradtaniguchi

😌
Developing
View GitHub Profile
// **NOTE** this doens't even get to the prompt yet, only setup that I think is correct.
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString: string = '';
let inputLines: string[] = [];
let currentLine: number = 0;
process.stdin.on('data', function(inputStdin: string): void {
inputString += inputStdin;
@bradtaniguchi
bradtaniguchi / living-clojure-let-example.clj
Last active September 1, 2021 23:14
Living Clojure book snippet example for let
(ns wonderland
(:require [clojure.set :as s]))
(defn common-fav-foods
[foods1 foods2]
(let [food-set1 (set foods1)
food-set2 (set foods2)
common-foods (s/intersection foods-set1 foods-set2)]
(str "Common Foods: " common-foods)))
;; TODO: add execution call examples.
@bradtaniguchi
bradtaniguchi / reverse-words.clj
Created September 1, 2021 20:48
reverse words in clojure using macros
;; reverses a list of words, from codewars challenge, solution provided from @alpox on Discord
;; https://www.codewars.com/kata/51c8991dee245d7ddf00000e/train/clojure
(defn reverse-words [words]
(-> words
(clojure.string/split #" ")
(reverse)
(->> (clojure.string/join " ")))
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
// fix for copilot
"editor.autoClosingBrackets": "languageDefined"
},
"[html]": {
@bradtaniguchi
bradtaniguchi / binary-heap-utils.js
Created August 25, 2021 03:20
a collection of utility functions to help remember how a binary tree works
// returns the parent-index, will return -1 if no parent
const getParentIndex = i => Math.floor((i - 1) / 2);
// returns the left-child index.
const getLeftChild = i => i * 2 + 1;
// returns the right-child index
const getRightChild = i => i * 2 + 2;
@bradtaniguchi
bradtaniguchi / min-heapify.js
Created August 24, 2021 03:58
min-heapify JS implementation, saved as a study guide, and starting point.
/**
* Heapify function example copied directly from:
* https://dandkim.com/js-heap-implementation/#minheapify
*
* credit goes to https://www.linkedin.com/in/dougouk
*
*/
function minHeapify (array, index) {
const temp = array[index]
let childIndex
/*
*
* Complete the 'matchingStrings' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. STRING_ARRAY strings
* 2. STRING_ARRAY queries
*
* @param strings {string[]} array of strings to compare against
@bradtaniguchi
bradtaniguchi / branded-types.md
Last active August 6, 2021 21:15
"Branded types" is a way to represent a "unique type of string", or "nominal string" type.

The "branded type" approach fixes the following problem:

type UserId = string;
type GroupId = string;

const myUserId: UserId = '1';
const myGroupId: GroupId = '2';

const getUser = (userId: UserId) => {/*stuff*/};
const sortStringsByVowels = (strings) =>
strings
.map((word) => ({
value: word.split("").reduce(
({ longest, current }, char) =>
"aeiouAEIOU".split("").includes(char)
? (current += 1) && {
longest: Math.max(longest, current),
current,
}
import { Observable, defer } from 'rxjs';
interface QueueItem {
req: string;
resolve: (req: string) => void;
}
const requestQueue: QueueItem[] = [];
const DELAY = 800;