Skip to content

Instantly share code, notes, and snippets.

View paulz's full-sized avatar
🍐
pairing is caring

Paul Zabelin paulz

🍐
pairing is caring
View GitHub Profile
@paulz
paulz / TimeIntervalParsing.swift
Last active May 15, 2021 21:29 — forked from Odie/gist:e26bc299bfc1f020e636
Parse user friendly time duration string in Swift
extension DateComponents {
subscript(unit: String) -> Int {
get {
switch unit {
case "month":
return self.month!
case "day":
return self.day!
case "hour":
return self.hour!
@paulz
paulz / open-with-app.scpt
Created June 28, 2020 07:25
Finder Service Open Application
# Open File or Folder with an application
#
# Create Automator new Quick Action workflow with these 3 actions:
# 1. Workflow receives "files or folders" in "any application
# 2. Get Specified Finder Items - used for debugging
# 3. Run Apple Script
#
# Paste script below and change Atom.app to any other appp
# Test shell script command works in terminal
# Test Automator workflow by adding items in step 2
@paulz
paulz / Breakpoints_v2.xcbkptlist
Last active March 31, 2020 08:25
Expect Exception without breaking in debugger
objc_exception_throw:
console command:
script lldb.process.Continue() if (lldb.frame.GetThread().GetName() == "skip-objc_exception_throw") else None
@paulz
paulz / ChainedResolver.swift
Created March 20, 2020 21:09
Dependency Injection For Objective C and Swift hybrid project
public struct ChainedResolver: ResolveDependency {
public func resolve<Service>(_: Service.Type, name: String?) -> Service? {
child.resolve(name: name) ?? parent.resolve(name: name)
}
let child, parent: ResolveDependency
public init(child: ResolveDependency, parent: ResolveDependency) {
self.child = child
self.parent = parent
@paulz
paulz / NameGenerator.swift
Last active March 20, 2020 04:26
Test date dependent code
public class NameGenerator: NSObject {
@Inject var now: () -> Date
public func nextName() -> String {
now().description
}
}
@paulz
paulz / .bash_profile
Created December 10, 2019 20:11
Bash aliases for Xcode developer
# Xcode Dervide Data clear
alias xdd='rm -rf /tmp/DerivedData'
# WorkSpace open
alias ws='find . -name *.xcworkspace -exec open {} \;'
@paulz
paulz / Assert.swift
Last active November 15, 2019 23:25
Make swift assert testable
let defaultAssert = {
(_ condition: @autoclosure () -> Bool,
_ message: @autoclosure () -> String,
file: StaticString,
line: UInt) in
Swift.assert(condition(), message(), file: file, line: line)
}
var evaluateAssert: (@autoclosure () -> Bool,
@autoclosure () -> String,
_ file: StaticString,
@paulz
paulz / ActionSpec.swift
Last active November 14, 2024 17:09
Make UIAction handler accessible for testing
import Quick
import Nimble
class ActionSpec: QuickSpec {
override func spec() {
describe("UIAction") {
it("should invoke handler") {
waitUntil { done in
let action = UIAction(title: "a title") { action in
done()
@paulz
paulz / frequencies.swift
Created April 29, 2019 22:17
Use uniquingKeysWith function
public func frequencies(input: [String]) -> [String: Int] {
return Dictionary(input.map {($0, 1)}, uniquingKeysWith: +)
}
@paulz
paulz / after aController.swift
Last active March 1, 2019 01:59
use functions for closures
import UIKit
import Siesta
class LoginOrSignupViewController: UIViewController {
@IBAction func logIn() {
let user = User(email: emailTextField.text!, password: passwordTextField.text!, name: nameTextField?.text)
api.login(user)
.onSuccess(weak(self, type(of: self).transitionToApp))
.onFailure(weak(self, type(of: self).showError))