Skip to content

Instantly share code, notes, and snippets.

View maciejpiotrowski89's full-sized avatar
πŸ‘¨β€πŸ’»

Maciej Piotrowski maciejpiotrowski89

πŸ‘¨β€πŸ’»
View GitHub Profile
extension String {
func deletingPrefix(_ prefix: String) -> String {
guard hasPrefix(prefix) else { return self }
return String(dropFirst(prefix.count))
}
}
let processInfo = ProcessInfo.processInfo
let environment = processInfo.environment
guard let environment["KEY"] else { return }
//
// ContentView.swift
// AdditiveAnimations
//
// Created by Chris Eidhof on 10.10.19.
// Copyright Β© 2019 Chris Eidhof. All rights reserved.
// https://github.com/objcio/S01E174-animation-curves/blob/master/AnimationCurves/ContentView.swift
import SwiftUI
@maciejpiotrowski89
maciejpiotrowski89 / swiftui_shake.swift
Last active November 15, 2020 06:20
Shake Animation in SwiftUI from objc.io swift talks
//
// ContentView.swift
// Layers
//
// Created by Chris Eidhof on 09.10.19.
// Copyright Β© 2019 Chris Eidhof. All rights reserved.
// https://github.com/objcio/S01E173-building-a-shake-animation/blob/master/Shake/ContentView.swift
import SwiftUI
@maciejpiotrowski89
maciejpiotrowski89 / DispatcherStub.swift
Last active May 12, 2020 17:08
Simplified `DispatcherStub` for unit testing asynchronous code ([link to blog post](https://swifting.io/blog/2018/03/03/50-synchronous-unit-tests/))
protocol Dispatching {
func dispatch(_ work: @escaping ()->Void)
}
final class DispatcherStub: Dispatching {
func dispatch(_ work: @escaping ()->Void) {
work()
}
}
fileprivate extension Selector {
static let doStuff = #selector(ViewController.doStuff)
}
//Method documentation
/*!
* @brief <#brief#>
* @discussion <#description#>.
* @warning <#warning#>.
* @param <#param description#>
* @return <#return description#>
*/
@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
}
(lldb) expr -l Swift -- import UIKit
(lldb) expr -l Swift -- let $pin = unsafeBitCast(0x7df67c50, to: MKPinAnnotationView.self)
(lldb) expr -l Swift -- print($pin.alpha)
//https://stackoverflow.com/questions/29441418/lldb-swift-casting-raw-address-into-usable-type
@maciejpiotrowski89
maciejpiotrowski89 / UIView+UIImage.m
Created January 31, 2018 07:42
Draw UIImage from UIView
- (UIImage *)image {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}