Skip to content

Instantly share code, notes, and snippets.

View juliengdt's full-sized avatar
🎯
Focusing

juliengdt juliengdt

🎯
Focusing
View GitHub Profile
@juliengdt
juliengdt / xcconfig.md
Created November 27, 2020 09:25
a brief intro to xcconfig inclusion

XCConfig

  • Le client s'appelle DOE
  • Les environnements possibles sont dev et release

Configuration principale pour le projet:

@juliengdt
juliengdt / Dowit.swift
Last active November 19, 2020 09:10
Do ! Or how to 'clean up' code when using `Dispatch.main`+ weak pointer
import Foundation
/// #Do class - Or how to transform DispatchQueue-escaping-weakable stuff on pointer into a more readable usage
/// TL;DR - Usage
// In ViewModel/Interactor
Do.bg(on: self) { this in
this.doSomeWSCalls()
let otherTableau: Array<(Int, String)> = [(1,"a"),(2,"b"),(3,"c"),(4,"d")]
let mean = otherTableau.map { tuple -> Int in
return tuple.0
}
/*
On peut aussi écrire le map de mean de cette facon, pour raccourcir l'écriture
"$0" est "le premier argument"
@juliengdt
juliengdt / Numeric+Normalization.swift
Created July 4, 2019 14:52
Put any numeral between two intervals, exactly like a numeric compass [0° <-> 360°] behavior.
extension Numeric where Self: Comparable /* NORMALIZER */ {
/// normalize the current value between a min and a max interval, by adding optionaly a value. this works just like the compass normalization. for Ex, 357°, by adding +4 became 1° for [0 - 360] interval
///
/// - Parameters:
/// - value: the value to add
/// - min: the minimum interval
/// - max: the maximum interval
/// - Returns: the new, transformed and normalized value
@juliengdt
juliengdt / gist:aa0554bc32d1f34c1f247e1b140115f1
Created May 24, 2019 13:29
UIImage+BrightnessExtensions.swift
extension CGImage {
var brightness: Double {
get {
let imageData = self.dataProvider?.data
let ptr = CFDataGetBytePtr(imageData)
var x = 0
var result: Double = 0
for _ in 0..<self.height {
for _ in 0..<self.width {
let r = ptr![0]
enum Restaurant: RawRepresentable {
typealias RawValue = Array<Int>
case toto
case tata
var rawValue: Array<Int> {
switch self {
case .tata:
@juliengdt
juliengdt / Routing+Repositioning.swift
Last active March 29, 2019 13:16
Swift side of the "repositioning-in-routing-request" (protocol is Android interface)
/// **From App to SDK(system)**
///
/// Give informations thanks to user interaction
/// Called by the app, when user interacts about routing or location stuff
///
/// `[App].call(sdkSystemDatasource.function(params))`
protocol PositionHelperDatasource {
/// Call this datasourced-function when a routing or a re-position is asked by the user
@juliengdt
juliengdt / GridLayout.swift
Created January 29, 2019 13:45
GridLayout
/**
* Copyright (c) 2017 Razeware LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@juliengdt
juliengdt / NSObject_Extensions.swift
Created March 21, 2018 16:11
Because NSObject KV setter sucks by default
extension NSObject {
private enum SetValuableErrorType: Error, CustomStringConvertible {
case unknown(key: String, type: NSObject)
var description: String {
switch self {
case .unknown(key: let k, type: let t):
return "Unknown parameters \(k) for object typped \(String(describing:t))"
}
import Foundation
import Result
import RxSwift
enum ResponseErrorType: Error, CustomStringConvertible {
case technical
case notFound
case other(message: Array<String>)