Skip to content

Instantly share code, notes, and snippets.

View bocato's full-sized avatar

Eduardo Bocato bocato

View GitHub Profile
@bocato
bocato / AnyEquatable.swift
Created April 15, 2021 03:40 — forked from pyrtsa/AnyEquatable.swift
AnyEquatable—making Equatable work with class inheritance and existential wrapping ("type erasure")
// Toggle this boolean to compare against stdlib:
#if true // Stdlib version
// Quick hack to avoid changing the AnyEquatable implementation below.
extension Equatable { typealias EqualSelf = Self }
#else // Modified version
protocol Equatable {
@bocato
bocato / CustomMatcher.swift
Created January 5, 2020 21:40 — forked from AliSoftware/CustomMatcher.swift
Add custom pattern matching to make your switch statements magical
struct CustomMatcher<Value> {
let closure: (Value) -> Bool
static func ~= (caseValue: CustomMatcher<Value>, switchValue: Value) -> Bool {
caseValue.closure(switchValue)
}
static func ~= (caseValue: Value, switchValue: CustomMatcher<Value>) -> Bool {
switchValue.closure(caseValue)
}
}
@bocato
bocato / ios_header_remover.swift
Created October 3, 2019 04:14 — forked from rockbruno/ios_header_remover.swift
iOS File Header remover script
import Foundation
func findFiles(rootPath: String, suffix: String, ignoreDirs: Bool = true) -> [String]? {
var result = [String]()
let fileManager = FileManager.default
if let paths = fileManager.subpaths(atPath: rootPath) {
let swiftPaths = paths.filter { $0.hasSuffix(suffix) }
for path in swiftPaths {
var isDir : ObjCBool = false
let fullPath = (rootPath as NSString).appendingPathComponent(path)
@bocato
bocato / XCTExpectation.swift
Created August 8, 2019 20:56 — forked from ole/XCTExpectation.swift
A variant of XCTKVOExpectation that works with native Swift key paths. To try it out, paste the code into an Xcode playground and observe the unit test output in the console. See my blog post at https://oleb.net/blog/2018/02/xctkvoexpectation-swift-keypaths/
import XCTest
/// An expectation that is fulfilled when a Key Value Observing (KVO) condition
/// is met. It's variant of `XCTKVOExpectation` with support for native Swift
/// key paths.
final class KVOExpectation: XCTestExpectation {
private var kvoToken: NSKeyValueObservation?
/// Creates an expectation that is fulfilled when a KVO change causes the
/// specified key path of the observed object to have an expected value.

How to Download iOS Simulator (Xcode) in Command Line and Install it

For faster connection speed and more flexibility.

Steps

  1. Start Xcode in command line by running this in commandline /Applications/Xcode.app/Contents/MacOS/Xcode
  2. Start downloading of the simulator
  3. Cancel it. YES CANCEL IT!
  4. You will get a message like this:
@bocato
bocato / icloud-reminders-as-text.js
Created March 7, 2016 14:09 — forked from duncansmart/icloud-reminders-as-text.js
Get iCloud Reminders as text
[].map.call(document.querySelectorAll('iframe[name=reminders]')[0].contentDocument.querySelectorAll('.reminder-not-completed-view .reminder-row .reminder-title'), function(el) {
return el.textContent;
}).join('\r\n');