Skip to content

Instantly share code, notes, and snippets.

View maxchuquimia's full-sized avatar

Max Chuquimia maxchuquimia

  • Sydney, Australia
View GitHub Profile
@maxchuquimia
maxchuquimia / import-uikit.sh
Last active January 14, 2020 05:45
Find all Swift files where you (probably) forgot to `import UIKit`. Useful for when you remove something that imports UIkit.h from your bridging header
grep -rlZE "(UI[a-zA-Z]*View|CG[A-Za-z]*)" --include "*.swift" --exclude-dir Pods . | tr '\n' '\0' | xargs -0 grep -LZ "^import UIKit"
@maxchuquimia
maxchuquimia / vscode
Created July 8, 2019 23:08
Opens VSCode with a file/workspace
#!/bin/bash
DOC="$1"
if [ -z "$DOC" ]
then
DOC="."
fi
open -a "Visual Studio Code" "$DOC"
@maxchuquimia
maxchuquimia / VIM.xccolortheme
Last active September 28, 2020 07:17
A handcrafted Xcode theme inspired by VIM
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.794852 1 0.923414 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Courier - 13.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 0.93397 0.612968 1</string>
import Foundation
// Edit this dictionary to contain every suite of mocks you need
// [targetfile : [option1, option2...]]
let mappings = [
"users-rewrite.json": [
"users.json", // Standard response
"users-empty.json", // No users available
"users-401.json", // Token expired state
"users-500.json", // Server broken state
import Foundation
import AppKit
import IOKit
import IOKit.hid
let manager = IOHIDManagerCreate(
kCFAllocatorDefault,
IOOptionBits(kIOHIDOptionsTypeNone)
)
@maxchuquimia
maxchuquimia / runscript.sh
Created April 28, 2018 07:51
Demo of using Swift in a Run Script phase in Xcode
#!/bin/bash
CONFIG_PASSWORD="BE5D2905-0625-4EBF-BCA2-7F6F5D138425"
REQUIRED_CONFIG_FILE_PATH="${SRCROOT}/YourProject/App/Config/Configurations/Config-${CONFIGURATION}.plist"
CONFIG_OUTPUT_PATH="${SRCROOT}/YourProject/App/Config/Configurations/Config.json"
CONFIG_EXTENSION_OUTPUT_PATH="${SRCROOT}/YourProject/App/Config/Configurations/Config+Extension.swift"
set -e
if [ -z "${CONFIGURATION}" ]
@maxchuquimia
maxchuquimia / compile-time.sh
Last active March 17, 2018 23:24
Track how much time you spend waiting for you Swift project to compile over the day
#!/bin/bash
# Start this in the morning when you get to work
# Control+C to kill it before you leave
# The time spent is printed on the screen
# Use it to make a case for a faster laptop!
INTERVAL=5
COMPILE_TIME=0
@maxchuquimia
maxchuquimia / Realm+CascadeDelete.swift
Created September 17, 2017 22:52
Cascade deleting with RealmSwift, and optionally respecting to-many references
// An example of iterating through an `Object`'s properties and deleting them
// Logging has been left for clarity
// Objects conforming to `DefersDeletionDuringCascade` can decide whether they should be deleted or not
// Not fully tested, but works so far!
import Foundation
import RealmSwift
fileprivate func log(_ s: String, level: Int) {
// This levelled logging is super useful
@maxchuquimia
maxchuquimia / ColorCombine.swift
Created August 23, 2017 05:37
Overlays a transparent colour on an opaque colour to produce an opaque colour
extension UIColor {
private var components: (CGFloat, CGFloat, CGFloat, CGFloat)? {
var r: CGFloat = 0.0
var g: CGFloat = 0.0
var b: CGFloat = 0.0
var a: CGFloat = 0.0
guard getRed(&r, green: &g, blue: &b, alpha: &a) else { return nil }
@maxchuquimia
maxchuquimia / Example.swift
Created June 8, 2017 00:10
Paging a UICollectionView when each cell is smaller than the width of the collection
// Set the inset so that the first and last cells can appear in the middle of the UICollectionView
override func layoutSubviews() {
super.layoutSubviews()
contentInset = UIEdgeInsets(top: 0, left: frame.width / 2.0 - layout.itemSize.width / 2.0, bottom: 0, right: 0)
}
private func currentCentredCell() -> UICollectionViewCell? {
return visibleCells.reduce(visibleCells.first) { (nearestCell, nextCell) -> UICollectionViewCell? in