Skip to content

Instantly share code, notes, and snippets.

@marcoarment
marcoarment / OCObservableKeyPaths.swift
Last active January 18, 2024 06:01
A Combine publisher for `@Observable` key-paths
// I think this works and doesn't create circular references?
/*
Usage: Add OCObservableKeyPaths conformance to the observed type. Then, e.g.
audioPlayer
.publisher(forObservableKeyPaths: [ \.timestamp, \.duration ])
.sink {
// respond to change
}
@marcoarment
marcoarment / Searchable_iOS16.swift
Created July 11, 2023 19:23
Backporting iOS 17's SwiftUI .searchable($isPresented) binding for iOS 16
import SwiftUI
extension View {
public func searchable_iOS16(text: Binding<String>, isPresented: Binding<Bool>, placement: SearchFieldPlacement) -> some View {
modifier(Searchable_iOS16(text: text, isPresented: isPresented, placement: placement))
}
}
public struct Searchable_iOS16: ViewModifier {
@Binding var text: String
@marcoarment
marcoarment / Text+InlineSymbol.swift
Last active October 26, 2023 17:13
SwiftUI Text with inline SF Symbols
import SwiftUI
extension Text {
public struct InlineSymbol {
public let name: String
public let accessibilityLabel: String
public let color: Color?
public init(name: String, accessibilityLabel: String, color: Color? = nil) {
self.name = name
import SwiftUI
struct ContentView: View {
@State var numbers = [1, 2, 3, 4, 5, 6, 7, 8]
var body: some View {
Button {
withAnimation {
numbers.append(Int.random(in: 9..<99))
numbers.sort()
#!/bin/bash
shopt -s nullglob
LOCALUSER=marco # Change this for you, obviously
DISABLED_FILES_DIR=/Users/$LOCALUSER/.quit-adobe
# Are any Adobe user-facing apps running? Assuming they begin with "Adobe ", e.g. "Adobe Audition 2022"
ps ax -c -o 'command=' | egrep '^Adobe ' | fgrep -v 'Adobe Desktop Service' | fgrep -v 'Adobe Installer' > /dev/null
if [ $? -eq 1 ] ; then
import SwiftUI
extension UIColor: Identifiable {
public var id: String {
get { self.accessibilityName }
}
}
struct ContentView: View {
@marcoarment
marcoarment / S3.php
Last active June 25, 2023 19:41
A simple PHP class to perform basic operations against Amazon S3 and compatible services.
<?php
/*
A simple PHP class to perform basic operations against Amazon S3 and compatible
services. Requires modern PHP (7+, probably) with curl, dom, and iconv modules.
Copyright 2022 Marco Arment. Released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@marcoarment
marcoarment / Sun.swift
Created January 17, 2021 16:43
Get sunrise, sunset, and the sun's position for a given time and location. Based on NOAA Solar Calculator.
// Sun.swift
// Created by Marco Arment on 1/17/21
//
// Solar-math functions are directly translated from the NOAA Solar Calculator:
// https://www.esrl.noaa.gov/gmd/grad/solcalc/
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
@marcoarment
marcoarment / apns_jwt_token.php
Last active November 18, 2023 02:24
Generate ES256 JWT tokens for Apple Push Notification Service (APNS) in PHP
<?php
function base64url_encode($binary_data) { return strtr(rtrim(base64_encode($binary_data), '='), '+/', '-_'); }
function apns_jwt_token($team_id, $key_id, $private_key_pem_str)
{
if (! function_exists('openssl_get_md_methods') || ! in_array('sha256', openssl_get_md_methods())) throw new Exception('Requires openssl with sha256 support');
$private_key = openssl_pkey_get_private($private_key_pem_str);
if (! $private_key) throw new Exception('Cannot decode private key');
@marcoarment
marcoarment / ATPLogoView.m
Created April 29, 2014 21:07
Source for the Accidental Tech Podcast (ATP) T-Shirt
// Source for the Accidental Tech Podcast (ATP) T-Shirt:
// http://www.marco.org/2014/04/29/atp-shirts
//
// By Marco Arment, April 28, 2014. MIT license.
@implementation ATPLogoView
- (void)drawRect:(CGRect)rectIgnored
{
NSString *fontName = @"MyriadPro-Semibold";