Skip to content

Instantly share code, notes, and snippets.

View dan-hart's full-sized avatar
🎵
Listening to music

Dan Hart dan-hart

🎵
Listening to music
View GitHub Profile
@dan-hart
dan-hart / View+onFirstAppear.swift
Last active September 2, 2025 20:56
SwiftUI Extension to add a state listener that only runs on first appear
public extension View {
func onFirstAppear(_ action: @escaping () -> ()) -> some View {
modifier(FirstAppear(action: action))
}
}
private struct FirstAppear: ViewModifier {
let action: () -> ()
// Use this to only fire your block one time
@dan-hart
dan-hart / GeometryReaderAlternative.swift
Created August 21, 2025 23:31
GeometryReader alternative called onGeometryChanged
import SwiftUI
struct ContentView: View {
@State private var contentHeight: CGFloat = 0
@State private var showsSheet = false
@State private var fontSize: CGFloat = 50
var body: some View {
VStack(spacing: 20) {
Text("onGeometryChange example")
{
config,
pkgs,
...
}: {
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
];
echo "
alias ls='ls -la'
alias update='sudo apt update'
alias c='clear'
alias n='nano'
alias py='python3'
alias s='sudo'
" >> ~/.bashrc && source ~/.bashrc
# Blocklist by @codedbydan
adtago.s3.amazonaws.com
analyticsengine.s3.amazonaws.com
analytics.s3.amazonaws.com
advice-ads.s3.amazonaws.com
advertising-api-eu.amazon.com
ads30.adcolony.com
adc3-launch.adcolony.com
events3alt.adcolony.com
@dan-hart
dan-hart / venmo.py.python
Created January 16, 2024 04:14
get transactions from a specific user on venmo
from venmo_api import Client
# Authentication (replace with your credentials)
access_token = "ACCESS_TOKEN_HERE"
# get user id from user input
user_id = input("Enter user id: ")
# Initialize API client
client = Client(access_token=access_token)
@dan-hart
dan-hart / View+embedInNavigationView.swift
Created December 29, 2023 21:28
embed a view inside of a navigation view
import SwiftUI
extension View {
/// Embeds the view in a `NavigationView`
///
/// **Example**
/// ```
/// NavigationView {
/// ~this view~
/// }
@dan-hart
dan-hart / Show-xcode-build-time.sh
Created January 27, 2023 15:07
terminal command to show the time of build in the Xcode toolbar
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
@dan-hart
dan-hart / one-line-install-and-run-swift.sh
Last active January 3, 2023 21:33
Install swift-sh, run a script that builds a swift file, download the file, make it executable, then run it with "Hello" as the script name
brew install swift-sh; curl https://raw.githubusercontent.com/dan-hart/sh/main/createSwiftScript.sh?token=GHSAT0AAAAAAB246YAPWKNBL5CIDXU52WJEY5UT4ZA > createSwiftScript.sh; chmod +x createSwiftScript.sh; sh createSwiftScript.sh Hello
@dan-hart
dan-hart / turn-off-power-led-raspberry-pi.sh
Created May 26, 2022 21:49
Turn off the power led (led1) on a raspberry pi, change this to led0 to turn off the "activity" led
echo 0 | sudo tee /sys/class/leds/led1/brightness > /dev/null