Skip to content

Instantly share code, notes, and snippets.

View Jeehut's full-sized avatar

Cihat Gündüz Jeehut

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

Resource Targets

Introduction

@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) {
@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 / 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 / DurationFormat.kt
Last active October 1, 2023 14:39
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