Skip to content

Instantly share code, notes, and snippets.

View alfian0's full-sized avatar
🎯
Focusing

Muhammad Alfiansyah alfian0

🎯
Focusing
View GitHub Profile
final class PublicKeyPinner {
/// Stored public key hashes
private let hashes: [String]
public init(hashes: [String]) {
self.hashes = hashes
}
/// ASN1 header for our public key to re-create the subject public key info
private let rsa2048Asn1Header: [UInt8] = [
@alfian0
alfian0 / authorization_interceptor.dart
Created August 30, 2022 00:11 — forked from TimurMukhortov/authorization_interceptor.dart
Dio authorization Interceptor with QueuedInterceptorsWrapper
class AuthorizationInterceptor extends QueuedInterceptorsWrapper {
final TokenRepository _tokenRepository;
final AuthorizationRepository _authorizationRepository;
final RefreshTokenRepository _refreshTokenRepository;
AuthorizationInterceptor({
required TokenRepository tokenRepository,
required AuthorizationRepository authorizationRepository,
required RefreshTokenRepository refreshTokenRepository,
}) : _tokenRepository = tokenRepository,
//
// UIDevice+Extension.swift
// Networking
//
// Created by alpiopio on 05/10/20.
// Copyright © 2020 alfian0. All rights reserved.
//
import UIKit
extension UIView {
public func snapshotImage(bgColor: UIColor? = nil, rect: CGRect? = nil, state: Bool = false) -> UIImage? {
var definedRect = CGRect.zero
if let rect = rect {
definedRect = rect
} else {
definedRect = self.bounds
}
UIGraphicsBeginImageContextWithOptions(definedRect.size, false, UIScreen.main.scale)
guard let graphicContext = UIGraphicsGetCurrentContext() else {
@IBDesignable
open class CheckBox: UIControl {
///Used to choose the style for the Checkbox
public enum Style {
/// ■
case square
/// ●
case circle
/// x
import UIKit
@IBDesignable
class DoubleSlider: UIControl {
@IBInspectable
var minimumValue: CGFloat = 0 {
didSet {
updateLayerFrames()
}
}
@IBDesignable class Badge: UILabel {
@IBInspectable var topInset: CGFloat = 5.0
@IBInspectable var bottomInset: CGFloat = 5.0
@IBInspectable var leftInset: CGFloat = 7.0
@IBInspectable var rightInset: CGFloat = 7.0
@IBInspectable var round: CGFloat = 7.0 {
didSet {
layer.cornerRadius = round
clipsToBounds = true
}
import UIKit
class GenericPickerView<T>: UIPickerView, UIPickerViewDataSource, UIPickerViewDelegate {
var items: [T] = [] {
didSet {
reloadAllComponents()
}
}
var titleForRow: ((T) -> String?)?
var selectionHandler: ((T) -> Void)?
@IBDesignable
class RatingComponent: UIControl {
@IBInspectable
var count: Int = 5 {
didSet {
ratings = []
for i in 0..<count {
let button = UIButton(type: .custom)
button.setImage(selectedImage, for: .selected)
button.setImage(unSelectedImage, for: .normal)
@objc
private func panGesture(_ sender: UIPanGestureRecognizer) {
let percentThreshold: CGFloat = 0.3
let translation = sender.translation(in: sender.view)
let verticalMovement = translation.y / sender.view!.bounds.height
let downwardMovement = fmaxf(Float(verticalMovement), 0.0)
let downwardMovementPercent = fminf(downwardMovement, 1.0)
let progress = CGFloat(downwardMovementPercent)
guard let interactor = interactor else { return }