Skip to content

Instantly share code, notes, and snippets.

@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 / NutritionFacts+Builder.m
Last active June 21, 2023 05:26
Objective-C Builder pattern.
@interface NutritionFacts(Builder)
-(NutritionFactsBuilder*)builder;
@end
@implementation NutritionFacts(Builder)
-(NutritionFactsBuilder*)builder {
return [[NutritionFactsBuilder alloc]initWithNutritionFacts:self];
}
@end
@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 / 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 / Optional+Extension.swift
Created February 18, 2017 10:32
Chainable closures for optional types.
import Foundation
extension Optional
{
@discardableResult
func ifSome(_ handler: (Wrapped) -> Void) -> Optional {
switch self {
case .some(let wrapped): handler(wrapped); return self
case .none: return self
}
@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 / Makefile
Last active August 5, 2020 12:48
Securing Apache with client certificate authorisation
.DEFAULT_GOAL := hello
CA = ca
CA_NAME = Janodev CA
SERVER = jano
SERVER_DOMAIN = jano.dev
CLIENT = client
CLIENT_NAME = Janodev Notes User
SERVER_CONF = server.conf
CLIENT_CONF = client.conf
@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)
@janodev
janodev / Person.m
Created May 16, 2017 14:32
Right and wrong ways to call a block property
#import <Foundation/Foundation.h>
#undef X
typedef void (^salute_t)();
@interface Person : NSObject
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) salute_t salute;