Skip to content

Instantly share code, notes, and snippets.

@hubgit
hubgit / Queue.ts
Created August 12, 2019 13:25
A queue
type QueueItem = () => Promise<void>
export class Queue {
private items: QueueItem[] = []
private running: boolean = false
public add = (item: QueueItem): void => {
this.items.push(item)
@hubgit
hubgit / fetch-wikidata-dump.js
Created July 26, 2019 15:00
Fetch and decompress a Wikidata dump
const fs = require('fs')
const https = require('https')
const unbzip2Stream = require('unbzip2-stream')
const url =
'https://dumps.wikimedia.org/wikidatawiki/entities/latest-all.json.bz2'
const decompress = unbzip2Stream()
const output = fs.createWriteStream('data/latest.json')
@hubgit
hubgit / muse-merge.js
Last active July 2, 2020 06:33
Given a Project Muse book id, this will fetch each chapter and merge them into a single PDF.
const fetch = require("node-fetch");
const url = require("url");
const { Parser } = require("htmlparser2");
const hummus = require("hummus");
const BOOK_ID = "66229"; // EDIT THIS
const OUTPUT_FILE = `${BOOK_ID}.pdf`;
const extractURLs = async () => {
{
"@context": "https://unwalled.garden/person.jsonld",
"title": "Paul Frazee",
"description": "Beaker guy",
"follows": [
"dat://alice.com",
"dat://bob.com"
]
}
<!DOCTYPE html>
<meta charset="utf-8">
<title>Twitter Archive Viewer</title>
<script>window.YTD = { tweet: {} }</script>
<script src="tweet.js"></script><!-- this is loading a file from the archive -->
<style>
.tweet { border: 1px solid #eee; margin: 8px }
.full_text { padding: 8px }
.created_at { padding: 8px; color: #777 }
</style>
brew install get_iplayer
PID=m00042g3
get_iplayer --subtitles --file-prefix="<pid>" --output=$PWD --pid $PID
ffmpeg -i $PID.mp4 -ss 00:25:26 -t 00:01:59 -vf subtitles=$PID.srt $PID-clip-subtitles.mp4
@hubgit
hubgit / generate-xsl.php
Created April 11, 2019 10:54
Use Saxon in PHP
<?php
$saxon = new Saxon\SaxonProcessor();
print "{$saxon->version()}\n";
$input = 'schematrons/1.0/jats4r-topic.sch';
$xsl = 'skeleton/iso_schematron_skeleton_for_saxon.xsl';
$output = 'jats4r-topic.xsl';
$processor = $saxon->newXsltProcessor();
@hubgit
hubgit / scripts-package.json
Created February 14, 2019 08:45
npm scripts for typescript libraries
"scripts": {
"build": "npm-run-all --parallel build:*",
"build:cjs": "tsc --outDir dist/cjs --module commonjs",
"build:es": "tsc --outDir dist/es --declarationDir dist/types --declaration",
"dev": "npm-run-all --parallel \"build:* --watch\"",
"lint": "tslint --project .",
"prebuild": "rimraf dist",
"prettier": "prettier --write \"src/**/*.{ts,tsx}\" \"*.{js,json}\"",
"preversion": "npm-run-all --parallel typecheck lint test",
"test": "jest",
@hubgit
hubgit / docker-env-arg.md
Last active February 4, 2019 13:27
Sources of variables in docker-compose.yml, Dockerfile, and the applications they start

Used in docker-compose.yml

  • environment variables in the shell where docker-compose is run
  • values set in an .env file in the folder where docker-compose is run

Used in Dockerfile

  • build args set in docker-compose.yml (build > args, object) and imported with ARG in Dockerfile
  • values set with ARG in Dockerfile
window.setInterval(() => window.scrollTo(0, document.body.scrollHeight), 1000)