Skip to content

Instantly share code, notes, and snippets.

View cwalo's full-sized avatar

Corey Walo cwalo

View GitHub Profile
@myleshyson
myleshyson / Command.swift
Last active August 27, 2024 08:22
Execute CLI Commands with Swift. Supports generating output, streaming output, and running sudo commands.
import Foundation
struct ShellCommand {
@discardableResult
static func stream(_ command: String) -> Int32 {
let outputPipe = Pipe()
let task = self.createProcess([command], outputPipe)
outputPipe.fileHandleForReading.readabilityHandler = { fileHandle in self.streamOutput(outputPipe, fileHandle) }
do {
@IanKeen
IanKeen / Abstraction.swift
Created August 16, 2022 17:41
TCA Scoping Abstraction
// MARK: - TCAView
public protocol TCAView: View where Body == WithViewStore<ScopedState, ScopedAction, Content> {
associatedtype ViewState
associatedtype ViewAction
associatedtype ScopedState
associatedtype ScopedAction
associatedtype Content
@KaneCheshire
KaneCheshire / AnyTask.swift
Last active August 22, 2024 18:31
Type-erased Swift Task that cancels itself on deinit
/// A type-erased task that you can store in a collection
/// to allow you to cancel at a later date.
///
/// Upon deinit of the task, the task will be cancelled
/// automatically. Similar to Combine's AnyCancellable.
final class AnyTask {
/// Call this cancellation block to cancel the task manually.
let cancel: () -> Void
/// Checks whether the task is cancelled.
@saagarjha
saagarjha / library_injector.cpp
Last active September 21, 2024 01:51
Load a library into newly spawned processes (using DYLD_INSERT_LIBRARIES and EndpointSecurity)
// To compile: clang++ -arch x86_64 -arch arm64 -std=c++20 library_injector.cpp -lbsm -lEndpointSecurity -o library_injector,
// then codesign with com.apple.developer.endpoint-security.client and run the
// program as root.
#include <EndpointSecurity/EndpointSecurity.h>
#include <algorithm>
#include <array>
#include <bsm/libbsm.h>
#include <cstddef>
#include <cstdint>
@WunDaii
WunDaii / BarcodeScannerViewRepresentable.swift
Last active June 14, 2024 19:40
Barcode Scanner Camera View for SwiftUI
//
// BarcodeScannerViewRepresentable.swift
//
// Created by Daven Gomes on 28/08/2020.
//
import SwiftUI
import AVFoundation
import UIKit
@nurtugan
nurtugan / DiffableDataSource-DeleteItem.swift
Last active July 17, 2024 20:28
Example of Deleting Item from Diffable Data Source
@objc
private func handleGet(_ sender: UIButton) {
var superview = sender.superview
while superview != nil {
if let cell = superview as? UICollectionViewCell {
guard let indexPath = collectionView.indexPath(for: cell),
let objectIClickedOnto = diffableDataSource.itemIdentifier(for: indexPath) else { return }
var snapshot = diffableDataSource.snapshot()
snapshot.deleteItems([objectIClickedOnto])
diffableDataSource.apply(snapshot)
@knandersen
knandersen / morphagene_ableton.py
Last active August 23, 2024 01:55 — forked from ferrihydrite/morphagene_audacity.py
Allows you to use Ableton projects and exports as reels for the Make Noise Morphagene eurorack module. Since a few people have found the script not working or difficulty getting python to work, I have created a web-based tool: https://knandersen.github.io/morphaweb/
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
USAGE:
morphagene_ableton.py -w <inputwavfile> -l <inputlabels> -o <outputfile>'
Instructions in Ableton:
Insert locators as splice markers in your project (Create > Add Locator)
Export Audio/Video with
Sample Rate: 48000 Hz
@AliSoftware
AliSoftware / Bindings.swift
Last active September 2, 2024 22:48
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@cwalo
cwalo / things_you_should_know.md
Last active June 29, 2020 14:59
Things you should know, but might forget...

Things you should know, but might forget...

This is a curated list of reference material that anyone who develops in the Apple domain will hopefully find helpful. Most items are things I have used and can vouch for.

--

Swift

--

The Swift Programming Language

Swift Forums

@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active September 24, 2024 21:51
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse