Skip to content

Instantly share code, notes, and snippets.

View dnedrow's full-sized avatar

David Nedrow dnedrow

View GitHub Profile
@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.

@dnedrow
dnedrow / Fastlane-spaceship-itc_team.md
Created June 22, 2023 16:48
Get ITC_TEAM_ID value from AppStore Connect using Fastlane

You may need to know the ITC_TEAM_ID, particularly when setting up automatic deployments to TestFlight in your CI/CD pipeline.

One way to do this is to use a Fastlane Spaceship playground.

I assume if you're reading this, you already have Fastlane installed.

To start a playground, run the following command in a terminal session:

fastlane spaceship
@dnedrow
dnedrow / remove-subs.md
Created April 19, 2023 20:33
How to remove git submodules completely
  1. Remove any references to the submodule in your project
  2. Delete the relevant section from the .gitmodules file
  3. Stage the .gitmodules changes: git add .gitmodules
  4. Delete the submodule reference in .git/config
  5. Run git rm --cached path_to_submodule
  6. Run rm -rf .git/modules/path_to_submodule
  7. Run rm -rf path_to_submodule
  8. Finally, git commit -m "Removed submodule "
@dnedrow
dnedrow / palindrome.swift
Created February 1, 2023 01:45
Check for palindrome in Swift (case sensitive)
func palindrome(inputString: String) -> Bool {
return inputString == String(inputString.reversed())
}
@dnedrow
dnedrow / century.swift
Created February 1, 2023 01:39
Simple way to get century in Swift
func century(year: Int) -> Int {
return (year%100)==0 ? (year / 100) : (year / 100 + 1)
}