Skip to content

Instantly share code, notes, and snippets.

@janodev
janodev / diagram.mermaid
Created October 19, 2024 11:26
Housing market
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@janodev
janodev / waitForExpectation.swift
Last active November 4, 2024 21:29
waitForExpectation
import Foundation
import Testing
func waitForExpectation(
timeout: Duration,
description: String,
fileID: String = #fileID,
filePath: String = #filePath,
line: Int = #line,
column: Int = #column,
@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"