Skip to content

Instantly share code, notes, and snippets.

View drewkerr's full-sized avatar

Andrew Kerr drewkerr

View GitHub Profile
@drewkerr
drewkerr / asteroids.js
Created July 22, 2018 13:07
Asteroids
// Credit: https://github.com/erkie/erkie.github.com
(function() {
function Asteroids() {
if ( ! window.ASTEROIDS )
window.ASTEROIDS = {
enemiesKilled: 0,
startedPlaying: (new Date()).getTime()
};
@drewkerr
drewkerr / covid-bendigo.js
Last active December 21, 2021 00:44
COVID-19 Cases in Bendigo, Victoria, Australia
const url = 'https://covid-sheets-mirror.web.app/api?'
const sid = '1nUUU5zPRPlhAXM_-8R7lsMnAkK4jaebvIL5agAaKoXk'
function params(obj) {
return Object.entries(obj)
.map(([key, val]) => `${key}=${encodeURI(val)}`).join("&")
}
const cases = url + params({
cache: true,
@drewkerr
drewkerr / get-focus-mode.js
Last active July 25, 2024 09:36
Read the current Focus mode on macOS Monterey (12.0+) using JavaScript for Automation (JXA)
const app = Application.currentApplication()
app.includeStandardAdditions = true
function getJSON(path) {
const fullPath = path.replace(/^~/, app.pathTo('home folder'))
const contents = app.read(fullPath)
return JSON.parse(contents)
}
function run() {
@drewkerr
drewkerr / set-focus-mode.js
Created April 13, 2022 14:51
Set a Focus mode on macOS Monterey (12.0+) using JavaScript for Automation (JXA)
function toggleFocus(focus) {
const app = Application("System Preferences")
const pane = app.panes.byId("com.apple.preference.notifications").anchors.byName("Focus")
app.reveal(pane) // Open the preference pane
// Useful way of inspecting the UI hierarchy of an open app:
// Application("System Events").applicationProcesses.byName("System Preferences").entireContents()
const ui = Application("System Events").applicationProcesses.byName("System Preferences").windows.byName("Notifications & Focus").tabGroups.at(0)
@drewkerr
drewkerr / Bezier.js
Created December 27, 2022 23:15
Suggestion to add Bézier curves to Jason Snell’s weather station Scriptable widget.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-purple; icon-glyph: chart-line;
const data = [59, 56, 52, 58, 57, 57, 52, 53]
// [points] to img of smooth (bezier) line graph
function lineGraph(points, width, height, line) {
let context = new DrawContext()
context.size = new Size(width, height)
@drewkerr
drewkerr / Medal Tally.js
Last active August 30, 2024 08:37
Olympic Medal Tally widget
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: medal;
async function getData() {
//const url = "https://sph-c-api.olympics.com/summer/competition/api/ENG/medals" // Olympic Games
const url = "https://sph-c-api.olympics.com/summer-para/competition/api/ENG/medals" // Paralympic Games
const req = new Request(url)
const res = await req.loadJSON()
return await res.medalStandings.medalsTable
}