Skip to content

Instantly share code, notes, and snippets.

View eldaroid's full-sized avatar
🎯
Focusing

Попов Эльдар eldaroid

🎯
Focusing
View GitHub Profile
extension FocusedValues {
var myKey: Binding<String>? {
get { self[MyFocusKey.self] }
set { self[MyFocusKey.self] = newValue }
}
struct MyFocusKey: FocusedValueKey {
typealias Value = Binding<String>
}
}
@eldaroid
eldaroid / View+ConditionModifiers.swift
Last active October 7, 2024 19:01
RU: Этот код расширяет протокол View в SwiftUI, предоставляя методы для условного применения модификаторов к представлениям на основе булевых и опциональных значений. EN: This code extends the View protocol in SwiftUI, providing methods for conditionally applying modifiers to views based on boolean and optional values
import SwiftUI
// Extension to handle boolean conditions
extension View {
@ViewBuilder
public func `if`<Transform: View>(
_ value: Bool,
transform: (Self) -> Transform
) -> some View {
if value {
@eldaroid
eldaroid / DynamicTextColoring.swift
Last active October 7, 2024 19:00
RU: Динамическое окрашивание текста: 1) Встроенным текстовым стилированием; 2) AttributedString EN: Dynamic text colorization: 1) Built-in text styling; 2) AttributedString
struct DynamicTextColoring: View {
var body: some View {
VStack {
// только с 16 оси
Text("1) Коллеги и платформа \(Text("поздравляют Вас").foregroundColor(.teal))!")
Text(attributedCongratulationString)
}
}
@eldaroid
eldaroid / LogSizes.swift
Last active October 7, 2024 19:00
RU: Инструмент для отладки UI в SwiftUI, позволяя более детально контролировать и понимать процесс вычисления размеров и размещения представлений. EN: A tool for debugging UIs in SwiftUI, allowing for more detailed control and understanding of the process of calculating view sizing and placement
struct LogSizes: Layout {
var label: String
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
assert(subviews.count == 1)
print(String(format: "предлагают _%@_: →%.2f x ↓%.2f", label, proposal.width ?? 0, proposal.height ?? 0))
let result = subviews[0].sizeThatFits(proposal)
print(String(format: "ответ от _%@_: →%.2f x ↓%.2f", label, result.width, result.height))
return result
}
@eldaroid
eldaroid / repeatingTasks.sh
Last active October 13, 2024 04:00
RU: Скрипт на Bash создаёт копии указанного markdown-файла задачи, обновляя в них дату с заданной периодичностью (неделя, месяц или год) на несколько лет вперёд. EN: The Bash script creates copies of the specified markdown file of a task, updating the date in them with a specified periodicity (week, month or year) for several years ahead
#!/bin/bash
# Проверка наличия аргументов
if [ $# -eq 0 ]; then
echo "Неправильное использование скрипта. Корректный формат: ./repeat.sh --task task.md --every week|month|year"
exit 1
fi
# Проверка первых двух аргументов
if [ -z "$1" ] || [ -z "$2" ]; then