Skip to content

Instantly share code, notes, and snippets.

View stevethomp's full-sized avatar

Steven Thompson stevethomp

  • Senior Mobile Developer at @Shopify
  • Ottawa, Canada
View GitHub Profile
@stevethomp
stevethomp / AssertUnwrap.swift
Last active August 26, 2019 12:17
An AssertUnwrap method for use in Xcode 10, inspired by Xcode 11's `XCTUnwrap`
import XCTest
/// Attempts to unwrap an optional, failing the test if the value is nil. Your test method needs to be marked as `throws` to use this, and unwrap with:
/// `let value = try AssertUnwrap(optionalValue)`
///
/// Inspired by the upcoming `XCTUnwrap()` in Xcode 11.
///
/// - Parameters:
/// - value: Optional to unwrap
/// - message: If you want to override the default error message
@stevethomp
stevethomp / dangerfile.ts
Last active August 8, 2018 16:09
Dangerfile
import { danger, warn, fail, markdown, message } from "danger";
import jiraIssue from "danger-plugin-jira-issue";
import { readFileSync } from "fs";
/*
Danger will post all these fail/warn/message's as a comment on the PR, from the jenkins user. Over time, as commits are added, the comment is amended.
No comment means you're all good and the PR passes these checks.
Check out http://danger.systems/js/ for how this all works, and http://danger.systems/js/guides/the_dangerfile.html for creating more rules.
*/
@stevethomp
stevethomp / History|-106d534d|entries.json
Last active May 4, 2023 11:55
Visual Studio Code Settings Sync Gist
{"version":1,"resource":"file:///Users/steven/src/github.com/Shopify/arrive-client/src/features/account/views/AccountDeletionView.tsx","entries":[{"id":"vhvm.tsx","source":"searchReplace.source","timestamp":1653671308343}]}
@stevethomp
stevethomp / DynamicTypeResponsive.swift
Last active June 7, 2019 00:19
Adds a simple way to register a view for automatic dynamic type updating by setting respondsToDynamicTypeChanges = true. Really only useful on iOS < 10
import UIKit
import ObjectiveC
// MARK: - DynamicTypeResponsive
protocol DynamicTypeResponsive {
var respondsToDynamicTypeChanges: Bool { get set }
}
extension UILabel: DynamicTypeResponsive {
var respondsToDynamicTypeChanges: Bool {
@stevethomp
stevethomp / CollectionViewHelpers.swift
Last active October 5, 2016 17:29
Simplifies the UITableView cell methods that are called all the time, and does away with annoying force unwraps in ViewControllers.
import UIKit
public extension UICollectionView {
public func register<T: UICollectionViewCell>(type: T.Type) {
registerNib(T.Nib, forCellWithReuseIdentifier: T.Identifier)
}
public func cell<T: UICollectionViewCell>(forIndexPath indexPath: NSIndexPath) -> T {
return dequeueReusableCellWithReuseIdentifier(T.Identifier, forIndexPath: indexPath) as! T
}
@stevethomp
stevethomp / Xcode project open script
Last active August 29, 2015 14:08
Launch your Xcode project quickly, defaulting first to the workspace file for Cocoapods
// Save as ~/Documents/.../OpenXcodeProject.sh
#!/bin/bash
if [ -e *.xcworkspace ]; then
open *.xcworkspace
echo 'Found a workspace file, opening'
elif [ -e *.xcodeproj ];
then open *.xcodeproj
echo 'found xcodeproj, opening'
else echo 'Found nothing!'
fi
return YES;