Skip to content

Instantly share code, notes, and snippets.

View antranapp's full-sized avatar

An Tran antranapp

View GitHub Profile
@matiaskorhonen
matiaskorhonen / ffmpeg-pad-and-overlay.sh
Last active May 9, 2025 03:31
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 \
@johnno1962
johnno1962 / InjectionInjection.md
Last active November 23, 2022 02:58
Injection Injection

InjectionIII is an app available that provides "code injection" functionality allowing you to update the implementation of functions, memeber function and SwiftUI content body properties without having to restart your application. This can be useful to iterate over code or design without having to rebuild and restart your application continuously.

https://github.com/johnno1962/InjectionIII

Part of the implementation of injection is that it requires a user to add the following line somewhere in their code:

Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
@ConfusedVorlon
ConfusedVorlon / HSHostingController.swift
Created April 11, 2020 10:03
HSHostingController, easily present fullscreen modals, safari, email, etc from SwiftUI
//
// HSHostingController.swift
// PuppySounds
//
// Created by Rob Jonson on 09/04/2020.
// Copyright © 2020 HobbyistSoftware. All rights reserved.
//
//HSHostingController.swift
import Foundation
@trilliwon
trilliwon / Reencoder.swift
Last active July 9, 2023 08:00
Reencoder ios swift
import AVFoundation
import os.log
/// https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html
/**
Steps
- Use serialization queues to handle the asynchronous nature of reading and writing audiovisual data
- Initialize an asset reader and configure two asset reader outputs, one for audio and one for video
- Initialize an asset writer and configure two asset writer inputs, one for audio and one for video
@dcwatson
dcwatson / hkdf_sha256.swift
Created July 26, 2019 16:04
HKDF implementation in Swift using Apple's CryptoKit framework
func hkdf_sha256(_ seed: Data, salt: Data, info: Data, outputSize: Int = 32) -> Data? {
// It would be nice to make this generic over <H: HashFunction> if HashFunction had byteCount instead of each hash
// individually implementing it.
let iterations = UInt8(ceil(Double(outputSize) / Double(SHA256.byteCount)))
guard iterations <= 255 else {
return nil
}
let prk = HMAC<SHA256>.authenticationCode(for: seed, using: SymmetricKey(data: salt))
let key = SymmetricKey(data: prk)
@haikieu
haikieu / resize-vi.swift
Last active March 28, 2024 04:29 — forked from darcwader/resize-vi.swift
Resize Image using vImage (Updated for Swift 5)
extension UIImage {
func resize(size: CGSize) -> UIImage? {
guard let cgImage = self.cgImage else { return nil}
var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil,
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue),
version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.defaultIntent)
var sourceBuffer = vImage_Buffer()
@pteasima
pteasima / OnScroll.swift
Last active December 16, 2020 17:35
SwiftUI onScroll
import SwiftUI
import Combine
struct OnScroll: ViewModifier {
@Binding var offset: CGFloat
//we can have a version with a closure instead of the binding, but that triggers an infinite loop if content depends on the same Store
// var onOffset: (CGFloat) -> ()
func body(content: Content) -> some View {
return VStack {
@dagronf
dagronf / ImageConversion.swift
Last active April 19, 2025 14:15
Extensions for converting NSImage <-> CGImage <-> CIImage
extension NSImage {
/// Create a CIImage using the best representation available
///
/// - Returns: Converted image, or nil
func asCIImage() -> CIImage? {
if let cgImage = self.asCGImage() {
return CIImage(cgImage: cgImage)
}
return nil
}
@algal
algal / Zipping.swift
Created February 17, 2019 01:18
Zip files on iOS, without using external libraries and without interoperating with the low-level Compression framework
// Zipping.swift
// known-good: Swift 4.2
// Alexis Gallagher
import Foundation
public extension URL {
/// Creates a zip archive of the file or folder represented by this URL and returns a references to the zipped file
///
@ElyDantas
ElyDantas / AutoRezingUiTableView.txt
Last active August 19, 2024 01:16
Resizing UITableView to fit Content Swift
StackOverflow answer by fl034 user.
Link: https://stackoverflow.com/questions/2595118/resizing-uitableview-to-fit-content/48623673#48623673
Swift 4.2 solution without KVO, DispatchQueue, or setting constraints yourself.
This solution is based on Gulz's answer.
1) Create a subclass of UITableView:
import UIKit