Skip to content

Instantly share code, notes, and snippets.

import * as bencode from 'https://deno.land/x/[email protected]/mod.ts'
import { gtin } from 'npm:cdigit'
import ISBN from 'npm:isbn3'
// zstd -d data/aa_isbn13_codes_20241204T185335Z.benc.zst
const data = await Deno.readFile('data/aa_isbn13_codes_20241204T185335Z.benc').then(bencode.decode)
for (const [key, value] of Object.entries(data as Record<string, Uint8Array>)) {
console.log(key)
@hubgit
hubgit / media-recorder.js
Created November 19, 2024 22:09
Record video + audio from a browser tab/window/screen
const media = await navigator.mediaDevices.getDisplayMedia({
audio: {
echoCancellation: false,
autoGainControl: false,
noiseSuppression: false,
},
})
const recorder = new MediaRecorder(media, {
mimeType: 'video/webm',
[50, 100, 3].toSorted(Intl.Collator('en', { numeric: true }).compare)
@hubgit
hubgit / fetch-imp-audio.ts
Last active April 1, 2024 22:44
Fetch Independent Music Podcast audio files: `deno run fetch-imp-audio.ts`
import RSSParser from 'npm:rss-parser'
await Deno.mkdir('audio', { recursive: true })
const feedURL = 'https://anchor.fm/s/1252b450/podcast/rss'
const feed = await new RSSParser().parseURL(feedURL)
for (const item of feed.items) {
const { url } = item.enclosure
console.log(url)
@hubgit
hubgit / download-all-linked-files.js
Created March 3, 2024 17:26
Download all downloadable links in a single zip archive
const links = document.querySelectorAll('a[download]')
if (links.length === 0) {
console.log("No downloadable files found")
return
}
const handle = await showSaveFilePicker({
suggestedName: 'files.zip',
types: [{
@hubgit
hubgit / mlx-mixtral-macos.md
Created January 9, 2024 22:45
Run Mixtral-8x7B-Instruct-v0.1 LLM on macOS (Apple Silicon) using MLX
brew install git-lfs 

git clone https://github.com/ml-explore/mlx-examples
cd mlx-examples/llms/mixtral
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
cd Mixtral-8x7B-Instruct-v0.1
git lfs pull --include "consolidated.*.pt" # ~100GB
git lfs pull --include "tokenizer.model"
@hubgit
hubgit / main.ts
Created December 11, 2023 12:18
Fetch tracks played on the Independent Music Podcast
import { DOMParser, type Element, } from "https://deno.land/x/[email protected]/deno-dom-wasm.ts";
const parser = new DOMParser()
const fetchDOM = async (url: string) => {
const response = await fetch(url)
if (!response.ok) {
throw new Error('Response was not ok')
}
const html = await response.text()
@hubgit
hubgit / chat.ts
Last active May 11, 2023 08:35
Vercel Edge Function for an OpenAI API request
import type { NextRequest } from 'next/server'
import { createParser } from 'eventsource-parser'
export const config = {
runtime: 'edge',
}
export default async function handler(req: NextRequest) {
const encoder = new TextEncoder()
const decoder = new TextDecoder()
@hubgit
hubgit / textract-pdf-tables.sh
Last active June 15, 2023 13:31
Extract tabular data from a PDF to CSV
# brew install awscli
# aws configure
aws s3 cp your-file.pdf s3://your-bucket/your-file.pdf
# https://pypi.org/project/amazon-textract-helper/
# https://github.com/aws-samples/amazon-textract-textractor/tree/master/helper
# pip install amazon-textract-helper
amazon-textract --input-document s3://your-bucket/your-file.pdf --features TABLES --pretty-print TABLES --pretty-print-table-format=csv
# https://aws.amazon.com/blogs/machine-learning/automatically-extract-text-and-structured-data-from-documents-with-amazon-textract/
[...document.querySelectorAll('div,main,body')].forEach(node => {
node.style.position = 'relative'
node.style.height = 'auto'
node.style.overflowY = 'visible'
});
[...document.querySelectorAll('button')].forEach(node => {
node.remove()
});