Skip to content

Instantly share code, notes, and snippets.

View antranapp's full-sized avatar

An Tran antranapp

View GitHub Profile
@kidGodzilla
kidGodzilla / pdf2png.sh
Last active May 20, 2024 07:03
PDF to PNG Script for Quickdrop App
# PDF to PNG shell script for Quickdrop app
# https://quickdrop.antran.app/
# pdfburst shell script
# chmod 0755 pdfburst
#!/usr/bin/swift
import Foundation
import PDFKit
@Priva28
Priva28 / VisionOSUniformSizedWindow.swift
Created February 22, 2024 10:12
A window in visionOS with a changeable aspect ratio.
import SwiftUI
public struct UniformWindowGroup<Content: View>: Scene {
var id: String?
var maxWidth: CGFloat
var maxHeight: CGFloat
var aspectRatio: CGFloat
var content: Content
@State private var setSize: CGSize?
@JadenGeller
JadenGeller / DragModifier.swift
Last active May 22, 2024 15:23
NSFilePromiseProvider with SwiftUI, to drag a file that's loaded asynchronously
import SwiftUI
import UniformTypeIdentifiers
struct FileDragProvider: NSViewRepresentable {
var filePromise: FilePromise
var preview: PlatformImage
class NSViewType: NSView, NSFilePromiseProviderDelegate, NSDraggingSource {
var filePromise: FilePromise
var preview: PlatformImage
@MarcoEidinger
MarcoEidinger / findRequiredReasonAPIUsage.sh
Created August 21, 2023 19:55
A shell script to find if any "required reason API" are used in Swift or Objective-C files within that folder or subfolders
#!/bin/bash
# https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api
searchTerms=(
# File timestamp APIs
"creationDate"
"modificationDate"
"fileModificationDate"
"contentModificationDateKey"
"creationDateKey"
@gdavis
gdavis / ThreadSafe.swift
Last active March 18, 2024 14:17
ThreadSafe is a property wrapper that can be used to control atomic access to the underlying property while allowing concurrent access to reading the value.
//
// ThreadSafe.swift
// GDICore
//
// Created by Grant Davis on 1/2/21.
// Updated to support `_modify` accessor on 12/5/21.
//
// Copyright © 2021 Grant Davis Interactive, LLC. All rights reserved.
//
import Foundation
JSON:
https://unpkg.com/emoji.json@13.1.0/emoji.json
class EmojiManager: ObservableObject {
@Published var emojis: [EmojiObject] = []
init() {
decodeJSON()
@zarghol
zarghol / gist:3c0f29bdbe7a6317536bf0a8c76a7380
Created June 8, 2021 22:58
Experiment with new SwiftUI Canvas View
import SwiftUI
enum TrigonometricFunction: CaseIterable {
case sinus
case cosinus
func apply(_ value: Double) -> Double {
switch self {
case .cosinus:
return cos(value)
@MapaX
MapaX / makeXCFamework.sh
Created April 26, 2021 10:45
Shell script to create xcframeworks from MLKit frameworks
#!/bin/zsh
makeXCFramework () {
BASEDIR=$(pwd)
echo "Script location: ${BASEDIR}"
LIBNAME=$(basename $BASEDIR)
echo "lib is: $LIBNAME"
cd Frameworks
// Don't forget to add to the project:
// 1. DeepLabV3 - https://developer.apple.com/machine-learning/models/
// 2. CoreMLHelpers - https://github.com/hollance/CoreMLHelpers
enum RemoveBackroundResult {
case background
case finalImage
}
extension UIImage {
@matiaskorhonen
matiaskorhonen / ffmpeg-pad-and-overlay.sh
Last active March 12, 2024 08:57
Add a device frame to an iOS screen recording (specifically an iPhone 12 Pro)
# Record screen from simulator:
xcrun simctl io booted recordVideo appVideo.mov
# Full size screen recording
ffmpeg -i screen-recording.mp4 -i iPhone12ProOverlay.png \
-filter_complex "scale=-1:2532,pad=width=3656:height=2057:x=(ow-iw)/2:y=(oh-ih)/2,overlay=x=0:y=0" \
output.mp4
# Screen recording resized to 1920px height
ffmpeg -i screen-recording.mp4 -i iPhone12ProOverlay-3656.png \