Skip to content

Instantly share code, notes, and snippets.

View d-date's full-sized avatar
🏠
Working from home

Daiki Matsudate d-date

🏠
Working from home
View GitHub Profile
enum CreditCardBrand: String {
enum Pattern {
static let visa = #"^4[0-9]{12}(?:[0-9]{3})?"#
static let master = #"^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$"#
static let amex = #"^3[47][0-9]{13}$"#
static let diners = #"^3(?:0[0-5]|[68][0-9])[0-9]{11,13}$"#
static let discover = #"^6(?:011|5[0-9]{2})[0-9]{12}$"#
static let jcb = #"^(?:2131|1800|35\d{3})\d{7}"#
}
import SwiftUI
public struct DatePickerTextField: View {
/// Config
var components: DatePicker.Components
@Binding var date: Date
var formattedString: (Date) -> String
/// View properties
@State private var viewID: String = UUID().uuidString
@FocusState private var isActive
@d-date
d-date / BundleCurrent.swift
Created April 22, 2023 09:10
Workaround for previewing SwiftPM resources
// Workaround for Bundle resource when running on Xcode previews
// https://forums.swift.org/t/xcode-previews-swiftpm-resources-xcpreviewagent-crashed/51680/10
// https://developer.apple.com/forums/thread/664295?answerId=673644022#673644022
// https://gist.github.com/ctreffs/ad9d23e08d586cf75e4d1c3bb1b1061f
import class Foundation.Bundle
import class Foundation.ProcessInfo
private class BundleFinder {}
import Foundation
struct EmailAddress: RawRepresentable, Codable {
let rawValue: String
init?(rawValue: String) {
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let range = NSRange(rawValue.startIndex..<rawValue.endIndex,in: rawValue)
let matches = detector?.matches(in: rawValue, options: [], range: range)
guard let match = matches?.first, matches?.count == 1 else { return nil }
@d-date
d-date / CoreSpotlight.swift
Last active December 14, 2020 06:02
Core Spotlight
import CoreSpotlight
import Foundation
#if canImport(UniformTypeIdentifiers)
import UniformTypeIdentifiers
#endif
import MobileCoreServices
struct ShopIndexHandler {
static let `default` : ShopIndexHandler = .init()
import Combine
import UIKit
public protocol CombineCompatible {}
// MARK: - UIControl
public extension UIControl {
final class Subscription<SubscriberType: Subscriber, Control: UIControl>: Combine.Subscription where SubscriberType.Input == Control {
private var subscriber: SubscriberType?
private let input: Control
import UIKit
import ImageIO
extension UIImage {
public static func gifImage(data: Data) -> UIImage? {
guard let source = CGImageSourceCreateWithData(data as CFData, nil) else {
print("image doesn't exist")
return nil
}
@d-date
d-date / project.yml
Last active March 17, 2024 21:17
XcodeGen Example
name: XXXX
attributes:
LastUpgradeCheck: 1140
ORGANIZATIONNAME: "kankak, Inc."
options:
bundleIdPrefix: com.xxxx.xxxxxxxx
deploymentTarget:
iOS: 13.1.3
configs:
Develop Debug: debug
import Foundation
let intJson = #"{ "inUse": 1, "name": "Daiki Matsudate", "twitter": "d_date", "stars": 99999, "occupation": null}"#
let boolJson = #"{ "inUse": true, "name": "Daiki Matsudate", "twitter": "d_date", "stars": 99999, "occupation": null}"#
protocol Inherits {
associatedtype SuperType
var `super`: SuperType { get }
}
let of = Observable.of(1,2,3)
.do(onNext: { print($0) })
let just = Observable.just(4)
.do(onNext: { print($0) })
let error = Observable<Any?>.error(FakeError())
.do(onError: { print($0) })
Observable.zip(of, just, error)
.subscribe()
.disposed(by: disposeBag)