Skip to content

Instantly share code, notes, and snippets.

@hubgit
hubgit / deno-compressed-json-lines-reader.ts
Last active August 26, 2022 22:17
Read/write a gzipped JSON lines file with Deno
const createInputReader = async (path: string) => {
const file = await Deno.open(path, {
read: true,
})
return file.readable
.pipeThrough(new DecompressionStream('gzip'))
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream())
.pipeThrough(
@hubgit
hubgit / docker-image-metadata.mjs
Last active July 7, 2022 20:30
Fetch Docker image metadata
// adapted from https://github.com/distribution/distribution/issues/1252#issuecomment-274944254
const IMAGE = 'example/foo'
const TAG = 'latest'
const authorise = async () => {
const url = new URL('https://auth.docker.io/token')
url.searchParams.set('scope', `repository:${IMAGE}:pull`)
url.searchParams.set('service', 'registry.docker.io')
const response = await fetch(url)
get_iplayer --file-prefix="<pid>" --output=$PWD --pid $PID --tv-quality sd --start $START --stop $STOP
@hubgit
hubgit / _headlines.txt
Created February 13, 2022 09:17
8 years of headlines from the Daily Express' "World War 3" page
Paxman the Peacemaker as he grills feuding Japan and China ambassadors in SEPARATE rooms
Russian President Vladimir Putin wants to start World War Three, says Ukraine PM
Putin's nuclear threat: Russian leader nearly started World War Three over the Crimea war
Putin has started a 'war with the whole civilised world' which could leave MILLIONS dead
Russia's chilling THREAT to the West: Putin's army chief warns of 'how it will all END'
World War Three in SPACE? Fears over rise in anti-satellite weapons created by Russia
Migrant crisis and Euro tensions threaten to trigger catastrophic conflict claim experts
World War Three could begin TOMORROW - and UK's armed forces 'are woefully unprepared'
WW3 THREAT: Ex-Navy chief calls presence of Russia's SAMs in Syria 'extremely dangerous'
Turkey threatens to SHOOT DOWN Putin's planes as it drags West closer to war with Russia
@hubgit
hubgit / wordle-tweets.js
Last active January 20, 2022 09:50
Fetch and parse Wordle lines from recent tweets
import fs from 'fs-extra'
import Twitter from 'twitter-v2'
const n = '213'
const query = `"wordle ${n}" -RT`
const auth = fs.readJSONSync('auth-node.json')
const client = new Twitter(auth)
@hubgit
hubgit / transform-stream
Created December 12, 2021 13:19
Transforming objects in a stream
import { Transform } from 'stream'
import inputStream from 'input-stream'
import outputStream from 'output-stream'
inputStream('input.csv')
.pipe(
Transform({
readableObjectMode: true,
writableObjectMode: true,
transform: (chunk, encoding, callback) => {
@hubgit
hubgit / Dockerfile
Created December 6, 2021 10:08
Node app Dockerfile
FROM node:16
WORKDIR /usr/src/app
ENV NODE_ENV=production
COPY package*.json ./
RUN npm ci
COPY . .
CMD [ "npm", "run", "start" ]
@hubgit
hubgit / grid-layout.css
Created November 6, 2021 19:45
CSS Grid Layout
.container {
height: 100%;
overflow: hidden;
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: auto 1fr auto;
column-gap: 5px;
}
@media (max-width: 800px) {
import biomsa from 'biomsa'
import fetch from 'node-fetch'
const sequence = async (id) => {
const params = new URLSearchParams({
db: 'nuccore',
retmode: 'text',
rettype: 'fasta',
id,
})
@hubgit
hubgit / _headers
Created August 20, 2021 19:35
Netlify + react-scripts headers for static files with content hash in filename - put the "_headers" file in "public" dir
/static/*
Cache-Control: max-age=31536000