Skip to content

Instantly share code, notes, and snippets.

View liddiard's full-sized avatar
🙃

Harrison Liddiard liddiard

🙃
View GitHub Profile
@liddiard
liddiard / js_await_sleep.js
Created May 12, 2023 23:02
One-liner sleep function to use in JavaScript with async/await
const sleep = s => new Promise(r => setTimeout(r, s*1000));
@liddiard
liddiard / game_master.html
Created October 27, 2022 22:56
Displays the person in charge of hosting a game for us to play with fun animations
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>
<style>
body {
@liddiard
liddiard / ssh_port_scan.sh
Last active November 29, 2020 19:52
Scan local network for open port 22 (SSH) in the range 192.168.0.1 – 192.168.0.64
nmap --open -v -p 22 192.168.0.1-64 | grep Discovered
@liddiard
liddiard / launch.json
Created September 14, 2020 00:53
Visual Studio Code launch.json config
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha All",
@liddiard
liddiard / timezone_time_share.html
Last active September 23, 2020 21:48
Share a date and time that will display in the whatever the viewer's time zone is: https://tz.harrisonliddiard.com
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<title>Display times in the viewer’s local timezone</title>
<style>
:root {
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
@liddiard
liddiard / promisify.js
Last active April 19, 2020 00:17
Simple implementation of taking a callback-style function that accepts an `(err, result)` callback as its last argument and return that function promisified.
// dummy callback func; randomly calls success or failure callback after 1 sec
const myFunc = (a, b, callback) => {
setTimeout(() =>
Math.random() > 0.5 ? callback(null, 'success!') : callback('fail :('),
1000)
}
// test the dummy func
myFunc('foo', 'bar', (err, res) => {
if (err) {
@liddiard
liddiard / extractSubtitles.js
Created March 20, 2020 00:58
Extract subtitles from a YouTube video API response (https://www.youtube.com/api/timedtext)
const subtitles = {} // replace with subtitles content
subtitles.events.map(ev => ev.segs[0].utf8.replace('\n', ' ')).join(' ')
<!doctype html>
<html lang="en"> <!-- necessary to define language here to get English hyphenation -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root {
--article-padding: 1.5em;
}
html {
@liddiard
liddiard / airport_info.sql
Last active February 21, 2020 05:12
Take airport info from https://ourairports.com/data/ and transform it into a table that contains pertinent info like frequencies, runways, and elevation for diversions. Run on SQLite 3.
-- requires airports, runways, and airport_frequencies tables to be present with the correct data types
-- example output row:
-- ident name ATIS CTAF TWR GND elevation_ft runways
-- KHWD Hayward Executive Airport 126.7 120.2 118.9 121.4 52 10L-28R 3107'x75', 10R-28L 5694'x150'
SELECT
ident,
name,
-- "pivot" frequency data from rows to columns
MAX(CASE WHEN airport_frequencies.type = 'ATIS' THEN airport_frequencies.frequency_mhz END) ATIS,
/* ballots in the form:
* { userID: [ firstChoice, secondChoice, ... ],
* userID: [ ... ],
* ... }
*/
const instantRunoff = ballots => {
// initialize an map from choices to number of votes
const votes = {};