Skip to content

Instantly share code, notes, and snippets.

View cassidoo's full-sized avatar
⌨️
sleepy

Cassidy Williams cassidoo

⌨️
sleepy
View GitHub Profile
@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 / base-css.md
Created May 4, 2022 06:37
Base CSS for a plain HTML document

If you don't want to deal with styling a mostly text-based HTML document, plop these lines in and it'll look good:

html {
  font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  font-size: 1.3em;
  max-width: 40rem;
  padding: 2rem;
  margin: auto;
 line-height: 1.5rem;
@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 / DTN.md
Last active March 6, 2024 15:48
Deploy to Netlify Button

Insta-deploy templates to Netlify

Make a Deploy to Netlify button like this:

Deploy to Netlify

With this:

@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 / human.md
Created October 14, 2021 20:22
Human Template for Obsidian
cuid alias tags
human<% tp.file.creation_date("YYYYMMDD-HHmmss") %>
👤 <% tp.file.title.substring(1) %>
<% tp.file.title.substring(1) %>
person/friends, person/family, person/coworker, person/rwc

👤 <% tp.file.title.substring(1) %>

🎂 Birthday: 💌 Email: ☎️ Phone:

@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
export default function usePromise(api) {
const [state, dispatch] = useReducer(
(state, action) => {
switch (action.type) {
case 'LOADING':
return { ...state, loading: true }
case 'RESOLVED':
return { ...state, loading: false, response: action.response, error: null }
case 'ERROR':
return { ...state, loading: false, response: null, error: action.error }