Skip to content

Instantly share code, notes, and snippets.

@hubgit
hubgit / pack-build.sh
Created March 12, 2021 16:10
You don't need a Dockerfile for a Node app
brew install buildpacks/tap/pack
pack builder suggest
pack config default-builder gcr.io/buildpacks/builder:v1
pack build my-app
const escapeHTML = input => input.replace(/[<>&"']/g, char => `&#${char.charCodeAt(0)};`)
brew install texlive jq datasette sqlite-utils
tlmgr dump-tlpdb --remote http://tug.ctan.org/systems/texlive/tlnet/tlpkg/texlive.tlpdb --json | jq '.main.tlpkgs' | sqlite-utils insert texlive.db tlpkgs -
datasette texlive.db
# SELECT category, name, shortdesc, longdesc FROM tlpkgs WHERE category = 'Package' ORDER BY name ASC LIMIT 200
sqlite-utils enable-fts texlive.db tlpkgs name shortdesc
const parseTextContent = (element, selector) => element.querySelector(selector)?.textContent ?? undefined
@hubgit
hubgit / rsync-backup.sh
Created August 31, 2020 07:22
rsync dry run with stats to summarise a backup of a remote server
rsync -avzh --progress --dry-run --stats -e ssh example:/ . --exclude=/backups --exclude=/boot --exclude=/build --exclude=/dev --exclude=/dump --exclude=/initrd --exclude=/latest --exclude=/lost+found --exclude=/media --exclude=/mnt --exclude=/nonexistent --exclude=/proc --exclude=/run --exclude=/selinux --exclude=/srv --exclude=/sys --exclude=/tmp
@hubgit
hubgit / EditorProvider.ts
Created August 28, 2020 07:53
A React context provider with undefined default value that exports a hook for accessing the context value
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import React, { createContext, useContext, useEffect, useState } from 'react'
import { Editor } from '../Editor'
const EditorContext = createContext<EditorState | undefined>(undefined)
export const useEditorContext = () => {
const editor = useContext(EditorContext)
@hubgit
hubgit / wikidata-isbn.js
Created July 25, 2020 06:32
Search Wikidata for a book by ISBN, then use Citation.js to fetch the metadata
const Cite = require('citation-js')
const isbn = '978-1-4088-4564-6'
// search ISBN-13 or ISBN-10 (note hyphens and case-sensitivity)
const sparql = `
SELECT DISTINCT ?subject WHERE {
?subject wdt:P31 wd:Q7725634.
{ ?subject wdt:P212 '${isbn}'. } UNION { ?subject wdt:P957 '${isbn}'. }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<article xmlns="https://dtd.nlm.nih.gov/ns/archiving/2.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="https://dtd.nlm.nih.gov/ns/archiving/2.3/ https://dtd.nlm.nih.gov/archiving/2.3/xsd/archivearticle.xsd" article-type="research-article">
<front>
<journal-meta>
<journal-id journal-id-type="nlm-ta">BMC Cell Biol</journal-id>
<journal-title>BMC Cell Biology</journal-title>
<issn pub-type="epub">1471-2121</issn>
<publisher>
<publisher-name>BioMed Central</publisher-name>
<publisher-loc>London</publisher-loc>
</publisher>
yarn init -y
yarn add --dev @11ty/eleventy
yarn eleventy --serve