Skip to content

Instantly share code, notes, and snippets.

Avatar

Grant Davis gdavis

View GitHub Profile
@gdavis
gdavis / disable-mouse-accel.markdown
Created Jul 3, 2022
Disable Mouse Scaling on macOS via Terminal
View disable-mouse-accel.markdown

Adopted from: https://techinfluence.net/turn-off-mouse-acceleration-on-mac/#Method_2_Turn_Off_Mouse_Acceleration_Using_the_Terminal

Check the current value of scaling in user defaults:

~ defaults read .GlobalPreferences com.apple.mouse.scaling

This will display a hidden preference setting that you can change by altering the number at the end. If the mouse acceleration feature is enabled, the above command should display a value between 0 and 3. This is the value that is altered when you move the ‘Tracking Speed’ slider

Disable mouse acceleration:

@gdavis
gdavis / SkeletonGradientAnimationView.swift
Created Mar 18, 2022
Animated Gradient view with overlay to be used as a "skeleton" view in the Mimir app
View SkeletonGradientAnimationView.swift
//
// SkeletonGradientAnimationView.swift
// Mimir
//
// Created by Grant Davis on 3/18/22.
// Copyright © 2022 Grant Davis Interactive, LLC. All rights reserved.
//
import Foundation
import SwiftUI
@gdavis
gdavis / increment_target_build_number.rb
Last active Feb 23, 2022
Custom lane for fastlane to increment the build number for a single target in the project file.
View increment_target_build_number.rb
### --------------------------------------------------------------------------------------------------
#
# The code below has been adotped and modified from https://stackoverflow.com/a/68022221/189292
# This allows the project to increment build numbers on a per-target basis, instead of updating the entire
# project for all targets when using the standard `increment_build_number` lane.
#
### --------------------------------------------------------------------------------------------------
# Sets the "BUILD" number for a target
#
@gdavis
gdavis / swift-concurrency.markdown
Last active Jan 2, 2022
Notes about usage of Swift Concurrency
View swift-concurrency.markdown

Swift Concurrency

Video: Meet async/await in Swift

With Swift concurrency, functions, initializers, read-only properties, and for-loops can all be marked async. Property getters can also throw.

func fetchThumbnails() await throws -> [UIImage] {
}

extension UIImage {
@gdavis
gdavis / xcode-vim.markdown
Last active Aug 11, 2022
Notes for working with Xcode VIM mode
View xcode-vim.markdown

Xcode VIM

This document is a scratchpad for helping me learn commonly used actions in Xcode's VIM mode.

Commands are case-sensitive. A command of N means pressing shift + n on the keyboard.

[Formatting is a WIP]


Normal Mode Commands

Basic Navigation

@gdavis
gdavis / ThreadSafe.swift
Last active Dec 6, 2021
ThreadSafe is a property wrapper that can be used to control atomic access to the underlying property while allowing concurrent access to reading the value.
View ThreadSafe.swift
//
// ThreadSafe.swift
// GDICore
//
// Created by Grant Davis on 1/2/21.
// Updated to support `_modify` accessor on 12/5/21.
//
// Copyright © 2021 Grant Davis Interactive, LLC. All rights reserved.
//
import Foundation
@gdavis
gdavis / Twilight.xccolortheme
Created Jul 19, 2021
Twilight – A Custom Xcode Theme
View Twilight.xccolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 1 1 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SFMono-Semibold - 13.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 1 1 1</string>
@gdavis
gdavis / swiftui-state.markdown
Last active Mar 17, 2021
Swift UI State Management
View swiftui-state.markdown

Swift UI State Management

Storing state for Child View Models

SwiftUI is all about state, and maintaining that state can be rather difficult when you have more than a few properties stored as @State for your view. It is common practice to use a view model to store the state outside of the view, since our views are constantly recreated as our state changes. Keeping what state you want in memory can provide a challenge, much more so than it may seem at first glance.

With SwiftUI 2, using @StateObject will keep a view model from being recreated with each rendering of a view's body. If the parent view is creating the view model, and then passing that down to the child view, that view model will also be recreated with each rendering of that parent view body.

struct ParentView: View {
  var body: some View {
@gdavis
gdavis / assignNoRetain.swift
Created Feb 10, 2021
Combine assign method without the memory leak
View assignNoRetain.swift
extension Publisher where Self.Failure == Never {
public func assignNoRetain<Root>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable where Root: AnyObject {
sink { [weak object] (value) in
object?[keyPath: keyPath] = value
}
}
}