Skip to content

Instantly share code, notes, and snippets.

View soundflix's full-sized avatar
💥
learning a lot

soundflix soundflix

💥
learning a lot
  • Berlin
View GitHub Profile
@Amzd
Amzd / StateObject.swift
Last active March 27, 2024 20:14
StateObject that works in iOS 13
import Combine
import PublishedObject // https://github.com/Amzd/PublishedObject
import SwiftUI
/// A property wrapper type that instantiates an observable object.
@propertyWrapper
public struct StateObject<ObjectType: ObservableObject>: DynamicProperty
where ObjectType.ObjectWillChangePublisher == ObservableObjectPublisher {
/// Wrapper that helps with initialising without actually having an ObservableObject yet
@Amzd
Amzd / ColorPicker.swift
Last active August 6, 2024 08:07
What SwiftUI's ColorPicker should have been.
import SwiftUI
@available(iOS 14.0, *)
public struct ColorPickerWithoutLabel: UIViewRepresentable {
@Binding var selection: Color
var supportsAlpha: Bool = true
public init(selection: Binding<Color>, supportsAlpha: Bool = true) {
self._selection = selection
self.supportsAlpha = supportsAlpha
@thecodewarrior
thecodewarrior / App Icon Template.svg
Last active September 24, 2024 02:45
An SVG template for creating macOS app icons, including guides and the standard drop shadow
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wtsnz
wtsnz / ContentView.swift
Last active September 5, 2024 01:17
Playing around with hosting SwiftUI Views in an NSWindow from inside a View 🙃 (also works for the NSStatusBar item!)
import SwiftUI
struct ContentView: View {
@State var now = Date()
@State var showWindow = false
@State var text: String = ""
let timer = Timer.publish(every: 1, on: .current, in: .common).autoconnect()
@jemmons
jemmons / Create Input with Block.swift
Last active November 17, 2022 07:04
Sample CoreMIDI code…
// See: https://forums.developer.apple.com/thread/65997
MIDIInputPortCreateWithBlock(midiClient, "Instrument" as CFString, &inPort, {
(unsafePacketList: UnsafePointer<MIDIPacketList>, pointer: UnsafeMutableRawPointer?) in
let packetList = unsafePacketList.pointee
if packetList.numPackets == 1 {
let packet = packetList.packet
if packet.length == 3 && packet.data.0 == 144 {
/* Note-On */
let note = packet.data.1
@allenhumphreys
allenhumphreys / CreateCroppedPixelBufferBiPlanar.c
Last active May 3, 2024 06:58
Functions in Swift/C to Crop and Scale CVPixelBuffers in the BiPlanar formats
CVPixelBufferRef createCroppedPixelBufferBiPlanar(CVPixelBufferRef srcPixelBuffer, CGRect croppingRect, CGSize scaleSize) {
OSType inputPixelFormat = CVPixelBufferGetPixelFormatType(srcPixelBuffer);
assert(inputPixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
|| inputPixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange);
size_t inputWidth = CVPixelBufferGetWidth(srcPixelBuffer);
size_t inputHeight = CVPixelBufferGetHeight(srcPixelBuffer);
assert(CGRectGetMinX(croppingRect) >= 0);