Skip to content

Instantly share code, notes, and snippets.

@janodev
janodev / Makefile
Created July 17, 2024 17:17
Makefile to generate documentation for a SPM package
#!/bin/zsh -e -o pipefail
# THIS MAKEFILE GENERATES DOCUMENTATION FOR A PACKAGE.
# It assumes that your doc file is at Sources/<PackageName>/<PackageName>.docc/<PackageName>.md
GIT_USER := YourGitHubUser
PACKAGE_NAME := $(shell basename $(CURDIR))
PACKAGE_NAME_LOWER := $(shell echo $(PACKAGE_NAME) | tr '[:upper:]' '[:lower:]')
DOCC_DIR := Sources/$(PACKAGE_NAME)/$(PACKAGE_NAME).docc
DOCC_FILE := $(DOCC_DIR)/$(PACKAGE_NAME).md
@janodev
janodev / readMachOHeader.swift
Created July 3, 2024 13:07
Reads a Mach-O header
import Foundation
import MachO.dyld
func readMachOHeader(path: String) {
guard let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
print("Failed to read file")
return
}
data.withUnsafeBytes { rawBufferPointer in
@janodev
janodev / viewtree.py
Last active June 19, 2024 21:38 — forked from avielg/viewtree.py
SwiftUI View Tree Graph
#!/opt/homebrew/bin/python3
import re
import glob
import os
import graphviz
import sys
## USAGE #########################################################################
@janodev
janodev / Testing.swift
Last active June 12, 2024 09:42
Summary of the Testing framework presented in WWDC 2024
/*
Sessions:
- Meet Swift Testing
https://www.youtube.com/watch?v=WFnkNcvLnCI
- Go further with Swift Testing
https://www.youtube.com/watch?v=bOvWGHi-BxI
There are three assertions that replace all XCTAssert functions:
@janodev
janodev / subtitles.sh
Created February 20, 2023 22:09
Generating Spanish subtitles for a bunch of mp4 files on a folder (works for any language)
# install mac whisper
brew install python3 ffmpeg
pip install setuptools-rust
pip install -U openai-whisper
# create a script to extract audio and translate
for f in *.mp4; do FILE=`basename -s '.mp4' "$f"`; echo ffmpeg -i "\"$f\"" -vn -acodec copy "\"$FILE.aac\"" >> script.sh; done
for f in *.mp4; do FILE=`basename -s '.mp4' "$f"`; echo whisper "\"$FILE.aac\"" --language Spanish --model medium --task transcribe >> script.sh; done
# run the script. on M1 max this is several times slower than the audio being translated
@janodev
janodev / HideBackButtonTitleModifier.swift
Created December 25, 2022 18:29
Custom modifier to hide the back button title.
import SwiftUI
/// Custom modifier to hide the back button title.
/// From https://stackoverflow.com/a/62854805/412916
/// Usage: `.modifier(HideBackButtonTitleModifier())`
struct HideBackButtonTitleModifier: ViewModifier {
@Environment(\.presentationMode) var presentation
@ViewBuilder @MainActor func body(content: Content) -> some View {
content
@janodev
janodev / project.yml
Created May 16, 2021 22:15
Xcodegen project
name: myproject
options:
bundleIdPrefix: com.myproject
usesTabs: false
indentWidth: 4
tabWidth: 4
createIntermediateGroups: true
deploymentTarget:
iOS: "14.5"
@janodev
janodev / SomeView.swift
Created September 29, 2020 18:08
VFL example
import UIKit
final class SomeView: LayoutView
{
let view1 = UIView()
let view2 = UIView()
let view3 = UIView()
override func layout() {
super.layout()
@janodev
janodev / ioslocaleidentifiers.csv
Created November 8, 2019 00:44 — forked from jacobbubu/ioslocaleidentifiers.csv
iOS Locale Identifiers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)