Skip to content

Instantly share code, notes, and snippets.

🏔

Andrew McKnight armcknight

🏔
Block or report user

Report or block armcknight

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@armcknight
armcknight / Podfile-configurable_devpod_declaration.rb
Last active Apr 20, 2018
The declaration included in my app Podfiles that allows either installing by release or by devpod without hand-editing or dirtying the Podfile's git status, for when I want to add to Pippin.
View Podfile-configurable_devpod_declaration.rb
target 'SomeApp' do
if !ENV['PIPPIN_PATH'].blank? then
pod 'Pippin', :path => ENV['PIPPIN_PATH']
else
pod 'Pippin'
end
end
@armcknight
armcknight / Rakefile-release_task.rb
Last active Apr 20, 2018
A rake task to release a cocoapod spec and record the version information to git.
View Rakefile-release_task.rb
desc 'Create git tags and push them to remote, push podspec to CocoaPods.'
task :release do
version = `vrsn --read --file #{version_file}`
sh "git tag #{version.strip}"
sh 'git push --tags'
sh 'pod trunk push'
end
@armcknight
armcknight / Rakefile-bump_task.rb
Last active Apr 20, 2018
Bumping versions in iOS apps and their repositories from the command line
View Rakefile-bump_task.rb
desc 'Bump version number and commit the changes with message as the output from vrsn. Can supply argument to bump one of: major, minor, patch or build. E.g., `rake bump[major]` or `rake bump[build]`.'
task :bump,[:component] do |t, args|
require 'open3'
modified_file_count, stderr, status = Open3.capture3("git status --porcelain | egrep '^(M| M)' | wc -l")
if modified_file_count.to_i > 0 then
sh "git stash --all"
end
component = args[:component]
@armcknight
armcknight / returning-nonoptional-collections-and-throwing.swift
Created May 19, 2017
In model/business logic returning collections, returning nonoptional collection types simplifies consumer logic, and throwing errors clearly communicates failure modes.
View returning-nonoptional-collections-and-throwing.swift
func modelLayerFunction() throws -> [Any] { /* ... */ }
func controllerFunction() throws -> [Any] {
let models = try modelLayerFunction()
// ...
return models
}
do {
let results = try controllerFunction()
@armcknight
armcknight / returning-nil-collections.swift
Created May 19, 2017
In model/business logic returning collections, returning nil adds complexity to consumer logic.
View returning-nil-collections.swift
func modelLayerFunction() -> [Any]? { /* ... */ }
func controllerFunction() -> [Any]? {
guard let models = modelLayerFunction() else {
// log error and/or show alert?
return nil
}
// ...
return models
}
@armcknight
armcknight / throwing-errors.swift
Last active May 19, 2017
Throwing an error in swift.
View throwing-errors.swift
class AnObject {
func resultOfWork() throws -> Any {/* ... */}
}
func doSomeWork() throws -> Any {
let result = try anObjectInstance.resultOfWork()
// ...
return result
}
@armcknight
armcknight / nil-as-error.swift
Last active May 19, 2017
Using an optional return type and returning nil to signify a failure.
View nil-as-error.swift
class AnObject {
func resultOfWork() -> Any? {/* ... */}
}
func doSomeWork() -> Any? {
guard let result = anObjectInstance.resultOfWork() else {
// log and/or show error alert here?
return nil
}
// ...
@armcknight
armcknight / bashorg_into_say_macos.sh
Last active May 19, 2017 — forked from triangletodd/bashorg_cowsay.sh
Retrieve a random quote from bash.org and pipe into macOS' say command. Probs not NSFW.
View bashorg_into_say_macos.sh
curl -s http://bash.org/?random1 \
| grep -oE "<p class=\"quote\">.*</p>.*</p>" \
| grep -oE "<p class=\"qt.*?</p>" \
| sed -e 's/<\/p>/\n/g' -e 's/<p class=\"qt\">//g' -e 's/<p class=\"qt\">//g' \
| perl -ne 'use HTML::Entities;print decode_entities($_),"\n"' \
| head -1 \
| say
@armcknight
armcknight / method-signature-with-block-typedef.h
Created Apr 3, 2017
Example of an Objective C method signature containing a block with an encapsulated type.
View method-signature-with-block-typedef.h
typedef void(^__nullable MyBlockType)(NSObject *__nullable a, NSObject *__nullable b, NSObject *__nullable c);
@interface MyClass
- (void)someMethodWithInput:(NSObject *__nonnull)input completion:(MyBlockType)completion;
@end
@armcknight
armcknight / method-signature-block-literal-antipattern.h
Last active Apr 3, 2017
Example of an Objective C method signature with a block parameter defined in literal syntax.
View method-signature-block-literal-antipattern.h
@interface MyClass
- (void)someMethodWithInput:(NSObject *__nonnull)input completion:(void(^__nullable)(NSObject *__nullable a, NSObject *__nullable b, NSObject *__nullable c))completion;
@end
You can’t perform that action at this time.