Skip to content

Instantly share code, notes, and snippets.

View liddiard's full-sized avatar
🙃

Harrison Liddiard liddiard

🙃
View GitHub Profile
@liddiard
liddiard / cycle_wifi.sh
Created February 13, 2017 00:38
Turn the Wi-Fi on a Mac off and on again, because apparently that's still a thing we need to do these days.
#!/bin/bash
networksetup -setairportpower en0 off
sleep 1
networksetup -setairportpower en0 on
@liddiard
liddiard / rotateTheWeb.js
Last active February 24, 2017 23:08
Messing around with device orientation API to rotate a webpage with the gyroscope movement, like viewing a Snapchat shot on Spectacles but way less interesting.
(function(){
document.body.style.width = '100vw';
document.documentElement.style.width = '100vw';
document.body.style.height = '100vh';
document.documentElement.style.height = '100vh';
document.body.style.overflow = 'scroll';
document.documentElement.style.overflow = 'scroll';
window.addEventListener("deviceorientation", event => {
@liddiard
liddiard / getFbModalPeople.js
Last active April 18, 2017 21:47
One-liner to get a sorted, newline-separated list of people from a Facebook modal.
Array.from(document.querySelectorAll('.fsl.fwb.fcb > a')).map(link => link.text).sort().join('\n');
@liddiard
liddiard / linkReport.js
Last active April 18, 2017 19:20
Get a list of broken links on a page that match a given selector. Uses Fetch API. Assumes cross-origin requests, if any, are allowed by the server.
function linkReport(selector) {
'use strict';
const fetchOptions = {
method: 'HEAD'
};
window.brokenLinks = [];
document
.querySelectorAll(selector)
.forEach(link => {
fetch(link.href)
@liddiard
liddiard / app.js
Created July 14, 2017 20:59
Get a newline-separated list of a GitHub user's public repositories with repo title, GitHub URL, and description.
const request = require('superagent');
const username = 'liddiard'; // change username as needed
request
.get(`https://api.github.com/users/${username}/repos`)
.query({page: 1}) // increment this page number as needed
.then(res =>
fs.appendFile('repos.txt', res.body.map(repo =>
[repo.name, repo.html_url, repo.description].join('\n'))
@liddiard
liddiard / moveToCart.js
Last active August 2, 2017 18:05
One-liner to press "Save for later" or "Move to cart" on all the items in your Amazon cart. Will start throwing errors when all items have been saved but whatever. `querySelectorAll + forEach` solution did not work.
window.setInterval(() => document.querySelector('input[value="Move to Cart"]').click(), 250);
@liddiard
liddiard / cloudCover.js
Last active March 13, 2018 03:59
Use OpenWeatherMap data to compile historical cloud cover by hour in specific months to figure out when the best time of day is to reserve VFR flight lessons.
data
.filter(x => (new Date(x.dt_iso)).getMonth() > 5 && (new Date(x.dt_iso)).getMonth() < 8)
.reduce((acc, x) => {
const h = (new Date(x.dt_iso)).getHours();
return acc.hasOwnProperty(h) ?
Object.assign({}, acc, { [h]: acc[h] + x.clouds.all }) :
Object.assign({}, acc, { [h]: x.clouds.all })
}, {});
/* ballots in the form:
* { userID: [ firstChoice, secondChoice, ... ],
* userID: [ ... ],
* ... }
*/
const instantRunoff = ballots => {
// initialize an map from choices to number of votes
const votes = {};
@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,
<!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 {