Skip to content

Instantly share code, notes, and snippets.

View markbattistella's full-sized avatar
🐢
code. code. code

Mark Battistella markbattistella

🐢
code. code. code
View GitHub Profile
@markbattistella
markbattistella / TagLayout.swift
Created February 24, 2026 21:44
A custom layout that arranges subviews in multiple rows, wrapping items to a new row when the current row exceeds the available width. Works like a tag or flow layout.
/// A custom layout that arranges subviews in multiple rows, wrapping items to a new row when the
/// current row exceeds the available width. Works like a tag or flow layout.
struct TagLayout: Layout {
/// Controls how subviews are horizontally distributed within each row.
indirect enum RowAlignment {
case leading
case center
case trailing
@markbattistella
markbattistella / fix_tags.sh
Created February 20, 2026 23:54
Fixes zero-padded tags (e.g. 26.02.07 → 26.2.7) across affected repos. Requires: gh (GitHub CLI), authenticated via `gh auth login`
#!/bin/bash
# Fixes zero-padded tags (e.g. 26.02.07 → 26.2.7) across affected repos.
# Requires: gh (GitHub CLI), authenticated via `gh auth login`
# ── Configuration ────────────────────────────────────────────────────────────
OWNER="your-github-username"
REPOS=(
"repo-name-1"
"repo-name-2"
)
@markbattistella
markbattistella / scan_tags.sh
Created February 20, 2026 23:52
Scans all repos for a given GitHub user and finds tags with zero-padded month or day segments. Outputs a ready-to-run fix_tags.sh if any are found. Requires: gh (GitHub CLI), authenticated via `gh auth login`
#!/bin/bash
# Scans all repos for a given GitHub user and finds tags with zero-padded
# month or day segments. Outputs a ready-to-run fix_tags.sh if any are found.
# Requires: gh (GitHub CLI), authenticated via `gh auth login`
# ── Configuration ────────────────────────────────────────────────────────────
TARGET_USER="${1:-}"
# ─────────────────────────────────────────────────────────────────────────────
if [ -z "$TARGET_USER" ]; then
@markbattistella
markbattistella / ScrollHeaderToolbar.swift
Last active June 15, 2025 20:08
SwiftUI Scroll-Responsive Header and Toolbar
//
// ScrollHeaderToolbar.swift
// Author: Mark Battistella
// Website: https://markbattistella.com
//
//
// Purpose:
// This SwiftUI implementation provides a dynamic navigation interface where a large navigation
// title, along with additional UI elements like buttons, transitions into a smaller inline
// navigation title as the user scrolls. This mimics the behaviour found in Apple’s first-party
@markbattistella
markbattistella / PlatformCheck.swift
Created February 19, 2024 23:27
A Swift Utility for OS Environment Checks
//
// Author: Mark Battistella
// Website: https://markbattistella.com
//
#if os(iOS)
import UIKit
#else
import Foundation
#endif
@markbattistella
markbattistella / auto-increment.sh
Created December 27, 2023 05:32
Auto-increment Xcode project number
#!/bin/sh
#
# auto-increment.sh
# Author: Mark Battistella
# Website: https://markbattistella.com
#
# get the path for the config file
CONFIG_FILE="${PROJECT_DIR}/Shared/Data/Config.xcconfig"
@markbattistella
markbattistella / youtubeEmbed
Created November 11, 2023 23:49
Open Youtube in new window
javascript:(function(){
if(window.location.host === 'www.youtube.com' && window.location.pathname === '/watch'){
var videoId = window.location.search.split('v=')[1];
var ampersandPosition = videoId.indexOf('&');
if(ampersandPosition != -1) {
videoId = videoId.substring(0, ampersandPosition);
}
var embedUrl = 'https://www.youtube.com/embed/' + videoId;
window.open(embedUrl, 'youtube', 'width=1920,height=1080');
}
@markbattistella
markbattistella / IDETemplateMacros.plist
Created September 1, 2023 06:30
Template for IDETemplateMacros.plist when creating Xcode projects
<?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>FILEHEADER</key>
<string>
// Project: ___PROJECTNAME___
// Author: ___FULLUSERNAME___
// Website: ___WEBSITE___
//
final class CoreDataManager {
// -- singleton initalisation
static let shared = CoreDataManager()
var container: NSPersistentContainer
// -- managed object context
var managedObjectContext: NSManagedObjectContext {
container.viewContext
@markbattistella
markbattistella / GetSize.swift
Last active October 28, 2022 23:22
Retrieve the size of an element within SwiftUI
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ContentView: View {
@State var hStackSize: CGSize = .zero
var body: some View {