Skip to content

Instantly share code, notes, and snippets.

View antranapp's full-sized avatar

An Tran antranapp

View GitHub Profile
@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 13, 2024 11:00
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
///
@SangsooNam
SangsooNam / gh-pages-deploy.sh
Created January 6, 2019 23:11
Script to deploy a target directory to `gh-pages` branch.
#!/bin/bash
directory=_site
branch=gh-pages
build_command() {
jekyll build
}
echo -e "\033[0;32mDeleting old content...\033[0m"
rm -rf $directory
@shalyf
shalyf / CVPixelBuffer(vImage).swift
Last active January 6, 2024 20:46
CVPixelBuffer通过vImage转换成CGImage
import Accelerate.vImage
func getImageBuffer(from pixelBuffer: CVPixelBuffer) -> vImage_Buffer? {
var buffer = vImage_Buffer()
let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.first.rawValue)
var cgFormat = vImage_CGImageFormat(bitsPerComponent: 8,
bitsPerPixel: 32,
colorSpace: nil,
bitmapInfo: bitmapInfo,
version: 0,