Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@codelynx
codelynx / NSTextField+Blurred.swift
Created March 8, 2024 21:58
NSSecureTextField alternative
//
// NSTextField+Blurred.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2024 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / Inspectables.swift
Created March 5, 2024 23:38
Inspectables helps you implementing inspector view and its model in swift
//
// Inspectable.swift
// Inspectables
//
// Created by Kaz Yoshikawa on 3/5/24.
//
//
// Overview:
// Inspectables a set of code help you implementing inspectable property values and its inspector value editing visual components, by using
// @InspectableValue, or @InspectableEnum property wrappers, then you may forcus writing property value editing components.
@codelynx
codelynx / Observable.swift
Created February 28, 2024 19:35
Observable property wrapper
// YObservable
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@codelynx
codelynx / heterogeneous-inspector-view-sample.swift
Created January 29, 2024 06:48
This code demonstrate how to make concrete inspector-like view from abstract protocol.
// Swift 5.9
//
// Following code demonstrate how to implemnt inspector-like view from abstruct protocol.
// Somehow, @Binding will not work in this case under Swift 5.9
import SwiftUI
protocol Shape {
func view() -> AnyView
@codelynx
codelynx / UnsafePointer+string.swift
Created January 17, 2024 20:28
utility extension convert UnsafePointer<UInt8> to String?
extension UnsafePointer<UInt8> {
var string: String? {
return String(validatingUTF8: UnsafeRawPointer(self).assumingMemoryBound(to: CChar.self))
}
}
// AWS-SDK-Swift
//
// When you need to find if error is caused by resource not found,rather than other type of errors
// such as network error or access permissions related error. This is how to find, if this error
// is cause of resource not found.
//
// Note:
// I don't want to spend time for this next time, so I paste code snippet here for my future reference
func processHeadRequest(s3client: S3Client, bucket: String, key: String) async throws {
@codelynx
codelynx / Data+hexadecimal.swift
Last active May 8, 2023 20:18
convert hexadecimal string to Data and/or the other way around
//
// Data+Hexadecimal.swift
//
// The MIT License (MIT)
//
// Copyright (c) 2023 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@codelynx
codelynx / UIImage+color.swift
Created March 2, 2023 05:40
UIImage extension to create 1 pixel color image
import UIKit
extension UIImage {
convenience init(color: UIColor) {
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 1, height: 1))
let image = renderer.image { context in
context.cgContext.setFillColor(UIColor.blue.cgColor)
context.cgContext.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
}
guard let cgImage = image.cgImage else { fatalError() }
@codelynx
codelynx / Error.swift
Created July 18, 2022 19:22
General purpose to make a concrete Error instance in Swift
//
// ZError.swift
// ZKit
//
// Created by Kaz Yoshikawa on 7/18/22.
//
// Usage:
// General usage for throwing Error in Swift language.
//
// Example:
@codelynx
codelynx / Array+RunLength.swift
Created July 17, 2022 19:53
encoding and decoding equatable elements from Array.
//
// Array+RunLength.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2020 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal