Skip to content

Instantly share code, notes, and snippets.

@RyanHirsch
RyanHirsch / parser.ts
Last active February 27, 2024 20:53
Validator for taking camelcase or snake case inputs and converting them to a consistent type checked value.
import * as z from "zod";
const camelToSnakeCase = (str: string) =>
str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
const validActions = ["HELLO_THERE"] as const;
const ValidActionsSchema = z.enum(validActions);
const ParseableSchema = z.object({
action: z.string().transform((value, ctx) => {
@RyanHirsch
RyanHirsch / example.js
Created October 20, 2021 21:13
Custom super property management example
const customSuperProp = {};
function register(obj) {
Object.assign(customSuperProp, obj);
}
function unregister(key) {
delete customSuperProp[key];
}
@RyanHirsch
RyanHirsch / parser.ts
Created October 12, 2021 15:08
Podverse integration
const pt = parseFeed(result.feedResponse);
/** Compatibility function to align partytime output with existing podverse item format */
const itemCompat = (episode) => {
const {
author,
description,
duration,
enclosure,
explicit,
@RyanHirsch
RyanHirsch / example.js
Created September 9, 2021 16:34
`npm i podcast-partytime@3.0.0-beta.0`
const fetch = require("node-fetch")
const {parseFeed} = require("podcast-partytime")
fetch("https://podnews.net/clock-rss")
.then(resp => resp.text())
.then(xml => parseFeed(xml))
.then(console.log)
@RyanHirsch
RyanHirsch / republic-times.js
Last active July 8, 2021 14:50
republic times
// ==UserScript==
// @name Republic Times Cleanup
// @namespace http://tampermonkey.net/
// @version 0.1.1
// @description try to take over the world!
// @author You
// @match https://republictimes.net/*
// @match https://republictimes.net
// @match http://republictimes.net/*
// @grant none
@RyanHirsch
RyanHirsch / sticky.ts
Created April 1, 2021 14:51
Traverse up the dom to find sticky parent
/**
* Traverse up the dom to find a sticky parent node crossing any shadow boundaries
*/
export function findStickyParent(element: HTMLElement): HTMLElement | null {
let elm = element.parentNode || element.host;
while (elm) {
if (elm.style && elm.style.top && window.getComputedStyle(elm).position === `sticky`) {
return elm;
@RyanHirsch
RyanHirsch / gist:1cbfba45119fd806787d05b9b97186c6
Last active February 4, 2021 17:59
code to convert uuid to b58 strings
const uuid1 = "da507fb6-5417-495a-b1f3-a23518f6b9ea";
const uuid2 = "b21e5078-8da2-421b-8b26-ace980f4164a";
//#region Uint8Array
/* https://stackoverflow.com/questions/38987784/how-to-convert-a-hexadecimal-string-to-uint8array-and-back-in-javascript */
const fromHexString = hexString =>
new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
const toHexString = bytes =>
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
@RyanHirsch
RyanHirsch / _README.md
Last active June 23, 2022 16:13
Next.js Setup with typescript, jest, tailwind, and MSW.

NextJS setup

yarn create next-app

run setup.sh

Update package.json

 "lint-staged": {
@RyanHirsch
RyanHirsch / .eslintignore
Created April 6, 2020 12:58
Typescript + Jest + ESLint + Tailwind
.next
__generated__
@RyanHirsch
RyanHirsch / machine.js
Last active March 7, 2020 02:10
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions