Skip to content

Instantly share code, notes, and snippets.


Grant Davis gdavis

View GitHub Profile
gdavis / disable-mouse-accel.markdown
Created July 3, 2022 14:27
Disable Mouse Scaling on macOS via Terminal
View disable-mouse-accel.markdown

Adopted from:

Check the current value of scaling in user defaults:

~ defaults read .GlobalPreferences

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 / SkeletonGradientAnimationView.swift
Created March 18, 2022 21:18
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 / increment_target_build_number.rb
Last active August 31, 2022 00:45
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
# 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 / swift-concurrency.markdown
Last active January 2, 2022 19:10
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 / xcode-vim.markdown
Last active March 25, 2023 22:15
Notes for working with Xcode VIM mode
View xcode-vim.markdown

Xcode VIM

Learning VIM in Xcode comes with its own set of challenges and limitations, but there is enough there for you to give your mousing hand a break and master the keyboard.

A limited set of commands are available in Xcode, and this document attempts help ease the learning curve of using VIM in Xcode by providing a handy reference as well as what I find works for me in practice.

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

This document is a work in progress! Leave a comment if you would like to see a change.

gdavis / ThreadSafe.swift
Last active December 6, 2021 15:39
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 / Twilight.xccolortheme
Created July 19, 2021 21:21
Twilight – A Custom Xcode Theme
View Twilight.xccolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<string>1 1 1 1</string>
<string>SFMono-Semibold - 13.0</string>
<string>1 1 1 1</string>
gdavis / swiftui-state.markdown
Last active March 27, 2023 19:56
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 / assignNoRetain.swift
Created February 10, 2021 18:03
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