Skip to content

Instantly share code, notes, and snippets.

View zarghol's full-sized avatar
🙂

Clément Nonn zarghol

🙂
View GitHub Profile
@zarghol
zarghol / gist:3c0f29bdbe7a6317536bf0a8c76a7380
Created June 8, 2021 22:58
Experiment with new SwiftUI Canvas View
import SwiftUI
enum TrigonometricFunction: CaseIterable {
case sinus
case cosinus
func apply(_ value: Double) -> Double {
switch self {
case .cosinus:
return cos(value)
@zarghol
zarghol / PublisherCatchAndExit.swift
Created May 9, 2020 19:43
custom publisher to avoid handling error in the sink
extension Publisher {
func catchAndExit(_ completion: @escaping (Self.Failure) -> Void) -> AnyPublisher<Self.Output, Never> {
return self
.map { output -> Optional<Output> in output }
.catch { error -> Just<Optional<Output>> in
completion(error)
return Just(nil)
}
.filter { $0 != nil }
@zarghol
zarghol / combine+delegate.swift
Created November 25, 2019 12:30
Combine+Pattern Delegate
import Foundation
import Combine
import CoreLocation
extension Subscriber {
func eraseToAnySubscriber() -> AnySubscriber<Self.Input, Self.Failure> {
return AnySubscriber<Input, Failure>.init(receiveSubscription: { sub in
self.receive(subscription: sub)
}, receiveValue: { value in
self.receive(value)
@zarghol
zarghol / Resultify.swift
Created November 25, 2019 12:20
Resultify
enum ResultError: Error { case emptyData }
func resultify<T>(_ completion: @escaping (Result<T, Error>) -> Void) -> (T?, Error?) -> Void {
return { data, error in
if let error = error {
completion(.failure(error))
} else if let data = data {
completion(.success(data))
} else {
completion(.failure(ResultError.emptyData))
//
// BaseWebService.swift
//
import Foundation
import UIKit
public enum NetworkError: Error {
case noData
case noGoodResponse
//
// ShadowView.swift
//
import UIKit
@IBDesignable
class ShadowView: UIView {
@IBInspectable var startAlpha: CGFloat = 90 {
@zarghol
zarghol / oclint.rb
Last active October 13, 2016 08:18
brew oclint 0.11
require 'formula'
class Oclint < Formula
homepage 'http://oclint.org'
url 'https://github.com/oclint/oclint/releases/download/v0.10.3/oclint-0.10.3-x86_64-darwin-15.5.0.tar.gz'
version '0.10.3'
sha256 '533b4fdc82664a3d3dede3820fee664c71c3fba2bef4ba096a37ec9c5fc2dae5'
def install
lib.install Dir['lib/clang']