Skip to content

Instantly share code, notes, and snippets.

View greathmaster's full-sized avatar
🧐

Hersha Venkatesh greathmaster

🧐
  • San Francisco, Bay Area
View GitHub Profile
<iframe src="https://app.box.com/embed/s/0dtgl906gz1vsrqp1w6paqxhwuarn1mv?sortColumn=date" width="500" height="400" frameborder="0" allowfullscreen webkitallowfullscreen msallowfullscreen></iframe>
<iframe src="https://amedmarket.app.box.com/embed/s/z5ywvjsia9qpllfj1yaq7gni6398ql6g?sortColumn=date" width="800" height="550" frameborder="0" allowfullscreen webkitallowfullscreen msallowfullscreen></iframe>
@greathmaster
greathmaster / gist:f25c461d64e48d25735d738cddd83569
Last active March 9, 2023 16:41
Prompt for zshell to show git branch and current directory
# Set color codes for directory and Git branch
dir_color='%F{blue}'
branch_color='%F{green}'
# Set Git branch state color codes
uncommitted_color='%F{red}'
untracked_color='%F{yellow}'
ahead_color='%F{cyan}'
behind_color='%F{magenta}'
conflicted_color='%F{red}'
@greathmaster
greathmaster / debounce-abort-fetch.js
Created March 24, 2021 22:36 — forked from alexnoz/debounce-abort-fetch.js
Abort fetching data in a function when debouncing it
function debounceFetch (fn, delay, onCancel = () => {}) {
let timer = 0, isFetching = false
return function (...args) {
clearTimeout(timer)
if (isFetching) {
onCancel()
isFetching = false
}
@greathmaster
greathmaster / react-hooks-build-a-clock.js
Created March 24, 2021 16:32
React: How to Correctly Build a Counter/Clock/Timer Component Using Hooks
// React: How to Correctly Build a Counter/Clock/Timer Component Using Hooks
//Taken from: https://overreacted.io/making-setinterval-declarative-with-react-hooks/
import React, { useState, useEffect, useRef } from "react";
import ReactDOM from "react-dom";
function Counter() {
const [count, setCount] = useState(0);
const savedCallback = useRef();
@greathmaster
greathmaster / union-find.js
Created December 21, 2020 20:00
Union Find data structure. Both simple with no optimizations and optimized Union Find with Path Compression/Collapsing Find and Union by Rank
class UnionFind {
constructor(size) {
this.nodes = new Array(size).fill(-1)
}
find(i) {
while(true) {
if(i === this.nodes[i]) this.nodes[i] = -1
if(this.nodes[i] < 0) {
return i;
@greathmaster
greathmaster / Leetcode-Problem-114.js
Created August 27, 2020 18:31
Iterative solution for Leetcode Problem 114
//Iterative solution for Leetcode Problem 114.
//Currently having out of memory issues on Leetcode, but runs flawlessly on local Node setup
var flatten = function(root) {
if(root === null) return null;
const DOWN = 1; //represents performing a recursive function call
const UP = 2; //represents returning from a recursive function call
let stack = [];
@greathmaster
greathmaster / quicksort.js
Created July 22, 2020 21:28
Variations on a theme by Quicksort
//Recursive Quicksort using Lomuto's partitioning method
function lomutosPartition(array, start, end) {
let i = start;
let pivot = array[end]
for(let j = start; j < end; j++) {
if(pivot > array[j]) {
[array[j], array[i]] = [array[i], array[j]];
i++;
}
@greathmaster
greathmaster / binary-search-variations-1.js
Created May 26, 2020 18:47
Binary Search Variations
/*
Given an array of 1's and 0's in the following format:
[1, 1, 1, 0, 0]
Use binary search to determine how many 1's are in the array.
You can assume the 1's will always appear together and at the
beginning of the array.
*/
function bs(array) {
@greathmaster
greathmaster / .block
Created March 24, 2020 19:14 — forked from mbostock/.block
Ocean
license: gpl-3.0