Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
@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
@samsonjs
samsonjs / Example.swift
Last active February 10, 2023 08:45
Tiny OSLog initializer that accepts types instead of strings
// Usage
import OSLog
private let log = Logger.forType(SheepFootPacker.self) // category is the package/module name
class SheepFootPacker {
func squishThings() {
log.debug("squishing")
}
@samsonjs
samsonjs / Sparkle.swift
Created December 20, 2022 16:16 — forked from UnderscoreDavidSmith/Sparkle.swift
Sparkle Effect in SwiftUI
@available(iOS 15.0, *)
struct TwinkleView:View {
private func position(in proxy: GeometryProxy, sparkle:Sparkle) -> CGPoint {
let radius = min(proxy.size.width, proxy.size.height) / 2.0
let drawnRadius = (radius - 5) * sparkle.position.x
let angle = Double.pi * 2.0 * sparkle.position.y
let x = proxy.size.width * 0.5 + drawnRadius * cos(angle)
let y = proxy.size.height * 0.5 + drawnRadius * sin(angle)
@samsonjs
samsonjs / inset.swift
Created December 12, 2022 05:05 — forked from erica/inset.swift
import Cocoa
public struct UIEdgeInsets {
public var top: CGFloat // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
public var left: CGFloat
public var bottom: CGFloat
@samsonjs
samsonjs / Logging.swift
Last active December 3, 2022 02:34
Simple logging helper for OSLog in Swift
import OSLog
extension Logger {
static let subsystem = Bundle.main.bundleIdentifier!
static func `for`(category: String) -> Logger {
Logger(subsystem: subsystem, category: category)
}
}
@samsonjs
samsonjs / BetterNotification.swift
Last active November 28, 2022 06:12
Slightly better type-safe notifications for Apple platforms
import Combine
import Foundation
public protocol BetterNotification {}
private extension BetterNotification {
static var notificationName: Notification.Name {
Notification.Name(rawValue: "BetterNotification:\(Self.self)")
}
}
@samsonjs
samsonjs / SimLink.swift
Last active November 23, 2022 07:28
Paul Samuel’s code for symlinking simulator directories to make them more accessible
@samsonjs
samsonjs / zlocal
Created September 21, 2022 05:13
zlocal from macOS
eval "$(/opt/homebrew/bin/brew shellenv)"
local_paths=(
/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin
/opt/homebrew/Cellar/python@3.10/3.10.*/Frameworks/Python.framework/Versions/3.10/bin(N)
/opt/homebrew/opt/libpq/bin
)
for dir in $local_paths; do
if [[ -d "$dir" ]]; then
path=($dir $path)
@samsonjs
samsonjs / S3.php
Created August 7, 2022 20:30 — forked from marcoarment/S3.php
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