Skip to content

Instantly share code, notes, and snippets.

Avatar

Rachel Brindle younata

View GitHub Profile
View FakeCall.swift
import Combine
class FakeCall<T> {
private(set) var calls = [T]()
func record(_ arguments: T) {
calls.append(arguments)
}
func reset() {
@younata
younata / layouthelpers.swift
Created Dec 19, 2020
UIView Autolayout Helpers
View layouthelpers.swift
import UIKit
extension UIView {
func removeAllSubviews() {
for view in self.subviews {
view.removeFromSuperview()
}
}
@discardableResult
@younata
younata / BadCSVParser.swift
Created Oct 7, 2018
Bad CSV Parser in swift
View BadCSVParser.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 Nov 8, 2016
ci.younata.com concourse manifest
View concourse_deployment.yml
---
name: concourse
director_uuid: RESULT OF bosh status --uuid
releases:
- name: concourse
version: latest
- name: garden-runc
version: latest
@younata
younata / NetworkSpec.swift
Created Feb 22, 2016
What Carthage/NetworkSpec.swift could have been
View NetworkSpec.swift
// 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 Dec 24, 2015
Home Assistant Configuration
View configuration.yml
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 Oct 24, 2015
Bad Self. Don't do comparisons like this.
View Polynomial.swift
func ==(a: Polynomial, b: Polynomial) -> Bool {
return a.description == b.description
}
View gist:9a540801f45341659b66
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'
View gist:c1c6fa2df0762e056afa
syntax on
set tabstop=2
set expandtab
set shiftwidth=2
let mapleader = ","
nnoremap / /\v
vnoremap / /\v
View gist:54cb2165359d4c413edd
import MathKit
let p = SimplePolynomial(string: "3x^2 + x + 1")
let p2 = SimplePolynomial(string: "(x)(y)")
let p3 = SimplePolynomial(string: "thisIsOneLongVariable^2")
p + p2 // returns 3x^2 + x + (x)(y) + 1
p - p2 // returns 3x^2 + x - (x)(y) + 1
p * p2 // don't feel like figuring that one out.