Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
@samsonjs
samsonjs / LogEvent.swift
Created April 23, 2024 00:01
Log info about an event titled "View recent photos"
import EventKit
import Foundation
import ObjectiveC.runtime
func logIvarList(obj: NSObject) {
var count: UInt32 = 0
if let ivars = class_copyIvarList(type(of: obj), &count) {
for i in 0..<Int(count) {
let ivar = ivars[i]
let name = ivar_getName(ivar).map(String.init(cString:)) ?? "Unknown"
@samsonjs
samsonjs / photos-navigation-url-candidates.txt
Last active April 19, 2024 03:05
Flailing trying to find out how to open Photos.app (aka MobileSlideShow.app) to a specific asset like the Photo Shuffle lock screen
Decompiling the binary and looking through the methods `-[PhotosWindowSceneDelegate openRoutingURL:]`
and `-[PhotosURLNavigationRequest _navigateAllowingRetry:]` uncovers some candidates:
- photos-navigation://asset?uuid={uuid}
- photos-navigation://album?name=recents&revealassetuuid={uuid}
- photos-navigation://contentmode?id=photos&assetuuid={uuid}&oneUp=1
Opening up an album by name works but so far I've had no luck figuring out how to show a specific asset.
And ideally it would open up in the photo library tab not the albums tab, just like the Photo Shuffle
lock screen.
@samsonjs
samsonjs / AssetFetcher.swift
Created April 18, 2024 21:17
Fetching assets from the photo library
//
// AssetFetcher.swift
// DailyDrip
//
// Created by Sami Samhuri on 2022-11-06.
//
import Foundation
import Photos
import SwiftUI
import AsyncAlgorithms
struct AsyncChanges<V>: ViewModifier where V : Equatable, V: Sendable {
typealias Element = (oldValue: V, newValue: V)
typealias Action = (AsyncStream<Element>) async -> Void
@State private var streamPair = AsyncStream<Element>.makeStream()
private let action: Action
private let value: V
@samsonjs
samsonjs / AudioSession.swift
Created October 17, 2023 20:03
Configure AVAudioSession for specific SwiftUI views
import AVFoundation
import OSLog
private let log = Logger(subsystem: "Whatever", category: "AudioSession")
enum AudioSession {
enum Source: String {
case videoPlayback = "video playback"
// ... add your othe use-cases here
}
@samsonjs
samsonjs / 💥.log
Created June 22, 2023 20:07
KMM crash log for drag-select-compose in the iOS simulator
Uncaught Kotlin exception: kotlin.IllegalArgumentException: Failed to open iconv for charset UTF-8 with error code 22
at 0 DragSelectCompose 0x100d26dff kfun:kotlin.Throwable#<init>(kotlin.String?){} + 123
at 1 DragSelectCompose 0x100d1f5d3 kfun:kotlin.Exception#<init>(kotlin.String?){} + 119
at 2 DragSelectCompose 0x100d1f97b kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 119
at 3 DragSelectCompose 0x100d1fd23 kfun:kotlin.IllegalArgumentException#<init>(kotlin.String?){} + 119
at 4 DragSelectCompose 0x1016bceb3 kfun:io.ktor.utils.io.charsets.checkErrors#internal + 815
at 5 DragSelectCompose 0x1016bc6e3 kfun:io.ktor.utils.io.charsets.CharsetImpl.<init>#internal + 615
at 6 DragSelectCompose 0x1016b95e3 kfun:io.ktor.utils.io.charsets.Charsets#<init>(){} + 191
at 7 DragSelectCo
struct ContentViews: View {
@State var image: UIImage
@State private var imageWidth: CGFloat = 0
@State private var imageHeight: CGFloat = 0
@State private var imageFrame: CGRect = .zero
@State private var rotationAngle: Double = 0
@State private var wdt: Double = 0
@samsonjs
samsonjs / index-bloat-by-table.sql
Last active April 5, 2023 22:17
A collection of useful Postgres snippets that I've collected from the web
WITH
constants AS (
SELECT
current_setting('block_size')::numeric AS bs,
-- What is this? Some header size?
23 AS hdr,
-- What is this? could be the word size or some other basic unit as it was defined as 4 by default
-- and 8 on 64-bit machines in the original query.
8 AS ma
),
@samsonjs
samsonjs / ContentView.swift
Created March 29, 2023 01:39
Proof-of-concept for swapping out items in a navigation path in SwiftUI, see https://mastodon.social/@caseyliss/110103718721678762
import SwiftUI
enum NavDest: Hashable {
case a
case b
case c
case d(Int)
}
struct ContentView: View {
@samsonjs
samsonjs / ZigZagBorder.swift
Created March 11, 2023 04:33
Zigzag border view for SwiftUI, but it doesn't look very good
import SwiftUI
/// Mostly courtesy of ChatGPT but even with some coaching it couldn't get it to the finish line. Humans are still useful! It's still ugly though.
struct ZigzagBorder: Shape {
let lineWidth: CGFloat
let amplitude: CGFloat
func path(in rect: CGRect) -> Path {
var path = Path()
let startX = rect.minX