Skip to content

Instantly share code, notes, and snippets.

@justinpawela
justinpawela / actor_dl_imge.swift
Created February 29, 2024 02:51 — forked from networkextension/actor_dl_imge.swift
actor async/await download imge Swift 5.5
extension UIImage {
@available(iOS 15, *)
var thumbnail: UIImage? {
get async {
let size = CGSize(width: 80, height: 40)
return await self.byPreparingThumbnail(ofSize: size)
}
}
}
enum FetchError:Error{
@justinpawela
justinpawela / UIViewControllerPreview.swift
Created December 6, 2019 16:02 — forked from mattt/UIViewControllerPreview.swift
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()
}
@justinpawela
justinpawela / higher-order-functions.scss
Created March 13, 2017 21:15 — forked from pdaoust/higher-order-functions.scss
Higher-order functions for Sass 3.3 -- now that we've got the `call()` function in Sass, we can start to compose functions. We don't have the benefit of anonymous functions, of course, but this is real functional programming, folks!
// 'map', 'transform', 'select', or 'project' function. Iterate over a list,
// performing a function on each item, and collecting the new items. Each
// function takes an item as a first argument and returns a transformed item.
// You can pass additional arguments to the function too, which is a decent poor
// man's function composition.
// (I didn't call this f-map because the term 'map' is already used in Sass to
// denote a hash or dictionary.)
@function f-apply($func, $list, $args...) {
$new-list: ();
@each $item in $list {