Skip to content

Instantly share code, notes, and snippets.

View andenacitelli's full-sized avatar

Kal andenacitelli

View GitHub Profile
@andenacitelli
andenacitelli / extract.ts
Last active April 19, 2023 16:25
Himalaya JS - Extract All Text From Webpage
// May require some slight tweaking, but this should
const transformTree = (tree: any): string | (object | string)[] => {
if (tree.type === "text") {
const cleaned = tree.content
.replaceAll(/[\n\r]/g, " ")
.replaceAll(/\s{2,}/g, "")
.trim();
if (
!/[\dA-Za-z]/g.test(cleaned) ||
import { Editor } from "@endwise/ui/Editor";
import { ErrorView } from "@endwise/ui/query";
import {
Box,
Button,
Group,
Input,
Select,
SimpleGrid,
Stack,
@andenacitelli
andenacitelli / cache.ts
Last active March 29, 2023 17:02
Simple zlib + Prisma compressed caching implementation
// Generic cache class for compressing and storing data in the database. Use it for any data where you don't need to be able to read it. Things like deterministic API calls are a great candidate.
// Also a fun experiment to play around with cache invalidation times, where the cache is only "valid" for so long.
import zlib from "zlib";
export const getCache = async (prisma: any, key: string): Promise<string | undefined> => {
const entry = await prisma.cacheEntry.findUnique({
where: {
key,
},
@andenacitelli
andenacitelli / notion_prioritization_formula.md
Last active February 23, 2023 23:13
A Notion formula that outputs a priority number based on a due date and priority. Lower means do it sooner.
@andenacitelli
andenacitelli / map.js
Created January 14, 2023 03:49
WoW Realm -> Slug Map
// Generated from the Blizzard API on 1/13/2023 for all US/EU realms
export const REALM_TO_SLUG = {
"Gurubashi": "gurubashi",
"Skywall": "skywall",
"Dalaran": "dalaran",
"Garona": "garona",
"Thunder lord": "thunderlord",
"Dunemaul": "dunemaul",
"Azjol-Nerub": "azjolnerub",
"Firetree": "firetree",
@andenacitelli
andenacitelli / regex.md
Last active April 12, 2024 20:19
RegEx to extract TQDM information from text-only progress bar representation

Useful RegEx to extract information from a text-only TQDM stream. I personally found this useful to extract progress data from a Python child process and use it to update a progress bar in my front-end Electron UI.

The RegEx:

(.*): *(\d+%).*(\d+\/\d+) +\[(\d+:\d+)<(\d+:\d+), +(\d+.\d+.*\/s)\]

Capture Groups:

  1. Label
  2. Percent Complete