Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View drewkerr's full-sized avatar

Andrew Kerr drewkerr

View GitHub Profile
@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 / 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 / get-focus-mode.js
Last active April 18, 2024 14:02
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 / 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 / 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()
};