Skip to content

Instantly share code, notes, and snippets.

View cassidoo's full-sized avatar
⌨️
sleepy

Cassidy Williams cassidoo

⌨️
sleepy
View GitHub Profile

Heading 1

This is an example lil thingy wow look at me!

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6
@cassidoo
cassidoo / simple-react-recorder.jsx
Last active November 15, 2024 07:09
A simple React microphone component, recording audio and showing the blob in the browser, styled with Tailwind.
"use client";
import { useState, useEffect, useRef } from "react";
function SimpleRecordButton() {
const [isRecording, setIsRecording] = useState(false);
const [audioStream, setAudioStream] = useState(null);
const [mediaRecorder, setMediaRecorder] = useState(null);
const [audioBlob, setAudioBlob] = useState(null);
const [recordingTime, setRecordingTime] = useState(0);
const timerRef = useRef(null);
@cassidoo
cassidoo / spaces-to-dashes.py
Created July 25, 2024 19:40
A script to replace all of the spaces with dashes in the file and folder names of a directory
# Place this file in the folder that you want to edit, and then run `python spaces-to-dashes.py`
import os
def rename_files_and_folders(root_directory):
for dirpath, dirnames, filenames in os.walk(root_directory, topdown=False):
# Rename files
for filename in filenames:
if ' ' in filename:
old_file_path = os.path.join(dirpath, filename)
@cassidoo
cassidoo / keyboard.json
Last active July 29, 2024 03:58
For the micro journal
{
"main":
[
"ESC", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "BACKSPACE",
"PGUP", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", 127,
"ALT", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "\n",
"SHIFT", "z", "x", "c", "v", " ", "b", "n", "m", ",", ".", "PGDN"
],
"main-shift":
@cassidoo
cassidoo / link-component.astro
Created June 4, 2024 05:43
Astro web component for a random post from a list of slugs
@cassidoo
cassidoo / clearInputs.js
Created March 27, 2024 03:42
Clear all the inputs on the page
function clearInputs() {
let inputs = document.getElementsByTagName("input");
for (const i of inputs) {
i.value = "";
}
}
@cassidoo
cassidoo / tauri-file-diff.js
Created March 21, 2024 21:05
A script for a Tauri application to iterate over files and generate new file names and not overwrite old ones
const { BaseDirectory, exists } = window.__TAURI__.fs;
async function doesFileExist(fileName) {
let fileExists = await exists(fileName + ".pdf", {
baseDir: BaseDirectory.Download,
});
let fileCounter = 0;
while (fileExists) {
fileCounter++;
@cassidoo
cassidoo / wrapunicodespangpt4.md
Last active February 18, 2024 21:24
A GPT-4 prompt to write a simple JavaScript function

Prompt: Write a function in JavaScript that wraps a Unicode character in an HTML document in a <span> tag with a CSS class.


Raw GPT-4 Output:

You can use the following JavaScript function to achieve this:

function wrapUnicodeCharacter(char, cssClass) {
@cassidoo
cassidoo / mergerefs.jsx
Created January 10, 2023 22:57
Merge refs in React so a component can have more than one ref
export function mergeRefs(refs) {
return (value) => {
refs.forEach((ref) => {
if (typeof ref === "function") {
ref(value);
} else if (ref != null) {
ref.current = value;
}
});
};
@cassidoo
cassidoo / youtubeid.js
Created January 6, 2023 20:16
Get YouTube ID with JavaScript
let url = "https://www.youtube.com/watch?v=nVvxOwxuk_w";
url = url.split("v=")[1].split("&")[0]; // this removes out any extra parameters, like a playlist point etc
console.log(url);
// id = nVvxOwxuk_w