Skip to content

Instantly share code, notes, and snippets.

Julien Sagot juliensagot

Block or report user

Report or block juliensagot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@juliensagot
juliensagot / UIImage+averageColor.swift
Last active Dec 9, 2019
Get the average color of a UIImage. (Swift 4.2, Xcode 10.0)
View UIImage+averageColor.swift
import UIKit
extension UIImage {
var averageColor: UIColor? {
guard let inputImage = self.ciImage ?? CIImage(image: self) else { return nil }
guard let filter = CIFilter(name: "CIAreaAverage", parameters: [kCIInputImageKey: inputImage, kCIInputExtentKey: CIVector(extent: inputImage.extent)])
else { return nil }
guard let outputImage = filter.outputImage else { return nil }
@juliensagot
juliensagot / UIBezierPath+utils.swift
Last active May 28, 2018
Extension of UIBezierPath to create a rounded rect with different corner radius while keeping smooth corners. (Swift 4, Xcode 9.2)
View UIBezierPath+utils.swift
import UIKit
fileprivate enum PathElement {
case moveToPoint(CGPoint)
case addLineToPoint(CGPoint)
case addQuadCurveToPoint(CGPoint, CGPoint)
case addCurveToPoint(CGPoint, CGPoint, CGPoint)
case closeSubpath
}
@juliensagot
juliensagot / Async.swift
Last active Dec 15, 2017
Syntactic sugar for DispatchQueue (Swift 4, Xcode 9.2)
View Async.swift
public func background(_ block: @escaping () -> Void) {
let qos = DispatchQoS.QoSClass.default
DispatchQueue.global(qos: qos).async(execute: block)
}
public func main(_ block: @escaping () -> Void) {
DispatchQueue.main.async(execute: block)
}
public func after(milliseconds: Float, block: @escaping () -> Void) {
@juliensagot
juliensagot / UIFont+smallCaps.swift
Last active Apr 9, 2019
Get UIFont with smallCaps feature (Swift 4, Xcode 9.2)
View UIFont+smallCaps.swift
extension UIFont {
var withSmallCaps: UIFont {
let upperCaseFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kUpperCaseType,
UIFontDescriptor.FeatureKey.typeIdentifier : kUpperCaseSmallCapsSelector
]
let lowerCaseFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kLowerCaseType,
UIFontDescriptor.FeatureKey.typeIdentifier : kLowerCaseSmallCapsSelector
@juliensagot
juliensagot / NSBezierPath+cgPath.swift
Last active Dec 24, 2019
Convert NSBezierPath to CGPath (Swift 5.1, Xcode 11.3 (11C29))
View NSBezierPath+cgPath.swift
extension NSBezierPath {
/// A `CGPath` object representing the current `NSBezierPath`.
var cgPath: CGPath {
let path = CGMutablePath()
let points = UnsafeMutablePointer<NSPoint>.allocate(capacity: 3)
let elementCount = self.elementCount
if elementCount > 0 {
var didClosePath = true
You can’t perform that action at this time.