Skip to content

Instantly share code, notes, and snippets.

View maakcode's full-sized avatar
💭
I may be slow to respond.

MaakCode maakcode

💭
I may be slow to respond.
View GitHub Profile
import KingFisher
struct KFLinkPresentationIconProvider: ImageDataProvider {
let url: URL
let cacheKey: String
init(url: URL, cacheKey: String? = nil) {
self.url = url
self.cacheKey = cacheKey ?? url.absoluteString
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
import Foundation
extension Character {
var isEmoji: Bool {
return unicodeScalars.allSatisfy { $0.properties.isEmoji }
}
}
func recentlyUsedEmoji() -> [Character]? {
#if os(iOS)
@asisadh
asisadh / AVAssetResourceLoaderDelegate+FairPlay.swift
Created July 4, 2019 09:45
FairPlay integration with Native AVPlayer Swift.
extension ViewController: AVAssetResourceLoaderDelegate{
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForRenewalOfRequestedResource renewalRequest: AVAssetResourceRenewalRequest) -> Bool {
return self.resourceLoader(resourceLoader, shouldWaitForLoadingOfRequestedResource: renewalRequest)
}
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
guard let url = loadingRequest.request.url else {
print("🔑", #function, "Unable to read the url/host data.")
loadingRequest.finishLoading(with: NSError(domain: "com.icapps.error", code: -1, userInfo: nil))
@linearhw
linearhw / Image Caching OpenSource.md
Last active December 15, 2022 06:39
이미지 캐싱 오픈소스 라이브러리에 대한 요약/정리

성능 비교하기

  • 테스트앱
  • 낮은 해상도 = 사진 크기: 10 ~ 50KB
  • 중간 해상도 = 사진 크기: 100 ~ 500KB + 5MB
  • 높은 해상도 = 사진 크기: 10 ~ 50MB
  • 기본 설정 = 설정: 메모리 100MB 디스크 150MB
  • 리사이즈 = (화면 너비 / 3)^2. iPhone 8+ 기준으로 414 pixel.

리사이즈 없이 테스트

@kishikawakatsumi
kishikawakatsumi / UIScrollView+UIPageControl.swift
Created April 29, 2018 15:21
UIScrollView + UIPageControl with RxSwift
import RxSwift
import RxCocoa
fileprivate extension Reactive where Base: UIScrollView {
fileprivate var currentPage: Observable<Int> {
return didEndDecelerating.map({
let pageWidth = self.base.frame.width
let page = floor((self.base.contentOffset.x - pageWidth / 2) / pageWidth) + 1
return Int(page)
})
@modocache
modocache / swiftc -Xfrontend -debug-time-compilation
Last active April 12, 2022 22:34
Swift compilation time debugging options and their outputs
===-------------------------------------------------------------------------===
Swift compilation
===-------------------------------------------------------------------------===
Total Execution Time: 0.0307 seconds (0.1196 wall clock)
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
0.0043 ( 39.3%) 0.0091 ( 45.6%) 0.0133 ( 43.4%) 0.0547 ( 45.7%) performSema
0.0030 ( 27.5%) 0.0070 ( 35.2%) 0.0100 ( 32.5%) 0.0437 ( 36.5%) performSema-loadStdlib
0.0011 ( 10.0%) 0.0011 ( 5.4%) 0.0022 ( 7.0%) 0.0081 ( 6.7%) performSema-parseAndCheckTypes
0.0008 ( 7.0%) 0.0009 ( 4.4%) 0.0016 ( 5.3%) 0.0067 ( 5.6%) Type checking / Semantic analysis
@tommyettinger
tommyettinger / mulberry32.c
Last active June 8, 2024 09:35
Mulberry32 PRNG
/* Written in 2017 by Tommy Ettinger (tommy.ettinger@gmail.com)
To the extent possible under law, the author has dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
#include <stdint.h>
@fousa
fousa / FairPlayer.swift
Last active June 1, 2023 12:28
Integrate HLS with FairPlay.
class FairPlayer: AVPlayer {
private let queue = DispatchQueue(label: "com.icapps.fairplay.queue")
func play(asset: AVURLAsset) {
// Set the resource loader delegate to this class. The `resourceLoader`'s delegate will be
// triggered when FairPlay handling is required.
asset.resourceLoader.setDelegate(self, queue: queue)
// Load the asset in the player.
@LeoHeo
LeoHeo / var-let-const.md
Last active July 19, 2024 11:52
javascript var, let, const 차이점

var, let, const 차이점은?

  • varfunction-scoped이고, let, constblock-scoped입니다.

  • function-scopedblock-scoped가 무슨말이냐?

var(function-scoped)

jsfiddle 참고주소