Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
SRC1=$HOME/Library/Safari
SRC2=$HOME/Library/Containers/com.apple.Safari/Data/Library/Safari
HOST=$( hostname | sed 's/\..*//' )
HOUR=$( date +"%H" )
DST=$HOME/Sync/Safari/$HOST/$HOUR
mkdir -p $DST 2>/dev/null
cd $SRC1
@GeekAndDad
GeekAndDad / three_circles.scad
Last active November 7, 2023 11:41
An answer to "distribute 3 circles evenly inside another" for OpenSCAD for Pete.
// For Pete
// v3.0.2
// by @GeekAndDad
// Define the outer circle radius and desired inner circle radius
outer_circle_radius = 100;
desired_inner_radius = 20;
// Call our function to calulate the centers of the three evenly spaced circles
// and
@GeekAndDad
GeekAndDad / TestMapCVS.swift
Last active August 15, 2023 08:20
A sketch of a possible approach to mapping a CurrentValueSubject<A,Never> to a CurrentValueSubject<B,Never>. Likely can be simplified and cleaned up, but seems to work...
import XCTest
import Cocoa
import Combine
final public class MappedCurrentValueSubject<A, B, Failure, S: CurrentValueSubject<A, Failure>> : Subject
where Failure == S.Failure
{
public typealias Output = B
@GeekAndDad
GeekAndDad / myplayground.swift
Created August 29, 2022 19:54
Sample of drawing into a bitmap
import Cocoa
print( NSImageRep.registeredClasses ) // -> [NSPDFImageRep, NSPICTImageRep, NSEPSImageRep, NSBitmapImageRep]
func test() {
guard let rep = NSBitmapImageRep(bitmapDataPlanes: nil,
pixelsWide: 256,
pixelsHigh: 256,
bitsPerSample: 8,
samplesPerPixel: 4,
@GeekAndDad
GeekAndDad / SafariOpenTabs.scpt
Created May 24, 2022 03:48
*how* many tabs do I have open in Safari? (macOS)
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
@GeekAndDad
GeekAndDad / macOSplayground.swift
Created March 12, 2022 18:38
Simple test around throwing close function and api design
enum ConnectionError: Error {
case fakeWork
case close
case connect
}
struct Connection {
func close(fail: Bool = false) throws {
if fail {
print("throwing during close connection ")
@GeekAndDad
GeekAndDad / ParseTest.swift
Last active January 27, 2022 14:03
Playground to test parsing. Is there simpler way to do this?
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)
// 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 {
@GeekAndDad
GeekAndDad / EjectDrives.scpt
Last active November 20, 2021 00:02
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.
-- 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
@GeekAndDad
GeekAndDad / Move Safari Windows UP.scpt
Last active November 18, 2021 05:15
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 …
-- 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..."