Skip to content

Instantly share code, notes, and snippets.

Alf Eaton hubgit

Block or report user

Report or block hubgit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hubgit
hubgit / query.js
Created May 16, 2020
MongoDB aggregate query with lookup and unwind
View query.js
const items = await Item.aggregate([
{
$project: {
body: 0,
},
},
{
$lookup: {
from: 'users',
localField: 'uid',
View webrtc.js
const config = { iceServers: [ { url: 'stun:stun.l.google.com:19302' } ] }
const [localConnection, remoteConnection] = [new RTCPeerConnection(config), new RTCPeerConnection(config)]
const handleIceCandidate = connection => event => event.candidate && connection.addIceCandidate(new RTCIceCandidate(event.candidate))
localConnection.onicecandidate = handleIceCandidate(remoteConnection)
remoteConnection.onicecandidate = handleIceCandidate(localConnection)
const [localVideo, remoteVideo] = [document.createElement('video'), document.createElement('video')]
@hubgit
hubgit / convert-emf-png.sh
Last active Mar 24, 2020
Batch convert EMF to PNG with Inkscape
View convert-emf-png.sh
export INKSCAPE=/Applications/Inkscape.app/Contents/MacOS/inkscape
# ${INKSCAPE} --help
for i in *.emf; do "${INKSCAPE}" --without-gui --export-file="${i}.png" --export-dpi=72 "${i}"; done
@hubgit
hubgit / barb-weekly-viewing-figures.js
Created Feb 4, 2020
Average UK weekly television viewing figures from BARB
View barb-weekly-viewing-figures.js
const axios = require('axios')
const qs = require('qs')
const fs = require('fs-extra')
const thisYear = (new Date).getFullYear()
const fetch = async () => {
const years = []
for (let year = 1992; year <= thisYear; year++) {
@hubgit
hubgit / now-php.sh
Created Jan 27, 2020
Deploy a PHP endpoint to now.sh
View now-php.sh
# Install `now`
yarn global add now
# Install `jo`
brew install jo
# Create a new folder for the project
mkdir now-php-example && cd $_
# Create now.json
View Queue.ts
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 Jul 26, 2019
Fetch and decompress a Wikidata dump
View fetch-wikidata-dump.js
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 Jun 25, 2019
Given a Project Muse book id, this will fetch each chapter and merge them into a single PDF.
View muse-merge.js
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 () => {
View person.json
{
"@context": "https://unwalled.garden/person.jsonld",
"title": "Paul Frazee",
"description": "Beaker guy",
"follows": [
"dat://alice.com",
"dat://bob.com"
]
}
View twitter-archive-viewer.html
<!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>
You can’t perform that action at this time.