Skip to content

Instantly share code, notes, and snippets.

View keif's full-sized avatar

Keith Baker keif

View GitHub Profile
@keif
keif / mark_as_done.py
Last active March 13, 2025 23:32
This script fetches all GitHub notifications, checks if their associated issues or pull requests are closed/merged, and marks them as done by deleting them via the GitHub API.
import requests
import os
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
# Get GitHub token from environment variable
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')
if not GITHUB_TOKEN:
raise ValueError("Missing GITHUB_TOKEN environment variable")
@keif
keif / hashtable.js
Created February 21, 2025 18:46
In Javascript, create a hash table from scratch.
class HashTable {
constructor(size = 53) {
this.buckets = Array.from({ length: size }, () => new Map()); // Use Map instead of arrays
this.size = size;
}
_hash = (key) =>
[...key].reduce((acc, char) => (acc + char.charCodeAt(0) * 23) % this.size, 0);
set(key, value) {
@keif
keif / hashmapFunctional.js
Last active February 21, 2025 18:47
In Javascript, create a hash table from scratch without using Map or Set.
function createHashTable(size = 53) {
// Initialize an array of given size to store key-value pairs (buckets)
const buckets = new Array(size);
// Hash function to convert a key into an index
function hash(key) {
let hash = 0;
for (let i = 0; i < key.length; i++) {
hash = (hash + key.charCodeAt(i) * 23) % size;
}
@keif
keif / hashmapClass.js
Last active February 21, 2025 18:47
In Javascript, create a hash table from scratch without using Map or Set.
class HashTable {
constructor(size = 53) {
// Initialize an array of given size to store key-value pairs (buckets)
this.buckets = new Array(size);
this.size = size;
}
// Hash function to convert a key into an index
_hash(key) {
let hash = 0;
@keif
keif / m8o-nextjs-framer-flip-card.tsx
Created July 31, 2024 17:42 — forked from alishahlakhani/madeofzero-nextjs-framer-flip-card.tsx
Create a Tarot card deck selection page using Framer Motion and Nextjs
"use client";
import React, { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import Image from "next/image";
import clsx from "clsx";
type Props = {
onPick?: (card: string | null) => void;
onSelect?: (card: string) => void;
};
@keif
keif / .zshrc
Last active December 18, 2021 15:39
Check for existing .nvmrc file - if present, use it - it not, continue using the default version.
# for NVM
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# place this after nvm initialization!
# check for .nvmrc file and run `nvm use` automatically
autoload -U add-zsh-hook
load-nvmrc() {
# check for .nvmrc file
@keif
keif / countHighlyProfitableMonths.js
Created October 26, 2021 11:47
/* The stocks of a company are being surveyed to analyze the net profit of the company over a period of several months. For an analysis parameter k, a group of k consecutive months is said to be highly profitable if the values of the stock prices are strictly increasing for those months. Given the stock prices of the company for n months and the…
function countHighlyProfitableMonths(stockPrices, k) {
// write your code here
let numOfProfitableMonths = 0
let stockPriceLen = stockPrices.length
let profitableMonthsArr = [stockPrices[0]]
for (let i = 1; i < stockPriceLen; i += 1) {
const currStockPrice = stockPrices[i]
// checking current stock price against the profitable array
if (currStockPrice > profitableMonthsArr[profitableMonthsArr.length - 1]) {
@keif
keif / maxRepeatingChar
Created August 28, 2021 22:03
Given a string, find the maximum consecutive repeating character in itself.
// given a string, give me the count of each particular character in the string.
// Hard mode: Give me the letter which is repeated the most in a row, regardless of how often the character appears in the string.
// “aaabbc” would return “a”
// “aaabbbbc” would return “b”
// “aaabbbbaacc” would return “b”
// “abababababcccababababababab” would return “c”
let strArr = [
`aaabbc`, // a
`aaabbbbc`, // b
@keif
keif / timeConversion.js
Last active August 28, 2021 22:04
Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format. timeConversion has the following parameter(s): string s: a time in hour format Returns string: the time in hour format Input Format A single string that represents a time in -hour clock format (i.e.: or ). Constr…
const timeConversion = (s) => {
const seperator = `:`
const timeArr = s.slice(0, 8).split(seperator);
const hours = parseInt(timeArr[0], 10);
if (s.toUpperCase().indexOf(`PM`) > -1) {
// handle PM
timeArr[0] = (hours < 12) ? (hours + 12).toString() : hours.toString()
} else {
// handle AM
@keif
keif / minSum.js
Last active August 28, 2021 22:18
minSum.js - ah, this is from HackerRank, now it all makes more sense.
// I liked reduce. It's weird, but it's quirky, but I don't find it easy to understand at quick glance for all devs
const minSum_short = (num, k) => {
return new Array(k)
.fill(undefined) // not crazy about this aspect
.reduce(
(prev) => {
// Sort the array high to low
const current = prev.sort((a, b) => b - a)
// Swap the maximum value with the updated one
current[0] = Math.ceil(current[0] / 2)