Skip to content

Instantly share code, notes, and snippets.

👨‍💻
Coding!

Andrew Crookston acrookston

👨‍💻
Coding!
Block or report user

Report or block acrookston

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
@acrookston
acrookston / README.md
Last active Oct 19, 2019
Xcode pre-action to build custom Info.plist
View README.md

Automatic build versions from git in Xcode (and other goodies)

Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.

1. Xcode Scheme pre-action

Edit Xcode Scheme and add a pre-action script. Copy the contents of preaction.sh into the pre-action script box.

View ImageZoom.swift
// The image is originally animated on to the view controller then added to the scroll view.
// So, there might be some animation residue in here.
// Class needs: <UIScrollViewDelegate>
func viewDidLoad() {
let width = UIScreen.mainScreen().bounds.size.width
let aspect: CGFloat = width / shotWidth
var frame = CGRectMake(0, 0, shotWidth * aspect, shotHeight * aspect)
self.scrollView = UIScrollView(frame: frame)
@acrookston
acrookston / NSRegularExpression.swift
Last active Apr 27, 2019
trim, strip and split, regex for Swift String
View NSRegularExpression.swift
extension NSRegularExpression {
convenience init(substrings: [String], options: NSRegularExpression.Options) throws {
let escapedSubstrings: [String] = substrings.map(NSRegularExpression.escapedTemplate)
let pattern: String = escapedSubstrings.joined(separator: "|")
try self.init(pattern: pattern, options: options)
}
convenience init?(with pattern: String, options: NSRegularExpression.Options = []) {
do {
try self.init(pattern: pattern, options: options)
@acrookston
acrookston / draft.swift
Last active Jan 23, 2019
Exploring view/controller state with Loading / Content / Error (LCE)
View draft.swift
/// ContentLoader is a lightweight state manager for loading and displaying content and/or errors.
/// It allows you to repeatedly make requests and display new content or cached content in the event of an error.
/// Commonly known as RemoteData or LCE (Loading / Content / Error).
/// Inspired by https://tech.instacart.com/lce-modeling-data-loading-in-rxjava-b798ac98d80
///
final class ContentLoader<T> {
init() { }
@discardableResult func loader(_ loader: (() -> Void)?) -> ContentLoader<T> {
self.loader = loader
@acrookston
acrookston / notes migration.scpt
Created Jan 10, 2019
Apple Notes to Evernote migration import/export script
View notes migration.scpt
# Thanks to: https://medium.com/doraoutloud/migrating-your-apple-notes-to-evernote-12114418ba00
# Open "Script Editor" application, paste and run.
tell application "Notes"
set theMessages to every note
repeat with thisMessage in theMessages
set myTitle to the name of thisMessage
@acrookston
acrookston / adb-all
Last active Aug 25, 2018
Script to execute an adb command on all connected devices. eg: adb-all uninstall com.example.test
View adb-all
#!/bin/bash
DEVICES=`adb devices | tail -n +2 | cut -f1`
for DEVICE in $DEVICES
do
RUN="adb -s $DEVICE $@"
echo $RUN
${RUN}
done
@acrookston
acrookston / proc_mem_pid
Last active Jun 28, 2018
Munin plugin for monitoring memory usage based on process id's
View proc_mem_pid
#!/bin/sh
#
# (c) 2015, Andrew Crookston <andrew@caoos.com>
# Licence: GPLv2
#
# Configure it by using the pidfiles env. Format: name:pidfile name:pidfile. e.g.:
#
# [proc_mem_pid]
# env.pidfiles munin-node:/var/run/munin/munin-node.pid
#
View String+Extensions.swift
extension String {
func localized(_ args: CVarArg...) -> String {
return String(format: NSLocalizedString(self, comment: ""), arguments: args)
}
}
let format = NSLocalizedString("Hello %@", comment: "")
print(String(format: format, "World"))
You can’t perform that action at this time.