Skip to content

Instantly share code, notes, and snippets.

Avatar

Cihat Gündüz Jeehut

View GitHub Profile
@Jeehut
Jeehut / DurationFormat.kt
Last active Jan 14, 2022
Localized duration formatting in Kotlin using APIs in Android 9+ with fallback to English on Android 8 and lower.
View DurationFormat.kt
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 Jul 19, 2020
AnyLint custom check with autocorrection for [SafeLocalizedStringKey](https://gist.github.com/Jeehut/c8c9a8caf8dc7c02583a4a07dfbb37aa).
View lint.swift
#!/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 Jul 19, 2020
Exploring safer localization workflows in SwiftUI ...
View SafeLocalizedStringKey.swift
// Copyright © 2020 Flinesoft. All rights reserved.
import Foundation
import SwiftUI
public struct SafeLocalizedStringKey :
ExpressibleByStringLiteral,
ExpressibleByStringInterpolation,
ExpressibleByExtendedGraphemeClusterLiteral,
ExpressibleByUnicodeScalarLiteral,
@Jeehut
Jeehut / AppPreferences.kt
Last active Jan 31, 2020
SharedPreferences wrapper in Kotlin: copy & paste the code into a new `AppPreferences.kt` file & follow the 4 TODO steps.
View AppPreferences.kt
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) {
View SW-Resource-Targets.md

Resource Targets

Introduction

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

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.
View TimeInterval.playground
import Foundation
//: ## The Problem
// property example
let pollingInterval: TimeInterval = 5
// method example
func animate(duration: TimeInterval = 20, animations: () -> Void) {