Skip to content

Instantly share code, notes, and snippets.

View Jeehut's full-sized avatar

Cihat Gündüz Jeehut

View GitHub Profile
@Jeehut
Jeehut / .editorconfig
Last active October 10, 2024 09:02
This file should be added to every SwiftPM project to ensure Xcode 16+ has the same indentation settings for everyone.
# EditorConfig is awesome: https://editorconfig.org
root = true
[*]
indent_style = space
tab_width = 8
indent_size = 4
end_of_line = lf
@Jeehut
Jeehut / DurationFormat.kt
Last active August 21, 2024 15:13
Localized duration formatting in Kotlin using APIs in Android 9+ with fallback to English on Android 8 and lower.
import android.icu.text.MeasureFormat
import android.icu.text.NumberFormat
import android.icu.util.MeasureUnit
import android.os.Build
import java.util.Locale
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.days
import kotlin.time.hours
import kotlin.time.milliseconds
@Jeehut
Jeehut / lint.swift
Last active July 19, 2020 20:28
AnyLint custom check with autocorrection for [SafeLocalizedStringKey](https://gist.github.com/Jeehut/c8c9a8caf8dc7c02583a4a07dfbb37aa).
#!/usr/local/bin/swift-sh
import AnyLint // @Flinesoft
try Lint.logSummaryAndExit(arguments: CommandLine.arguments) {
// MARK: - Variables
let swiftAppFiles: Regex = #"^(Shared|iOS|macOS)/App/Sources/.*\.swift$"#
// MARK: - Checks
// MARK: SafeLocalizedStringKey
let unsafeLocalizedStringKeyTypes: String = [
@Jeehut
Jeehut / SafeLocalizedStringKey.swift
Created July 19, 2020 17:00
Exploring safer localization workflows in SwiftUI ...
// Copyright © 2020 Flinesoft. All rights reserved.
import Foundation
import SwiftUI
public struct SafeLocalizedStringKey :
ExpressibleByStringLiteral,
ExpressibleByStringInterpolation,
ExpressibleByExtendedGraphemeClusterLiteral,
ExpressibleByUnicodeScalarLiteral,
@Jeehut
Jeehut / AppPreferences.kt
Last active January 31, 2020 11:09
SharedPreferences wrapper in Kotlin: copy & paste the code into a new `AppPreferences.kt` file & follow the 4 TODO steps.
import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.content.SharedPreferences
import androidx.core.content.edit
object AppPreferences {
private var sharedPreferences: SharedPreferences? = null
// TODO step 1: call `AppPreferences.setup(applicationContext)` in your MainActivity's `onCreate` method
fun setup(context: Context) {

Resource Targets

Introduction

@Jeehut
Jeehut / Short-Xcode-Headers_Instructions.md
Last active May 10, 2019 05:41
Migrating from default Xcode headers to shortened ones.

Migrating from Default Xcode headers to shortened ones

By default, Xcode creates comments like this:

//
//  AppDelegate.swift
//  HeaderDemo
//
// Created by Cihat Gündüz on 09.05.19.
import Foundation
//: ## The Problem
// property example
let pollingInterval: TimeInterval = 5
// method example
func animate(duration: TimeInterval = 20, animations: () -> Void) {