Skip to content

Instantly share code, notes, and snippets.

View codeactual's full-sized avatar

David Smith codeactual

  • Found Apparatus
View GitHub Profile
struct OverflowLayout: Layout {
var spacing = CGFloat(10)
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let containerWidth = proposal.replacingUnspecifiedDimensions().width
let sizes = subviews.map { $0.sizeThatFits(.unspecified) }
return layout(sizes: sizes, containerWidth: containerWidth).size
}
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
@codeactual
codeactual / archive-env.log
Created June 3, 2023 07:53 — forked from ben-xD/archive-env.log
XCode environment variables available during Archiving
ACTION=install
ADDITIONAL_SDKS=
AD_HOC_CODE_SIGNING_ALLOWED=YES
ALL_OTHER_LDFLAGS=' '
ALL_OTHER_LIBTOOLFLAGS=' '
ALTERNATE_GROUP=staff
ALTERNATE_LINKER=
ALTERNATE_MODE=u+w,go-w,a+rX
ALTERNATE_OWNER=username
ALTERNATE_PERMISSIONS_FILES=
@codeactual
codeactual / sqlite_random_sample.sql
Created February 27, 2023 22:34 — forked from swayson/sqlite_random_sample.sql
Efficient way to do random sampling in SQLite.
SELECT * FROM table
WHERE _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM table))
LIMIT 1
//
// SFSymbolImage.swift
// SFSymbolVariableValueAnimationWrong
//
// Created by Matthew Young on 12/22/22.
//
import SwiftUI
struct AnimatableVariableValueModifier: Animatable, ViewModifier {
@codeactual
codeactual / AVPlayer+Scrubbing.swift
Created November 15, 2022 19:27 — forked from shaps80/AVPlayer+Scrubbing.swift
Enables smooth frame-by-frame scrubbing (in both directions) – similar to Apple's applications.
public enum Direction {
case forward
case backward
}
internal var player: AVPlayer?
private var isSeekInProgress = false
private var chaseTime = kCMTimeZero
private var preferredFrameRate: Float = 23.98
@codeactual
codeactual / UIScrollViewWrapper.swift
Created November 11, 2022 20:32 — forked from timothycosta/UIScrollViewWrapper.swift
UIScrollView wrapped for SwiftUI
//
// UIScrollViewWrapper.swift
// lingq-5
//
// Created by Timothy Costa on 2019/07/05.
// Copyright © 2019 timothycosta.com. All rights reserved.
//
import SwiftUI
import UIKit
import Combine
public extension Task {
/// Keep a reference to a task that can be cancelled.
func store(in set: inout Set<AnyCancellable>) {
set.insert(AnyCancellable {
self.cancel()
})
}
@codeactual
codeactual / cross-view-lines.swift
Created September 15, 2022 15:15 — forked from bjhomer/cross-view-lines.swift
Creating cross-view lines in SwiftUI
//
// ContentView.swift
// SwiftUIPlayground
//
// Created by BJ Homer on 4/26/21.
//
import SwiftUI
@codeactual
codeactual / CropVideo.m
Created August 24, 2022 15:57 — forked from zrxq/CropVideo.m
Crop video to square with a specified side respecting the original video orientation
@import MobileCoreServices;
@import AVFoundation;
@import AssetsLibrary;
// ...
- (void)cropVideoAtURL:(NSURL *)videoURL toSquareWithSide:(CGFloat)sideLength completion:(void(^)(NSURL *resultURL, NSError *error))completionHander {
/* asset */
@codeactual
codeactual / BetterTapGesture.swift
Created August 12, 2022 13:37 — forked from fluidpixel/BetterTapGesture.swift
Using SwiftUI DragGesture as a tap, as TapGesture doesn't give location (as of beta6)
struct ContentView: View {
@State var moved: CGFloat = 0
@State var startTime: Date?
var body: some View {
//0 means that it acts like a press
//coordinateSpace local means local to the view its added to
let tap = DragGesture(minimumDistance: 0, coordinateSpace: .local)
.onChanged { value in
//store distance the touch has moved as a sum of all movements