Skip to content

Instantly share code, notes, and snippets.

View amine2233's full-sized avatar

Amine Bensalah amine2233

View GitHub Profile
@kylebshr
kylebshr / VaporSignInWithAppleJWT.swift
Last active October 22, 2024 03:01
Verifying a Sign in with Apple JWT in Vapor 3
/*
Once you've signed in with Apple in your iOS app, turn the `identityToken` into a string with something like
`String(data: identityToken, encoding: .utf8)`. Then use that string in the Authorization header:
`urlRequest.addValue("Bearer \(identityString)", forHTTPHeaderField: "Authorization")`
*/
import Vapor
import JWT
@themightychris
themightychris / Dockerfile
Created September 24, 2019 22:55
nginx + PHP composite Docker container
#
# Multi-Stage Docker build:
# Laravel 5.8 + PHP73 + Postgres || MySQL
#
# @link https://laravel.com/docs/5.8
# @link https://hub.docker.com/_/php
# @link https://hub.docker.com/_/mysql
# @link https://hub.docker.com/_/postgres
#
@freak4pc
freak4pc / Combine+WithLatestFrom.swift
Last active November 25, 2024 05:58
withLatestFrom for Apple's Combine
//
// Combine+WithLatestFrom.swift
//
// Created by Shai Mishali on 29/08/2019.
// Copyright © 2019 Shai Mishali. All rights reserved.
//
import Combine
// MARK: - Operator methods
import Combine
struct ZipMany<Element, Failure>: Publisher where Failure: Error {
typealias Output = [Element]
private let underlying: AnyPublisher<Output, Failure>
init<T: Publisher>(publishers: [T]) where T.Output == Element, T.Failure == Failure {
let zipped: AnyPublisher<[T.Output], T.Failure>? = publishers.reduce(nil) { result, publisher in
if let result = result {
/// Similar to a `Binding`, but this is also observable/dynamic.
@propertyDelegate
@dynamicMemberLookup
final class Derived<A>: BindableObject {
let didChange = PassthroughSubject<A, Never>()
fileprivate var cancellables: [AnyCancellable] = []
private let get: () -> (A)
private let mutate: ((inout A) -> ()) -> ()
init(get: @escaping () -> A, mutate: @escaping ((inout A) -> ()) -> ()) {
self.get = get
@n8chur
n8chur / Published.swift
Last active March 2, 2022 06:41
An example implementation of @published from Swift's Combine framework along with an "immutable" variant.
import Combine
/**
An observable, mutable property.
Replays the current value when subscribed.
*/
@propertyWrapper
struct Published<Output>: Publisher {
typealias Failure = Never
@AliSoftware
AliSoftware / Bindings.swift
Last active March 26, 2025 12:10
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@marcprux
marcprux / SFSymbols.swift
Created June 6, 2019 01:27
All the SFSymbol images as extensions of UIImage & NSImage
#if os(macOS)
import AppKit
public typealias UXImage = NSImage
#elseif os(iOS)
import UIKit
public typealias UXImage = UIImage
#endif
/// Extensions for system images included in SF Symbols
@available(macOS 10.15, iOS 13.0, *)
@stevestreza
stevestreza / DispatchQueueScheduler.swift
Last active June 29, 2023 13:06
A basic implementation of a Scheduler for Combine. Probably not a great implementation. Useful only as a toy, do not ship this.
//
// DispatchQueueScheduler.swift
//
import Combine
import Foundation
// DO NOT USE THIS IN PRODUCTION
struct DispatchQueueScheduler: Scheduler {
let queue: DispatchQueue