Skip to content

Instantly share code, notes, and snippets.

import NIO
import Logging
extension EventLoopFuture {
func whenFailureLog(
level: Logger.Level = .error,
_ message: @escaping @autoclosure () -> Logger.Message,
using logger: Logger,
errorDescriptionMetadataKey: String = "reason",
metadata: @escaping @autoclosure () -> Logger.Metadata? = nil,
@iamchiwon
iamchiwon / ASAuthorizationControllerProxy.swift
Last active July 6, 2023 07:37
 Sign in with Apple + Rx
import AuthenticationServices
import RxCocoa
import RxSwift
import UIKit
@available(iOS 13.0, *)
extension ASAuthorizationController: HasDelegate {
public typealias Delegate = ASAuthorizationControllerDelegate
}
@hmmhmmhm
hmmhmmhm / sigungu.json
Last active March 7, 2025 15:59
한국의 모든 시/군/구 전국 지역 좌표 JSON 대한민국 지역 좌표 pre_rendered
{
"서울특별시/강남구": {
"lat": "37.4951",
"long": "127.06278"
},
"서울특별시/강동구": {
"lat": "37.55274",
"long": "127.14546"
},
"서울특별시/강북구": {
@chriseidhof
chriseidhof / boilerplate.swift
Last active September 27, 2025 12:39
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@fananek
fananek / Vapor4_Pivot_EagerLoading.swift
Last active January 18, 2021 22:42
Fluent - Eager load property stored in a pivot model - Vapor 4
import Fluent
import Vapor
// Todo model
final class Todo: Model, Content {
static let schema = "todos"
@ID(key: .id)
var id: UUID?
@Limwin94
Limwin94 / CollectionView.md
Last active October 20, 2020 22:17
Collection View 관계도 정리
We couldn’t find that file to show.
import FluentKit
import Vapor
final class Todo: Model, Content {
static let schema = "todos"
@iID(key: "id", .uuid, .identifier(auto: false))
var id: UUID?
@iField(key: "title", .string, .required)
@jimmychu0807
jimmychu0807 / string-conversion.rs
Created November 21, 2019 10:20
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte
@mattt
mattt / UIViewControllerPreview.swift
Last active December 3, 2024 07:42
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()
}
@MihaelIsaev
MihaelIsaev / AuthMiddleware.swift
Created August 17, 2019 20:03
Simple authorization middleware for Vapor 3.
import Vapor
import SwifQL
class AuthMiddleware: Middleware {
/// Use it on your router like this
/// ```swift
/// let protectedRoute = router.grouped(AuthMiddleware())
/// ```
func respond(to request: Request, chainingTo next: Responder) throws -> Future<Response> {
return try request.requireToken().flatMap { try next.respond(to: $0) }