Skip to content

Instantly share code, notes, and snippets.

View atierian's full-sized avatar

Ian Saultz atierian

  • Amazon Web Services
  • Charleston, SC
View GitHub Profile
@atierian
atierian / embrace_swift_generics.swift
Created December 26, 2023 18:40
Example of parametric polymorphism from WWDC '22 Embrace Swift Generics
// https://developer.apple.com/videos/play/wwdc2022/110352/
/**
some
- holds a fixed concrete type
- guarantees type relationships
any
- holds an abrititray concreate type
- erases type relationships
@atierian
atierian / Device.swift
Created August 31, 2023 15:25
utsname / DeviceInfo
@dynamicMemberLookup
public struct Device {
public let info: Info
public subscript<T>(dynamicMember keyPath: KeyPath<Info, T>) -> T {
info[keyPath: keyPath]
}
}
extension Device: Equatable {
@atierian
atierian / palindrome_permutation.swift
Last active October 23, 2023 17:34
misguided (but fun) attempt at a fast path check for Palidrone Permutations problem
/*
Palindrome Permutation: given a string, write a function to check if it is a permutation of a palindrome.
A palindrome is a word or phrase that is the same forwards and backwards.
A permutation is a rearrangement of letters.
The palindrome does not need to be limited to just dictionary words.
You can ignore casing and non-letter characters.
EXAMPLE
Input: Tact Coa
Output: True (permutations: “taco cat”, “atco cta”, etc.)
#!/bin/bash
# Invoke from root project directory after running `amplify codegen models` to add `CaseIterable`
# conformance to all codegen'd enums
FILES="amplify/generated/models/*.swift"
for f in $FILES
do
echo "Processing $f file..."
awk '/public enum [^CodingKeys]/ {gsub($0, "extension " $3 " CaseIterable {}"); print "\n" $0}' $f >> $f
#!/bin/bash
echo "🧪 scanning for shell injection"
semgrep --config="r/yaml.github-actions.security.run-shell-injection.run-shell-injection"
echo "\n\n"
echo "🧪 scanning for target code checkout"
semgrep --config="r/yaml.github-actions.security.pull-request-target-code-checkout.pull-request-target-code-checkout"
echo "\n\n"
@dynamicMemberLookup
struct Identified<Value> {
let value: Value
let id: String
subscript<T>(dynamicMember keyPath: KeyPath<Value, T>) -> T {
value[keyPath: keyPath]
}
}
@atierian
atierian / CrossModuleGenericLifting.swift
Last active January 25, 2023 17:47
(ab)using enum pattern matching to lift generic types to specific types and vice-versa in a type-safe way
// MARK: Interface Module
struct Request<Output> {
let kind: Kind
enum Kind {
case one((Int) -> Output)
case two((String) -> Output)
}
}
@atierian
atierian / AsyncSequenceExample.swift
Created August 12, 2022 18:00
Subscribing to AsyncSequence vs Combine Publisher
actor Counter: AsyncSequence {
typealias Element = Int
let limit: Int
var current = 1
init(limit: Int, current: Int = 1) {
self.limit = limit
self.current = current
}
@atierian
atierian / README.md
Last active August 21, 2023 11:53
Allow consumers of SwiftUI UIViewRepresentable conforming Views to inject wrapped UIView delegate implementations through ViewModifiers using a ProxyDelegate.

Allow the consumer of a SwiftUI UIViewRepresentable View to inject delegate implementations for the wrapped UIView through View Modifiers by using a proxy delegate.

This can be a helpful pattern when providing a SwiftUI wrapper for a very heavy and complex UIView, where the wrapper implements many of the delegate methods of the wrapped UIView. But you want someone consuming the wrapper to have the ability to inject their own delegate method implementations to override yours, or to leverage some of the methods your not implementing.

@atierian
atierian / Concurrency.swift
Last active November 10, 2021 14:24
Comparison of App Sizes when including the concurrency backport. Compiled with Xcode 13.2 beta.
import UIKit
class ViewController: UIViewController {
let label = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(label)