Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View shanecowherd's full-sized avatar

Shane Cowherd shanecowherd

  • Cowherd.com, Making Blocks, PBSCO, Bulb, BombBomb, Echo1612
  • Colorado Springs
  • 02:12 (UTC -06:00)
View GitHub Profile
@shanecowherd
shanecowherd / Mac Power Usage.sh
Created January 14, 2020 05:57
This prints out the current power your laptop is pulling from the wall.
system_profiler SPPowerDataType | grep Voltage; system_profiler SPPowerDataType | grep Amper
@shanecowherd
shanecowherd / UIColorExtension.swift
Created January 14, 2020 05:30
Change color of an image. A better approach is to use vector template images.
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 May 12, 2023 15:28
Install the Unifi Controller software in a Docker container on Mac.
@shanecowherd
shanecowherd / keyboardextension.swift
Created December 30, 2019 23:23
This adds a "done" button to your keyboard toolbar.
//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:
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 December 20, 2019 21:28
A modified version of timeAgo. The native Apple one has bugs in iOS 12-13
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)
import Foundation
import UIKit
let json = """
[{
"first_name": "Shakti",
"last_name": "prakash",
"age":25,
"address":"Cuttack,Odisha,India"
},
@shanecowherd
shanecowherd / topPresentedViewController.swift
Created December 12, 2019 21:57
If you have a bunch of view controllers presented on top of each other, you can drill down the hierarchy to find the top VC.
extension UIViewController {
func topPresentedViewController() -> UIViewController? {
var topViewController: UIViewController? = self
while true {
if topViewController?.presentedViewController != nil {
topViewController = topViewController?.presentedViewController
} else {
return topViewController
}
}
@shanecowherd
shanecowherd / UpdateUIAtBreakpoint.swift
Created November 27, 2019 08:15
Update the UI if your on a breakpoint, this helps you visualize it on the device.
(lldb) expr CATransaction.flush()
// This simple command will update your UI on your device while you are at a breakpoint.
@shanecowherd
shanecowherd / SnapAnimation.swift
Created November 21, 2019 20:41
When you rotate a screen, prevent animations and just snap into place
// When you rotate a screen, prevent animations and just snap into place
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate(alongsideTransition: nil) { _ in
UIView.setAnimationsEnabled(true)
}
UIView.setAnimationsEnabled(false)
super.viewWillTransition(to: size, with: coordinator)
}