Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃

Dad @ GeekAndDad GeekAndDadDad

🙃
View GitHub Profile
@GeekAndDadDad
GeekAndDadDad / SafariOpenTabs.scpt
Created May 24, 2022
*how* many tabs do I have open in Safari? (macOS)
View SafariOpenTabs.scpt
local countOfWindows
local countOfTabs
tell application "Safari"
set countOfWindows to count of windows
set countOfTabs to 0
repeat with n from 1 to countOfWindows
set countOfTabs to countOfTabs + (count of tabs in window n)
end repeat
@GeekAndDadDad
GeekAndDadDad / macOSplayground.swift
Created Mar 12, 2022
Simple test around throwing close function and api design
View macOSplayground.swift
enum ConnectionError: Error {
case fakeWork
case close
case connect
}
struct Connection {
func close(fail: Bool = false) throws {
if fail {
print("throwing during close connection ")
@GeekAndDadDad
GeekAndDadDad / ParseTest.swift
Last active Jan 27, 2022
Playground to test parsing. Is there simpler way to do this?
View ParseTest.swift
import Parsing
/// simple test.
/// First char must exist and must be a char from a to z
/// Followed by zero or more characters from a to z or 0 to 9
/// Must end with a space or be the end of input
///
let validFirstChars = CharacterSet(charactersIn: "a"..."z")
let validFollowingChars = CharacterSet(charactersIn: "0"..."9").union(validFirstChars)
View transiftion-present-dismiss.swift
// Advanced SwiftUI Transitions
// https://swiftui-lab.com
// https://swiftui-lab.com/advanced-transitions
import SwiftUI
struct GeometryEffectTransitionsDemo: View {
@State private var show = false
var body: some View {
@GeekAndDadDad
GeekAndDadDad / EjectDrives.scpt
Last active Nov 20, 2021
AppleScript to eject mounted local disks. Written for when I'm going to take my laptop off my desk and am disconnecting from my TB hub.
View EjectDrives.scpt
-- AppleScript I wrote to eject mounted USB disks before I disconnect my USB-C hub.
-- Notes:
-- this will halt a time machine backup to a locally mounted
-- drive when it tries to eject it.
-- will also halt a time machine backup to a network destination.
-- tested in macOS 11.6 (2021.11.19)
-- License: MIT
tell application "System Events"
set ds to get disks
@GeekAndDadDad
GeekAndDadDad / Move Safari Windows UP.scpt
Last active Nov 18, 2021
Code for a blog post about a silly AppleScript to move Safari windows back up after a bug in Safari moves them down on wake from sleep sometimes. The post is here: https://geekanddad.wordpress.com/?p=2161. This script moves all Safari windows up the same amount to keep their relative positioning and moves them up as much as possible while still …
View Move Safari Windows UP.scpt
-- Put in the public domain with zero warranty of any kind
--
-- only tested on macOS 11.6, with Safari 13.0; ymmv
use scripting additions
tell application "Safari"
set windlist to windows
log "Examining " & length of windlist & " windows..."
@GeekAndDadDad
GeekAndDadDad / TestDecodingFunTests.swift
Last active Sep 22, 2020
@chunkyguy on twitter said they were facing a similar challenge to one I was facing, but their challenge actually seemed a little different and potentially easier. So I explored their challenge and created this solution.
View TestDecodingFunTests.swift
//
// TestDecodingFunTests.swift
// TestDecodingFunTests
//
// Created by Dad on 9/22/20.
//
// Poster wanted to be able to parse (visual) "components" out of a json file that would
// have various components of various types.
@GeekAndDadDad
GeekAndDadDad / confusing.swift
Last active Jul 24, 2020
Computed properties don't call specialized version of functions? Work fine when you call the specialized functions directly but not when those functions are used within a getter or setter it seems… ???
View confusing.swift
// macOS playground source
// swift 5.3, Xcode 12b2
import Cocoa
struct Foo<A> {
var subVal: Any?
let defaultValue: A
init(defaultValue: A) {
@GeekAndDadDad
GeekAndDadDad / detweet.swift
Created Jun 21, 2020 — forked from mxcl/detweet.swift
Delete all tweets and favorites older than two months ago. Instructions in comment.
View detweet.swift
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
@GeekAndDadDad
GeekAndDadDad / ContentView.Swift
Created Apr 3, 2020
Bug? Two `.alert` modifiers mean only last one works?
View ContentView.Swift
//
// ContentView.swift
// TestAlert
//
//
import SwiftUI
struct ContentView: View {
@State private var showAlert1: Bool = false