Skip to content

Instantly share code, notes, and snippets.

View eldaroid's full-sized avatar
🎯
Focusing

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

🎯
Focusing
View GitHub Profile
@eldaroid
eldaroid / TagsModel.swift
Last active October 13, 2024 04:03
RU: Реализация макета Selectable Aligned Tags с поддержкой переносов строк и выравнивания. EN: Implementation Selectable Aligned Tags layout that supports line breaks and alignment
public struct TagsModel: Identifiable, Hashable, Equatable {
public let id: String
public var title: String
public var tooltip: String?
public var isSelected: Bool
public init(
id: String = UUID().uuidString,
title: String,
isSelected: Bool = false,
@eldaroid
eldaroid / Collection+Utils.swift
Last active October 7, 2024 19:04
RU: Удобный и настраиваемый способ навигации между разделами (вкладками) информации с помощью эффекта matchedGeometryEffect. EN: Convenient and customizable way to navigate between sections (tabs) of information with matchedGeometryEffect
public extension Collection {
subscript(safe index: Index) -> Element? {
indices.contains(index) ? self[index] : nil
}
}
@eldaroid
eldaroid / PingIPsRange.sh
Last active October 7, 2024 19:04
RU: Скрипт проверяет доступность IP-адресов в указанном диапазоне. Он пингует каждый IP-адрес в сети 192.168.0.x и выводит сообщение, если адрес доступен. EN: The script checks the availability of IP addresses in the specified range. It pings each IP address in the 192.168.0.x network and displays a message if the address is available
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <number_of_ips>"
exit 1
fi
if ! [[ $1 =~ ^[0-9]+$ ]] || [ $1 -lt 0 ] || [ $1 -gt 255 ]; then
echo "Error: The argument must be a number in the range from 0 to 255."
exit 1
@eldaroid
eldaroid / LifeCycleAppDelegate.swift
Last active October 7, 2024 19:03
RU: Исследуем жизненный цикл iOS приложения (методы AppDelegate). EN: Exploring the iOS app lifecycle (AppDelegate methods)
import UIKit
@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// 1 начальная настройка перед завершением запуска
func application(
_ application: UIApplication,
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
@eldaroid
eldaroid / LifeCycleSceneDelegate.swift
Last active October 7, 2024 19:03
RU: Исследуем жизненный цикл iOS Scene (методы SceneDelegate). EN: Exploring the iOS Scene lifecycle (SceneDelegate methods)
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
// Настройка окна приложения
window = UIWindow(windowScene: windowScene)
let initialViewController = ViewController()
window?.rootViewController = initialViewController
@eldaroid
eldaroid / LifeCycleViewController.swift
Last active October 7, 2024 19:02
RU: Исследуем жизненный цикл ViewController. EN: Let's study the ViewController life cycle
final class ViewController: UIViewController {
private let name = "🖥️"
private let infoLabel: UILabel = {
let label = UILabel()
label.text = "AppDelegate Life Cycle"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private let switchButton: UIButton = {
@eldaroid
eldaroid / AnimationExample.swift
Last active October 7, 2024 19:02
RU: Визуализация различных типов анимационных кривых и наблюдение их поведения: в реальном времени. EN: Visualize different types of animation curves and observe their behavior: in real time
struct AnimationExample: View {
@ObservedObject var trace = AnimationTrace()
@State var animating: Bool = false
@State var selectedAnimationIndex: Int = 0
@State var slowAnimations: Bool = false
var selectedAnimation: (String, Animation) {
return animations[selectedAnimationIndex]
}
var body: some View {
VStack {
// BlurReplace, Identity, Move, Offset,
// Opacity, Push, Scale, Slide
// Asymmetric
struct ContentView: View {
@State private var showBlurReplace = false
@State private var showIdentity = false
@State private var showMove = false
@State private var showOffset = false
@State private var showOpacity = false
@State private var showPush = false
struct DefaultPopUps: View {
@State var onSheet = false
@State var onFullScreenCover = false
@State var onPopover = false
@State var onAlert = false
@State var onActionSheet = false
var body: some View {
VStack {
Button(action: {
@eldaroid
eldaroid / DoubleHumanFormatted.swift
Last active October 7, 2024 19:01
RU: Преобразование чисел в удобочитаемый формат, добавляя соответствующие постфиксы для больших чисел (например, 123 тысяч, 5 миллионов, 8 миллиардов и т.д.). EN: Convert numbers into a readable format by adding appropriate postfixes for large numbers (e.g. 123 thousand, 5 million, 8 billion, etc.)
public extension Double {
func humanFormatted(
groupingSeparator: String = " ",
roundingMode: NumberFormatter.RoundingMode = .halfEven,
fractionDigits: Int = 1,
threshold: Double = 9_999
) -> (stringValue: String, postfix: String?) {
let dividerNames: [String?] = [nil, "тыс.", "млн", "млрд", "трлн", "квадрлн"]