Skip to content

Instantly share code, notes, and snippets.

@adam-rocska
adam-rocska / operators+throwIfOptional.swift
Last active March 30, 2022 13:25
A Swift operator unwrapping & returning an optional value if it exists, while throwing an error if it doesn't.
// TODO: Depend on https://github.com/21GramConsulting/Beton instead
@sergdort
sergdort / TaskPublisher.swift
Last active September 26, 2024 10:55
Bridge between async await and Publisher.
@available(iOS 15.0, *)
struct TaskPublisher<Output>: Publisher{
typealias Failure = Never
let work: () async -> Output
init(work: @escaping () async -> Output) {
self.work = work
}
// Based on this StackOverflow answer: https://stackoverflow.com/a/61273595/4239752
import Foundation
import Combine
extension Publisher {
/// collects elements from the source sequence until the boundary sequence fires. Then it emits the elements as an array and begins collecting again.
func buffer<T: Publisher, U>(_ boundary: T) -> AnyPublisher<[Output], Failure> where T.Output == U {
let subject = PassthroughSubject<[Output], Failure>()
// Download the "video GIF"
let data = try! Data(contentsOf: URL(string: "https://thumbs.gfycat.com/ThankfulLawfulAsianelephant-mobile.mp4")!)
let fileName = String(format: "%@_%@", ProcessInfo.processInfo.globallyUniqueString, "html5gif.mp4")
let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)
try! data.write(to: url, options: [.atomic])
// Do the converties
let asset = AVURLAsset(url: url)
guard let reader = try? AVAssetReader(asset: asset) else {
return
@WoonHaKim
WoonHaKim / example.ios.yml
Last active July 17, 2023 03:43
GitHub Action iOS build workflow example
name: Example iOS Build
on:
push:
branches:
- development
jobs:
build-ios:
runs-on: macos-latest
@JoshuaSullivan
JoshuaSullivan / core-image-filters-ios-13.md
Last active March 19, 2024 15:17
An enumeration of iOS 13 Core Image filters.

Core Image Filters

iOS 13 has 218 filters.

New Filters in iOS 13

  • CIDocumentEnhancer
  • CIGaborGradients
  • CIKeystoneCorrectionCombined
  • CIKeystoneCorrectionHorizontal
  • CIKeystoneCorrectionVertical
//
// TYAudioVideoManager.swift
// Yash Thaker
//
// Created by Yash Thaker on 05/12/18.
// Copyright © 2018 Yash Thaker. All rights reserved.
//
/*
1) mergeVideos(videoUrls: [URL], exportUrl: URL, preset: String? = nil, progress: @escaping Progress, completion: @escaping Completion)
@Sorix
Sorix / Package.swift
Last active April 8, 2025 05:41
Example of Package.swift with environment variables support
// swift-tools-version:4.0
import PackageDescription
#if os(Linux)
import Glibc
#else
import Darwin.C
#endif
enum Enviroment: String {
@umohi
umohi / download-github-artifact
Created September 21, 2018 22:48
use curl to download release artifact from github private repository
# in order to download release artifacts from github, you have to first retreive the
# list of asset URLs using the github repo REST API. Use the asset URL to download
# the artifact as a octet-stream data stream. You will need to get an access token
# from "settings -> developer settings -> personal access tokens" on the github UI
#!/bin/bash -e
owner="MY_ORG_NAME"
repo="MY_REPO_NAME"
tag="ARTIFACT_TAG"
artifact="ARTIFACT_NAME"
@smosko
smosko / OSLog+Extensions.swift
Last active December 26, 2022 07:54
Unified Logging Wrapper
import Foundation
@_exported import os.log
public extension OSLog {
convenience init(_ bundle: Bundle = .main, category: String? = nil) {
self.init(subsystem: bundle.bundleIdentifier ?? "default", category: category ?? "default")
}
convenience init(_ aClass: AnyClass, category: String? = nil) {