Skip to content

Instantly share code, notes, and snippets.

View mackoj's full-sized avatar
🤓
Neerding & Parenting

Jeffrey Macko mackoj

🤓
Neerding & Parenting
View GitHub Profile
@mackoj
mackoj / PrefixUntil.swift
Last active June 29, 2022 09:17
This an operator for the swift-parsing library that add a parser that consumes a subsequence from the beginning of its input up to a given parser succeed.
import Foundation
import Parsing
/// A parser that consumes a subsequence from the beginning of its input up to a given parser succeed.
///
/// This parser behave a lot like `PrefixUpTo` but it can be slower because it can use a parser instead of
/// a static string and consume and return input up to a particular parser succeed.
///
/// If provided with a string that correspond to the begining of the parser it will be almost as fast as `PrefixUpTo` in most cases. The only case where it will be slow when providing a string is when there is a lot of false positive aka pattern that look like what the parser should valid but are not valid.
///
@mackoj
mackoj / PublisherToAsync.swift
Created October 4, 2022 09:09
This convert your Combine base code to Async/Await
import Fopundation
import Combine
extension AnyPublisher {
func async<NewOutput>(_ transform: @escaping (Output) throws -> NewOutput) async throws -> NewOutput {
try await withCheckedThrowingContinuation { continuation in
var cancellable: AnyCancellable?
cancellable = first()
.sink { result in
switch result {
@mackoj
mackoj / Codable+URL.swift
Last active October 19, 2022 21:15
This add the ability to use URL when decoding JSON directly in the model
import Foundation
// public struct Model: Codable {
// public let test: URL?
// public let test2: URL
// ...
// }
// ⚠️ This is not a universal solution tho in orfer to handle properlu fileURL URL should be init with `URL(fileURLWithPath:)` instead of URL(string:)
@mackoj
mackoj / sdkExterneEtApiTierces.md
Created February 20, 2023 23:54 — forked from ThibaultFighieraPJ/sdkExterneEtApiTierces.md
Intégration de SDKs Externes et Api Tierce Android

SDK Externe et API Tierces

Objectif : Lister ce à quoi les SDK externes et API tierces doivent se conformer avant d'être intégrés dans l'application Android PagesJaunes.

Veuillez forker ce gist et mettre un ✅ devant les cases vous concernant. Renvoyez-nous le lien de votre document par email avec l'explication de ce que vous ne faites pas et pourquoi ? 🙂

Documentation

  • En ligne
    • Publique
  • Accès restreint

Playground

https://www.swift-linux.com/sextant/

Syntax

Depending on the client used JSONPath expressions do start with $. indicating the root element. Some clients omit the leading $..

$.store.book[0].title

@mackoj
mackoj / SDKExterneEtAPITierces.md
Last active June 19, 2023 13:48 — forked from icPJmobile/iOS-SDKExterneEtAPITierces.md
Lister ce à quoi les SDK externes et API tierces doivent se conformer avant d'être intégrés dans l'application iOS PagesJaunes. Le but est de ne pas limiter l'évolution de l'application si, par hasard, un SDK était mal conçu.

SDK Externe et API Tierces

Objectif : Lister ce à quoi les SDK externes et API tierces doivent se conformer avant d'être intégrés dans l'application iOS. Le but est de ne pas limiter l'évolution de l'application si, par hasard, un SDK était mal conçu.

Veuillez forker ce gist et mettre un ✅ devant ce que vous faites. Renvoyez nous son lien par mail avec l'explication de ce que vous ne faites pas et pourquoi ? 🙂

Besoin

  • On doit pouvoir influer sur les évolutions possibles du SDK afin qu'il puisse évoluer avec nous si besoin.
  • On doit avoir un contact technique direct (et non pas un quelqu'un du support commercial 😉). Cette personne doit avoir la possibilité d'influer sur l'évolution du SDK et nous renseigner techniquement dans un délais acceptable.
@mackoj
mackoj / Font+Autoregistering.swift
Last active December 28, 2023 07:11
This simplifies the process of loading custom fonts that are resources in an iOS Apple SPM Package (Swift Package Manager).
import Foundation
import UIKit
public typealias FontNameExt = (name: String, ext: String)
public func autoRegisteringFont(_ fontNames: [FontNameExt], _ spmBundleName : String) throws {
guard let spmBundle = Bundle(bundleName: spmBundleName) else {
throw("Fail to find bundle(\(spmBundleName).bundle) in your app bundle.")
}
try fontURLs(for: fontNames, in: spmBundle).forEach { try registerFont(from: $0) }
@mackoj
mackoj / transmute.swift
Created April 10, 2024 08:30
Force AnyCodable to change a type of an object
import Foundation
import AnyCodable
// This is Fugly but it get the job done.
extension AnyCodable {
func transmuteThrow<Output: Codable>(_ encoder: JSONEncoder = JSONEncoder(), _ decoder: JSONDecoder = JSONDecoder()) throws -> Output {
let data = try encoder.encode(self)
return try decoder.decode(Output.self, from: data)
}