Skip to content

Instantly share code, notes, and snippets.

@danie7k
danie7k / executiontime.swift
Created October 18, 2019 09:28
CFAbsoluteTime measuring
let start = CFAbsoluteTimeGetCurrent()
// run your work
let diff = CFAbsoluteTimeGetCurrent() - start
print("Took \(diff) seconds")
@danie7k
danie7k / measure.swift
Created October 18, 2019 09:27
Quick Performance Timing
@discardableResult
func measure<A>(name: String = "", _ block: () -> A) -> A {
let startTime = CACurrentMediaTime()
let result = block()
let timeElapsed = CACurrentMediaTime() - startTime
print("Time: \(name) - \(timeElapsed)")
return result
}
@danie7k
danie7k / text-image.m
Created February 14, 2018 14:37
Text around image
UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
self.textView.textContainer.exclusionPaths = @[imgRect];
CFNETWORK_DIAGNOSTICS 3
OS_ACTIVITY_MODE disable
extension CGPath {
func forEach( body: @convention(block) (CGPathElement) -> Void) {
typealias Body = @convention(block) (CGPathElement) -> Void
let callback: @convention(c) (UnsafeMutableRawPointer, UnsafePointer<CGPathElement>) -> Void = { (info, element) in
let body = unsafeBitCast(info, to: Body.self)
body(element.pointee)
}
print(MemoryLayout.size(ofValue: body))
let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
func fixPerformance() {
if (self.cornerRadius > 0) {
self.masksToBounds = false
self.shouldRasterize = true
self.rasterizationScale = UIScreen.main.scale
}
if (self.shadowRadius > 0) {
self.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: self.cornerRadius).cgPath
}
import UIKit
extension UIColor {
convenience init(hex: Int, alpha: CGFloat = 1.0) {
self.init(
red: CGFloat((hex >> 16) & 0xFF) / 255.0,
green: CGFloat((hex >> 8) & 0xFF) / 255.0,
blue: CGFloat(hex & 0xFF) / 255.0,
alpha: alpha
import UIKit
typealias GradientPoints = (startPoint: CGPoint, endPoint: CGPoint)
enum GradientOrientation {
case horizontal
case vertical
var startPoint: CGPoint {
return points.startPoint
func roundImage(image: Image) -> Image? {
let rect = CGRect(origin:CGPoint(x: 0, y: 0), size: image.size)
UIGraphicsBeginImageContextWithOptions(image.size, false, 0.0)
UIBezierPath(roundedRect: rect, cornerRadius: self.cornerRadius).addClip()
image.draw(in: rect)
let roundedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return roundedImage
}
@danie7k
danie7k / user-command.sh
Created November 22, 2016 16:51
Run console command as another user
sudo -H -u www-data git status