Skip to content

Instantly share code, notes, and snippets.

Avatar

Shane Cowherd shanecowherd

View GitHub Profile
View Operation.swift
class AsyncOperation: Operation {
var completion: () -> Void
init(completion: @escaping () -> Void) {
self.completion = completion
}
override func main() {
let waitForFinish = DispatchGroup()
waitForFinish.enter()
@shanecowherd
shanecowherd / SwizzleWKWebviewPopupKeyboard.txt
Created Jul 2, 2020
OBCJ Swizzle to pop up a keyboard in WKWebview
View SwizzleWKWebviewPopupKeyboard.txt
If you need to programatically open the keyboard in a WKWebview, use this ObjC Swizzle.
https://stackoverflow.com/questions/32449870/programmatically-focus-on-a-form-in-a-webview-wkwebview/48623286#48623286
@shanecowherd
shanecowherd / logMilestone.swift
Created Jan 31, 2020 — forked from atomicbird/logMilestone.swift
Sometimes you just want to print a message that tells you a line of code was executed. Inspired by a tweet from Paige Sun: https://twitter.com/_PaigeSun/status/1161132108875796480
View logMilestone.swift
/// Log the current filename and function, with an optional extra message. Call this with no arguments to simply print the current file and function. Log messages will include an Emoji selected from a list in the function, based on the hash of the filename, to make it easier to see which file a message comes from.
/// - Parameter message: Optional message to include
/// - file: Don't use; Swift will fill in the file name
/// - function: Don't use, Swift will fill in the function name
/// - line: Don't use, Swift will fill in the line number
func logMilestone(_ message: String? = nil, file: String = #file, function: String = #function, line: Int = #line) -> Void {
#if DEBUG
// Feel free to change the list of Emojis, but don't make it shorter, because a longer list is better.
let logEmojis = ["😀","😎","😱","😈","👺","👽","👾","🤖","🎃","👍","👁","🧠","🎒","🧤","🐶","🐱","🐭","🐹","🦊","🐻","🐨","🐵","🦄","🦋","🌈","🔥","💥","⭐️","🍉","🥝","🌽","🍔","🍿","🎹","🎁","❤️","🧡","💛","💚","💙","💜","🔔"]
let logEmoji = logEmojis[abs(
View heicExpressConverter.md

Docker installation instructions

docker run --name heicconverter -v ~/Desktop/heicconverter:/root/heicconverter -p 8080:3000 -it ubuntu /bin/bash

Now you should be inside a docker container, run the following commends

cd ~/heicconverter
apt update; apt install nodejs npm libheif-examples -y
@shanecowherd
shanecowherd / Mac Power Usage.sh
Created Jan 14, 2020
This prints out the current power your laptop is pulling from the wall.
View Mac Power Usage.sh
system_profiler SPPowerDataType | grep Voltage; system_profiler SPPowerDataType | grep Amper
@shanecowherd
shanecowherd / UIColorExtension.swift
Created Jan 14, 2020
Change color of an image. A better approach is to use vector template images.
View UIColorExtension.swift
extension UIColor {
/// Change the color of a template image
/// Used in interface elements and icons
/// - Parameter tintColor: UIColor to tint
func imageWithColor(tintColor: UIColor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)
tintColor.setFill()
let context = UIGraphicsGetCurrentContext()
context?.translateBy(x: 0, y: self.size.height)
@shanecowherd
shanecowherd / Unifi Controller Docker.md
Last active Jan 6, 2020
Install the Unifi Controller software in a Docker container on Mac.
View Unifi Controller Docker.md
@shanecowherd
shanecowherd / keyboardextension.swift
Created Dec 30, 2019
This adds a "done" button to your keyboard toolbar.
View keyboardextension.swift
//Modified from:
//http://swiftquickstart.blogspot.com/2016/10/adding-done-button-to-keyboard.html
extension UITextField {
func addKeyboardDoneButton() {
let keyboardToolBar = UIToolbar()
keyboardToolBar.sizeToFit()
let flexibleSpace = UIBarButtonItem(barButtonSystemItem:
UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem(barButtonSystemItem:
View Awesomeswift resources.txt
Medium post with a ton of resources
https://medium.com/swlh/5-tools-to-speed-up-your-app-development-6979d0e49e34
Repo full of awesome swift projects
https://github.com/vsouza/awesome-ios
Cool UIKit designs
https://www.invisionapp.com/inside-design/design-resources/now/
https://www.invisionapp.com/inside-design/design-resources/tethr/
https://www.sketchappsources.com/free-source/attachment-1722-phoenix-ui-kit-sketch-freebie-resource-img2.html
@shanecowherd
shanecowherd / timeago.swift
Last active Dec 20, 2019
A modified version of timeAgo. The native Apple one has bugs in iOS 12-13
View timeago.swift
extension Date {
func timeAgoSinceDate() -> String {
// From Time
let fromDate = self
// To Time
let toDate = Date()
let time = Calendar.current.dateComponents([.month, .day, .hour, .minute, .second], from: fromDate, to: toDate)
You can’t perform that action at this time.