Skip to content

Instantly share code, notes, and snippets.

@hubgit
hubgit / rsync-backup.sh
Created Aug 31, 2020
rsync dry run with stats to summarise a backup of a remote server
View rsync-backup.sh
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 Aug 28, 2020
A React context provider with undefined default value that exports a hook for accessing the context value
View EditorProvider.ts
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 Jul 25, 2020
Search Wikidata for a book by ISBN, then use Citation.js to fetch the metadata
View wikidata-isbn.js
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}'. }
View atypon-logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View test.xml
<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>
View eleventy.sh
yarn init -y
yarn add --dev @11ty/eleventy
yarn eleventy --serve
@hubgit
hubgit / NOTES.md
Created Jun 25, 2020
Kubernetes Dashboard user
View NOTES.md
@hubgit
hubgit / ns-resolver.ts
Last active Jun 24, 2020
Creating a namespace resolver for document.evaluate
View ns-resolver.ts
// from the doc or node being parsed
const namespaceResolver = doc.createNSResolver(doc)
// from XML you control
const namespaceResolverDoc = new DOMParser().parseFromString(
`<TEI xmlns="http://www.tei-c.org/ns/1.0"/>`,
'application/xml'
)
@hubgit
hubgit / execfile-promise-pipe.js
Created Jun 17, 2020
Pipe input to a promisified execFile command
View execfile-promise-pipe.js
const promise = promisify(execFile)('foo', {
encoding: 'buffer', // remove this to get the output as a string
})
promise.child.stdin.write(input)
promise.child.stdin.end()
const { stdout: output } = await promise
You can’t perform that action at this time.