Skip to content

Instantly share code, notes, and snippets.

View younata's full-sized avatar

Rachel Brindle younata

View GitHub Profile
@younata
younata / MixedSwiftTestingXCTest.swift
Created October 13, 2024 23:06
Mixed Swift Testing Issue
import XCTest
import Testing
final class MixedSwiftTestingXCTestTests: XCTestCase {
func testShouldntRecordFailure() {
XCTExpectFailure("This should fail")
XCTFail("This should fail")
}
}
@younata
younata / ArtistsController.swift
Created May 22, 2024 18:03
Example Client-Server implementation, using a theoretical variant of the subsonic API that actually returns JSON
import Observation
enum State<T> {
case loading
case loaded(T)
case failed(String)
}
@MainActor
final class ArtistsController {
@younata
younata / BackgroundExecutorApp.swift
Created March 19, 2024 00:41
BackgroundExecutorTestApp
import SwiftUI
import Dispatch
// A simple app to verify https://mastodon.social/@calicoding/112118821467209266
// Allows you to check using Swift Tasks, or Dispatch Queues.
//
// I found this to not be the case, but maybe this isn't realistic?
// When compiled on Xcode 15.3 (either debug or release) and run on iOS 17.4,
// background QoS tasks are still executed even when Low Power Mode is enabled.
import Combine
class FakeCall<T> {
private(set) var calls = [T]()
func record(_ arguments: T) {
calls.append(arguments)
}
func reset() {
@younata
younata / layouthelpers.swift
Created December 19, 2020 21:02
UIView Autolayout Helpers
import UIKit
extension UIView {
func removeAllSubviews() {
for view in self.subviews {
view.removeFromSuperview()
}
}
@discardableResult
@younata
younata / BadCSVParser.swift
Created October 7, 2018 16:15
Bad CSV Parser in swift
// Quick and dirty CSV parser I wrote. Handles edge cases badly. Doesn't perform well. Doesn't handle large csv files.
// But, hey, it solved my use case!
// Swift 4.2+
func parseCSVBadly(csvData: Data) -> [[String]] {
guard let csv = String(data: csvData, encoding: .utf8) else { return [] }
return csv.components(separatedBy: CharacterSet.newlines).compactMap { line in
guard !line.hasPrefix("#") else { return nil }
return line.components(separatedBy: ",")
}
@younata
younata / concourse_deployment.yml
Last active November 8, 2016 19:55
ci.younata.com concourse manifest
---
name: concourse
director_uuid: RESULT OF bosh status --uuid
releases:
- name: concourse
version: latest
- name: garden-runc
version: latest
@younata
younata / NetworkSpec.swift
Created February 22, 2016 23:08
What Carthage/NetworkSpec.swift could have been
// I spent 2 hours working on this before I gave up. This is what I had when I declared it not worth the effort.
import Quick
import Nimble
import ReactiveCocoa
import CarthageKit
import OHHTTPStubs
class NetworkSpec: QuickSpec {
override func spec() {
@younata
younata / configuration.yml
Last active December 24, 2015 07:05
Home Assistant Configuration
homeassistant:
name: Apartment
latitude: [Redacted]
longitude: [Redacted]
temperature_unit: F
time_zone: America/Los_Angeles
customize:
scene.romantic:
friendly_name: "Romantic"
scene.lights_on:
@younata
younata / Polynomial.swift
Created October 24, 2015 04:26
Bad Self. Don't do comparisons like this.
func ==(a: Polynomial, b: Polynomial) -> Bool {
return a.description == b.description
}