Skip to content

Instantly share code, notes, and snippets.

View simonbs's full-sized avatar
🐼

Simon B. Støvring simonbs

🐼
View GitHub Profile
@simonbs
simonbs / Tour de France Profile.js
Created July 13, 2021 14:37
Scriptable script showing a profile of the current Tour de France stage
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: yellow; icon-glyph: bicycle;
let stages = await loadStages()
let stage = findStage(stages)
if (stage == null) {
let widget = createTournamentOverWidget()
await widget.presentMedium()
} else {
let stageDetails = await loadStageDetails(stage.id)
@simonbs
simonbs / Today's Pollen Count.js
Last active July 17, 2022 17:35
Shows the current pollen counts. Pulls data from a Danish provider and only works in Denmark.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: tree;
const STATION_VIBORG = "49"
const STATION_CPH = "48"
const IDS = {
BIRCH: "7",
MUGWORT: "31",
ALDER: "1",
ELM: "4",
@simonbs
simonbs / childForStatusBarStyle.swift
Last active September 25, 2023 14:49
It seems that -childForStatusBarStyle: isn’t called on a UIViewController that is presented from a SwiftUI view using UIViewControllerRepresentable. Or am I doing something wrong? I came up with this *ugly* workaround that swizzles -childForStatusBarStyle: to return an associated object when present and uses the default implementation as fallback.
// We'll store a UIViewController as an associated object and don't want to store a strong reference to it.
private final class WeakBoxedValue<T: AnyObject>: NSObject {
private(set) weak var value: T?
init(_ value: T?) {
self.value = value
}
}
// Use associated objects to a UIViewController that should determine the status bar appearance.
@simonbs
simonbs / UserDefault.swift
Last active August 2, 2025 16:09
Property wrapper that stores values in UserDefaults and works with SwiftUI and Combine.
/**
* I needed a property wrapper that fulfilled the following four requirements:
*
* 1. Values are stored in UserDefaults.
* 2. Properties using the property wrapper can be used with SwiftUI.
* 3. The property wrapper exposes a Publisher to be used with Combine.
* 4. The publisher is only called when the value is updated and not
* when_any_ value stored in UserDefaults is updated.
*
* First I tried using SwiftUI's builtin @AppStorage property wrapper
@simonbs
simonbs / Indie App Santa.js
Last active December 2, 2020 20:46
Indie App Santa
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: calendar-alt;
let data = await loadData()
let app = data.today[0]
let widget = null
if (config.runsInWidget) {
if (config.widgetFamily == "small") {
widget = await createSmallWidget(app)
} else {
@simonbs
simonbs / One More Thing.js
Last active February 17, 2024 11:04
Countdown to Apple's "One More Thing" event on November 10th, 2020
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-purple; icon-glyph: apple-alt;
const TITLE = "One More Thing"
const DATE = "2020-11-10T17:00:00Z"
const IMG_URL = "https://i.ibb.co/f2SN2Wb/bg.png"
let widget = await createWidget()
if (config.runsInWidget) {
Script.setWidget(widget)
@simonbs
simonbs / Animals of the Day.js
Created November 1, 2020 13:05
Shows an image of an animal
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: purple; icon-glyph: paw;
let pandaURL = "https://c402277.ssl.cf1.rackcdn.com/photos/7749/images/story_full_width/HI_204718.jpg?1414503137"
let slothURL = "https://c402277.ssl.cf1.rackcdn.com/photos/6518/images/story_full_width/iStock_000011145477Large_mini_%281%29.jpg?1394632882"
let redPandaURL = "https://c402277.ssl.cf1.rackcdn.com/photos/8036/images/story_full_width/WEB_279173.jpg?1418412345"
let pandaImg = await getImage(pandaURL)
let slothImg = await getImage(slothURL)
let redPandaImg = await getImage(redPandaURL)
@simonbs
simonbs / Hi, Speed.js
Last active May 21, 2025 06:02
Greg Jowsiak's "Hi, Speed" widget recreated in Scriptable
// This script recreates Greg Joswiak's widget that counts down to the "Hi, Speed" Apple Event on October 13th, 2020.
// You can see Greg's widget in this tweet:
// https://twitter.com/gregjoz/status/1313519797879988225
//
// You'll need this image for the background:
// https://i.imgur.com/t9Jr8kL.png
//
// I've stored the image at imgs/hispeed.png Scriptable's folder in iCloud Drive.
let widget = createWidget()
@simonbs
simonbs / Is Slack down?.js
Created September 3, 2020 04:56
Scriptable script to check if Slack is down. Works with Siri and widgets.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: orange; icon-glyph: exclamation-triangle;
// Checks if Slack is down by examining their status page. Works perfectly with Siri.
let url = "https://status.slack.com"
let r = new Request(url)
if (config.runsWithSiri) {
let isDown = await getIsDown(url)
if (isDown) {
Speech.speak("Yes")
@simonbs
simonbs / Latest News on MacStories.js
Created August 15, 2020 06:07
Show latest news on MacStories in a widget.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: newspaper;
let items = await loadItems()
if (config.runsInWidget) {
let widget = createWidget(items)
Script.setWidget(widget)
Script.complete()
} else {