Skip to content

Instantly share code, notes, and snippets.

View zoolu-got-rhythm's full-sized avatar
🏀
ballin'

Christopher P.K. Morris zoolu-got-rhythm

🏀
ballin'
View GitHub Profile
@zoolu-got-rhythm
zoolu-got-rhythm / countAuthorCommits.sh
Created November 21, 2023 17:49
count number of commits for each author in a git repository
#!/opt/homebrew/Cellar/bash/5.2.21/bin/bash
# echo "running in shell: $(ps -p $$)"
# Check if a directory argument was provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <directory>"
exit 1
fi
@zoolu-got-rhythm
zoolu-got-rhythm / useGetMuiScreenWidthBreakpoint.ts
Created October 19, 2023 14:32
mui screen width breakpoint hook
import { Breakpoint, useMediaQuery, useTheme } from "@mui/material";
/**
xs, extra-small: 0px
sm, small: 600px
md, medium: 900px
lg, large: 1200px
xl, extra-large: 1536px
*/
export function useGetMuiBreakPointLabel(): Breakpoint {
@zoolu-got-rhythm
zoolu-got-rhythm / consoleLogMatchTestFile.txt
Created September 18, 2023 10:15
console.log match test file example
console // match start
.log // match end
console.log console.log // 2 matches
console .log // match
console. // match start
log // match end
asdf
asdf
console.log // match
asdf
@zoolu-got-rhythm
zoolu-got-rhythm / countConsoleLogsInFile.sh
Last active September 17, 2023 20:58
robust bash function that counts console.log's in a javascript file, options to print lines logs found on aswell
#!/bin/bash
# takes in a file as argument 1
# takes in a boolean as argument 2
count_and_print_logs_in_file() {
file=$1
print_logs_found_on_lines=false
if [ $# -gt 1 ]; then
print_logs_found_on_lines=$2
fi
@zoolu-got-rhythm
zoolu-got-rhythm / getAudioClipDuration.ts
Created September 8, 2023 22:03
get the length/duration (in milliseconds) of an audio file in JS, written in TS
/**
* returns a promise which when resolves returns the duration of the audio in milliseconds or
* rejects with the value if something goes wrong
*/
export function getDurationOfAudioInMilliseconds(src: string): Promise<number> {
return new Promise((resolve, reject) => {
var audio = new Audio();
audio.addEventListener("loadedmetadata", function () {
if (audio.duration) {
@zoolu-got-rhythm
zoolu-got-rhythm / countConsoleLogs.sh
Created August 22, 2023 10:16
cat here document not working for some reason (from line 31 to 34)
#!/bin/sh
# this script has been tested on mac bash/terminal
# test valid input argument (directory path)
echo "ths is arg #: $#"
if [ $# -eq 0 ]; then
echo "no directory to search from supplied"
@zoolu-got-rhythm
zoolu-got-rhythm / countConsoleLogs.sh
Last active August 21, 2023 18:14
find all files with console.log's in a directory and count total, useful for JavaScript and Typescript projects
#!/bin/sh
# this script has been tested on mac bash/terminal
# test valid input argument (directory path)
if [ $# -eq 0 ]; then
echo "no directory to search from supplied"
exit 1
else
@zoolu-got-rhythm
zoolu-got-rhythm / increaseSineFrequencyOverTime.js
Created June 23, 2023 10:14
increase frequency of sine wave over time in web audio api
function increaseFreq(osc, nOfTimesToIncreaseFreq, delayInSeconds, riseInFrequency){
for(let i = 0; i < nOfTimesToIncreaseFreq; i++){
osc.frequency.setValueAtTime(200 + (i*riseInFrequency) , audioCtx.currentTime + (i * delayInSeconds)); // value in hertz
}
}
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// create Oscillator node
const oscillator = audioCtx.createOscillator();
@zoolu-got-rhythm
zoolu-got-rhythm / observerPattern.ts
Created December 2, 2022 18:32
observer pattern implementation in typescript
interface Observer<ObservableClass, ObservableEventEnum>{
update: (ObjectRef: ObservableClass, observableEventEnum: ObservableEventEnum) => void;
}
class Observable<ObservableClass, ObservableEventEnum>{
observers: Observer<ObservableClass, ObservableEventEnum>[];
constructor(){
this.observers = [];
}
@zoolu-got-rhythm
zoolu-got-rhythm / rockPaperScissors.ts
Last active November 25, 2022 04:13
rock, paper, scissors game logic modeled and written in typescript
// rock paper scissors business logic/application state/model data
enum Hand{
ROCK,
PAPER,
SCISSORS
}
const hands = [Hand.ROCK, Hand.PAPER, Hand.SCISSORS];