Skip to content

Instantly share code, notes, and snippets.

View younata's full-sized avatar

Rachel Brindle younata

View GitHub Profile
@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
}
class Foo: NSObject {
var obj: NSObject? = nil
}
func createObjectOfType(type: NSObject.self) -> Foo {
let obj = type()
if obj.respondsToSelector("obj") {
obj.setValue(NSObject(), forKey: "obj") // never gets called
}
//obj.setValue(NSObject(), forKey: "obj") // Exceptions if you don't call it with 'Foo.self'
syntax on
set tabstop=2
set expandtab
set shiftwidth=2
let mapleader = ","
nnoremap / /\v
vnoremap / /\v