Skip to content

Instantly share code, notes, and snippets.

View dnedrow's full-sized avatar

David Nedrow dnedrow

View GitHub Profile
@dnedrow
dnedrow / leverageuserappfolder.md
Created October 1, 2025 17:17
Leveraging an Applications folder in the user's home on macOS

Leveraging a User Applications Folder on macOS

The Why

A macOS user does not necessarily have the ability to install applications in the system /Applications folder. This often is because they are not an administrator on their machine. However, they can install applications in their own user folder. This is typically /Users/<username>/Applications.

The How

If a /Users//Applications folder does not exist, the user should

@dnedrow
dnedrow / SkipIfNoCodeChanges.yml
Last active February 6, 2025 20:28
Skip GitHub Actions workflow step(s) if there are no code changes
-- https://stackoverflow.com/q/73109333
name: push
on: [push]
jobs:
list-contents:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: ls ./src/content/ > ./src/_content.txt
- run: if [[ "$(git diff --exit-code src/_content.txt)" =~ 'diff' ]]; then echo "IS_VALID=true" >> $GITHUB_ENV; else echo "IS_VALID=false" >> $GITHUB_ENV ;fi
@dnedrow
dnedrow / CustomSwiftUIViewInitWithCombine.swift
Created February 6, 2025 20:25
Custom init for a SwiftUI view that uses Combine
// https://stackoverflow.com/a/56911273
// Custom init for a SwiftUI view that uses Combine
struct CustomInput : View {
@Binding var text: String
var name: String
init(_ name: String, _ text: Binding<String>) {
self.name = name
self._text = text
@dnedrow
dnedrow / slowmotion.sh
Created October 4, 2024 16:10
Enable dock animation slow motion
#!/usr/bin/env bash
# The following command will enable slow motion for Dock animation.
# Once this command is run, just hold the SHIFT key down while minimizing
# or expanding items in the Dock.
defaults write com.apple.dock slow-motion-allowed -bool YES; killall Dock
@dnedrow
dnedrow / PreviewContainer.swift
Created February 13, 2024 22:12
Wrapper to allow UIViews to preview in SwiftUI preview pane
import Foundation
import SwiftUI
import UIKit
///
/// Wraps a UIView such that it can be shown in the SwifUI
/// preview pane.
/// Usage:
/// ```
/// struct SampleView_Previews: PreviewProvider {
@dnedrow
dnedrow / DynamicSize.swift
Created February 13, 2024 20:14
Provides View that are dynamically sized based on a base size
import SwiftUI
struct DynamicSize {
static private let baseViewWidth: CGFloat = 414.0
static private let baseViewHeight: CGFloat = 896.0
static func getHeight(_ height: CGFloat) -> CGFloat {
return (height / baseViewHeight) * UIScreen.main.bounds.height
}
@dnedrow
dnedrow / PlayFileNamed.swift
Last active December 7, 2023 21:27
Simple mechanism for playing arbitrary sound files in Swift
import Foundation
import AudioToolbox
import Foundation
import AudioToolbox
// This provides additions to SystemSoundID
extension SystemSoundID {
/// Play a sound
/// This can be handy when attached to notify on breaking constraints.
@dnedrow
dnedrow / fixrubybuild.sh
Created November 9, 2023 16:25
Solving rvm ruby build `Error running '__rvm_make -j8'` on macOS
/usr/bin/env bash
# When installing Ruby with [RVM](https://rvm.io), you may run into the
# following error:
# `Error running '__rvm_make -j8'`
# This is caused by the inability of the build to find particular libraries
# installed via [Homebrew](https://brew.sh).
#
# Just run this script before calling `rvm install`
# This solution found on [StackOverflow](https://stackoverflow.com/a/76922741/1227012)
@dnedrow
dnedrow / getsuggestedvolume.sh
Last active November 7, 2023 18:26
Returns a percentage value for use with scripts that play sounds on the Mac
#!/usr/bin/env zsh
# Usage:
# Source this and then use the function with afplay
# afplay -v $( getsuggestedvolume ) foo.wav
function getsuggestedvolume() {
(( systemVolume=$(osascript -e 'output volume of (get volume settings)') ))
(( currentVolume=`echo "scale=2; $systemVolume/100" | bc -l` ))
(( normalizedVolume=`echo "scale=2; $currentVolume/3" | bc -l` ))
@dnedrow
dnedrow / androidtools.md
Last active July 24, 2023 14:34
Solving Android tools `java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema` error

The Problem

When using new versions of Java (anything higher than 1.8), you may see the following error when attempting to use any of the SDK tools, e.g. sdkmanager...

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

Starting with Java 9, the XmlSchema library is not included in the base JDK.

To get around this, many people will resort to downgrading to JDK 1.8. This is unneccesary.