Skip to content

Instantly share code, notes, and snippets.

View acrookston's full-sized avatar
👨‍💻
Coding!

Andrew Crookston acrookston

👨‍💻
Coding!
View GitHub Profile
@acrookston
acrookston / proc_cpu_pid
Last active May 24, 2023 21:59
Munin plugin to track CPU usage from specific processes based on process id's
#!/bin/sh
#
# Extended 2015 by Andrew Crookston <andrew@caoos.com> to use pidfiles instead of process names
# Original (c) 2010, Andrew Johnstone andrew @ajohnstone.com
# Based on the 'proc_mem' plugin, written by Rodrigo Sieiro rsieiro @gmail.com
#
# Configure it by using the pidfiles env. Format: name:pidfile name:pidfile. e.g.:
#
# [proc_cpu_pid]
# env.pidfiles munin-node:/var/run/munin/munin-node.pid
@acrookston
acrookston / adb-all
Last active March 3, 2023 07:00
Script to execute an adb command on all connected devices. eg: adb-all uninstall com.example.test
#!/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 April 7, 2022 20:00
Munin plugin for monitoring memory usage based on process id's
#!/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
#
@acrookston
acrookston / README.md
Last active January 26, 2022 11:05
Xcode pre-action to build custom Info.plist

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.

@acrookston
acrookston / NSRegularExpression.swift
Last active April 5, 2021 06:50
trim, strip and split, regex for Swift String
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 / ImageZoom.swift
Created January 14, 2015 19:12
Swift image zoom
// 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 / draft.swift
Last active January 23, 2019 21:01
Exploring view/controller state with Loading / Content / Error (LCE)
/// 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 January 10, 2019 18:14
Apple Notes to Evernote migration import/export script
# 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