This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shamelessly stolen from https://glama.ai/blog/2024-08-29-reverse-engineering-minified-code-using-openai | |
import React, { useEffect, useRef, useState } from 'react'; | |
const selectedCharacterSet = | |
"$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,^`'. .:â–‘â–’â–“â–ˆ"; | |
const characterSetLength = selectedCharacterSet.length; | |
const calculateCharacter = ( | |
x: number, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wait for an element to be added to the DOM or shadow DOM. | |
* @param {ShadowRoot | Document} root - The root to observe. | |
* @param {string} selector - The selector of the element to wait for. | |
* @param {number} [timeout] - The time in milliseconds to wait before rejecting the promise. | |
* @return {Promise<HTMLElement | Node>} - A promise that resolves with the element when it is added to the DOM or shadow DOM. | |
*/ | |
function waitForElement(root, selector, timeout = 1000) { | |
let timeoutId; | |
return new Promise((resolve, reject) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param {number} milliseconds - time in milliseconds | |
* @returns {string} - time in hours, minutes, seconds | |
*/ | |
function millisecondsToTimestamp(milliseconds) { | |
if(milliseconds < 0) { | |
return '00:00:00'; | |
} | |
if(milliseconds === 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getStuff(token) { | |
const body = {} | |
// wrap in try / catch so we can resolve any network failures | |
try { | |
// initial request | |
const result = await fetch(`https://example.com/api/v1`, { | |
headers: { | |
"x-CSRF-Token": token, | |
"Content-Type": "application/json" | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim:ft=zsh ts=2 sw=2 sts=2 | |
# Must use Powerline font, for \uE0A0 to render. | |
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}\uE0A0 " | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}!" | |
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?" | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg_bold[red]%}‹" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see https://www.nodc.noaa.gov/archive/arc0021/0002199/1.1/data/0-data/HTML/WMO-CODE/WMO4677.HTM | |
function matchWeatherCode(code) { | |
switch (code) { | |
case 0: | |
return "🌥️" | |
case 1: | |
return "🌥️" | |
case 2: | |
return "🌥️" | |
case 3: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.git_templates/hooks/pre-push | |
#!/bin/bash | |
protected_branch='master' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ $protected_branch = $current_branch ] | |
then | |
echo "${protected_branch} is a protected branch, create PR to merge" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { parse } = require('rss-to-json'); | |
const cheerio = require('cheerio'); | |
const fs = require('fs'); | |
const TurndownService = require('turndown') | |
const turndownService = new TurndownService({ | |
codeBlockStyle: 'fenced', | |
bulletListMarker: '-', | |
headingStyle: 'atx', | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = | |
Pick<T, Exclude<keyof T, Keys>> | |
& { | |
[K in Keys]-?: | |
Required<Pick<T, K>> | |
& Partial<Record<Exclude<Keys, K>, undefined>> | |
}[Keys] | |
type Events = 'play' | 'pause' | 'ready' | 'seek' | 'end'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.body.addEventListener('load', function () { | |
/** | |
* | |
* @param {HTMLElement} selector | |
* @returns a ✨ new carousel ✨ | |
*/ | |
function createCarousel( | |
selector, | |
autoRotationInterval = 3_000, | |
onPrevCallback = null, |
NewerOlder