Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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 / README.md
Last active March 23, 2024 19:12
A5 printed card with HTML + CSS
  1. Clone this Gist.
  2. For card sizes other than A5, edit the size value in @page, and the height and width properties of body.
  3. Add contents to each face. The simplest approach is to add an image called front.png of the same dimensions as the card.
  4. Generate a PDF from the HTML + CSS. If using Prince, it's as simple as prince index.html card.pdf.
  5. Take the PDF to a printer, and ask them to print as many copies as you need.
@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 / marc-to-mods.php
Created April 24, 2012 16:54
Convert Harvard Library Bibliographic Dataset (MARC21) to MODS XML
<?php
require 'File/MARC.php';
$xsl = new DOMDocument;
$xsl->load('http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-4.xsl');
$xsltproc = new XSLTProcessor;
$xsltproc->importStylesheet($xsl);
$marcxml = new DOMDocument;
@hubgit
hubgit / index.html
Last active January 12, 2024 11:39
Render the text of a PDF with PDF.js
<!doctype html>
<meta charset="utf-8">
<title>Render the text of a PDF with PDF.js</title>
<style>
.page-container {
box-shadow: 0 1px 3px #444;
position: relative;
font-size: 1px;
line-height: 1;
@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 / SelectField.tsx
Last active December 29, 2023 03:41
Use react-select with Formik
import { FieldProps } from 'formik'
import React from 'react'
import Select, { Option, ReactSelectProps } from 'react-select'
export const SelectField: React.SFC<ReactSelectProps & FieldProps> = ({
options,
field,
form,
}) => (
<Select
@hubgit
hubgit / scopus-citations.md
Last active December 20, 2023 12:09
Scopus citations API
@hubgit
hubgit / README.md
Last active December 16, 2023 14:09
Remove metadata from a PDF file, using exiftool and qpdf. Note that embedded objects may still contain metadata.

Anonymising PDFs

PDF metadata

Metadata in PDF files can be stored in at least two places:

  • the Info Dictionary, a limited set of key/value pairs
  • XMP packets, which contain RDF statements expressed as XML

PDF files

@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/deno_dom@v0.1.43/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()