Skip to content

Instantly share code, notes, and snippets.

View liddiard's full-sized avatar
🙃

Harrison Liddiard liddiard

🙃
View GitHub Profile
@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 })
}, {});
@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 / 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 / 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 / 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 / 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 / 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 / dank.js
Last active December 6, 2016 06:04
Documenting the spread of dank memes at UCLA: https://www.facebook.com/groups/163576114113950/members/
// click the "more members" button programatically to get everyone who likes dank memes
window.setInterval(() => { document.querySelector('.uiMorePagerPrimary').click() }, 5000);
// get the names of everyone who likes dank memes
let people = Array
.from(document.querySelectorAll('.fsl.fwb.fcb'))
.map(a => { return a.innerText });
// get the 100x100 profile photo URLs of everyone who likes dank memes
let photos = Array
@liddiard
liddiard / handlebars-template-loader.js
Last active November 30, 2016 19:12
Load a handlebars template into the DOM with no additional code. Gets the template URL from script's `data-template` attribute, and JSON template data URL from `data-context` attribute.
(function(){
// get a reference to the current script (IE support)
// http://stackoverflow.com/a/22745553
const scripts = document.getElementsByTagName('script');
const currentScript = scripts[ scripts.length - 1 ];
const CONTEXT_URL = currentScript.dataset.context;
const TEMPLATE_URL = currentScript.dataset.template;
@liddiard
liddiard / thoughtpad.html
Last active February 13, 2017 00:40
Simple full-body contenteditable web page with contents persisted in localStorage. I don't really know why you'd need this, but why not?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<title>Thoughtpad</title>
<meta name="description" content="Page description, shows up in search results. Should be no longer than 150-160 characters." />