Skip to content

Instantly share code, notes, and snippets.

View SergLam's full-sized avatar
😊
Try to make your code better!

Serhii Liamtsev SergLam

😊
Try to make your code better!
View GitHub Profile
@SergLam
SergLam / HiddenMacOSDebuggingPanel.md
Created April 18, 2024 09:37 — forked from usagimaru/HiddenMacOSDebuggingPanel.md
Enables useful debugging panel in macOS apps

Use _NS_4445425547 or NS🐞 for enables debuggging panel. When enabled it, a ladybug 🐞 menu appears in the app menu bar.

“4445425547” means DEBUG in Unicode table.

0x44=D
0x45=E
0x42=B
0x55=U
0x47=G

@SergLam
SergLam / SwiftUIDoubleClickModifier.swift
Created March 11, 2024 12:02 — forked from joelekstrom/SwiftUIDoubleClickModifier.swift
A view modifier that can reliably detect double clicks on macOS, even in List
extension View {
/// Adds a double click handler this view (macOS only)
///
/// Example
/// ```
/// Text("Hello")
/// .onDoubleClick { print("Double click detected") }
/// ```
/// - Parameters:
/// - handler: Block invoked when a double click is detected
@SergLam
SergLam / Generics+Utilities.swift
Created November 9, 2023 09:13 — forked from edc0der/Generics+Utilities.swift
Get class name without namespace in Swift
func className(target: AnyObject) -> String {
let nameSpaceClassName = NSStringFromClass(type(of: target))
if let className = nameSpaceClassName.components(separatedBy: ".").last {
return className
}
return ""
}
@SergLam
SergLam / AsyncURLSessionTask.swift
Last active September 29, 2023 17:48
Async-await URLSesionTask API wrapper.
// TODO: - Change raw completion handlers once Swift issue is resolved.
// https://github.com/apple/swift/issues/60488
public typealias DataTaskCompletion = (Data?, URLResponse?, Error?) -> Void
public typealias DownloadTaskCompletion = (URL?, URLResponse?, Error?) -> Void
/// async-await URLSessionTask wrapper with `cancel` and `suspend` functionality.
public class AsyncURLSessionTask: Identifiable {
enum State {
case ready
@SergLam
SergLam / UserDefaults+Codable.swift
Created May 24, 2023 08:51
UserDefaults+Codable - handy extension for Codable models storing in UserDefaults
import Foundation
private let jsonDecoder: JSONDecoder = {
let decoder = JSONDecoder()
if #available(iOS 10.0, *) {
decoder.dateDecodingStrategy = JSONDecoder.DateDecodingStrategy.iso8601
}
return decoder
}()
@SergLam
SergLam / Animate-Border-Width-And-Color.m
Last active May 31, 2022 17:51
UIView animation with CABasicAnimation - border width and color
static const CGFloat kCornerRadiusStateNormal = 20.0f;
static const CGFloat kCornerRadiusStateSelected = 40.0f;
static const CGFloat kBorderWidth = 3.0f;
// First variant, long and ugly
- (void)updateStateAnimated:(BOOL)animated {
if (animated) {
CAMediaTimingFunction* timing =[[CAMediaTimingFunction alloc] initWithControlPoints:0.2f:0.0f:0.0f:1.0f];
@SergLam
SergLam / SampleTableViewCell.swift
Created April 25, 2022 18:20
SwiftUI Previews for UIKit
import UIKit
final class SampleTableViewCell: UITableViewCell {
static let cellHeight: CGFloat = 60.0
static let reuseIdentifier: String = String(describing: SampleTableViewCell.self)
private let nameLabel: UILabel = UILabel()
@SergLam
SergLam / UIImageView+ImageLoading.swift
Created April 21, 2022 19:03
Swift Extension for iOS: Load image from URL + set to an UIImageView
import UIKit
extension UIImageView {
func downloadImage(from url: URL) {
URLSession.shared.dataTask(with: url) { data, response, error in
guard
let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
let mimeType = response?.mimeType, mimeType.hasPrefix("image"),
let data = data, error == nil,
@SergLam
SergLam / CertificatePinningURLSessionDelegate.swift
Created February 19, 2022 13:14
Certificate and Public Key Pinning for URLSession using Swift
// Based on https://code.tutsplus.com/articles/securing-communications-on-ios--cms-28529
import Foundation
import Security
struct Certificate {
let certificate: SecCertificate
let data: Data
}
extension Certificate {
@SergLam
SergLam / MockDataConstants.swift
Last active October 21, 2024 14:13
Mock Data URLs - links to audio, video and image files
import Foundation
struct MockDataConstants {
// MARK: - Image files
static let imageUrls: [String] = [
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg",
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/ElephantsDream.jpg",
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/ForBiggerBlazes.jpg",
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/ForBiggerEscapes.jpg",