Skip to content

Instantly share code, notes, and snippets.

View juliengdt's full-sized avatar
🎯
Focusing

juliengdt juliengdt

🎯
Focusing
View GitHub Profile
@juliengdt
juliengdt / SwiftIntegerChecker.swift
Created August 26, 2015 07:48
To check if a number is between a range in Swift
// To check if a number is between a range, don't do
if number >=0 && number <= 100 {
}
// Use range and news operators instead :
if 0...100 ~= number {
}
@juliengdt
juliengdt / CHANGELOG.md
Last active September 5, 2023 09:27
CHANGELOG.md template

CHANGELOG.md

1.8.0 (unreleased)

Features:

  • add support for SVN sources -> 95f32s5b
  • add metadata allowed_push_host to new gem template -> 95f32s5b
  • adds a --no-install flag to bundle package -> 95f32s5b
@juliengdt
juliengdt / lowpower_mode.md
Last active August 26, 2023 18:26
Detect and make your iPhone app responds to low-power mode

Low Power Mode - LPM

With iOS 9 Apple added a Low Power Mode to the iPhone. It extends battery life by stopping some battery heavy features such as email fetch, Hey Siri and background app refresh until you can recharge the device.

It is important to understand that it is the user who decides to enter low power mode. You need to go into the battery settings to turn it on.

Detection

To detect LPM you have to be in the couple iOS 9.X / iPhone:

  • For iOS 8.X, you need test availablity before use it
@juliengdt
juliengdt / AUTHORS.md
Created August 27, 2014 07:42
AUTHORS.md template

Project Authors

This is where your explain when the project started, for which client, and list all devteams who contributes to it.

Project technical leads:

  • John Foo - position - City (Country)
  • Bar Doe - position - City (Country)
struct Throttle {
static func onQueue(queue: NSOperationQueue, by timeInterval: NSTimeInterval, function: () -> ()) {
queue.cancelAllOperations()
let delayOperation = DelayOperation(timeInterval: timeInterval)
let throttledOperation = NSBlockOperation() {
function()
}
throttledOperation.addDependency(delayOperation)
queue.addOperations([delayOperation, throttledOperation], waitUntilFinished: false)
@juliengdt
juliengdt / AlamofirePrintable.swift
Created September 1, 2016 09:24
Pretty print extension for Alamofire Request
extension Alamofire.Request {
func responseDebugPrint() -> Self {
return responseJSON() {
response in
if let JSON: AnyObject = response.result.value,
JSONData = try? NSJSONSerialization.dataWithJSONObject(JSON, options: .PrettyPrinted),
prettyString = NSString(data: JSONData, encoding: NSUTF8StringEncoding) {
print(prettyString)
} else if let error = response.result.error {
print("Error Debug Print: \(error.localizedDescription)")
@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()
@juliengdt
juliengdt / Soumission Apple Appstore - iOS.md
Last active July 28, 2020 17:10
Soumission Apple Appstore - iOS

Soumission Apple Appstore - iOS

Ce document liste toutes les informations nécessaires afin de soumettre rapidement une application iOS sur iTunesConnect pour:

  • Une nouvelle application
  • Une mise à jour d'application

Nouvelle Application

@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]