A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| def isPerfectSquare(x): | |
| sr = math.sqrt(x) | |
| return (sr - math.floor(sr)) == 0 |
| 🏋🏻♂️ 👨🏻💻 |
| class RaindropView: UIView { | |
| var images: [CGImage] { | |
| return [UIImage(named: "rain"), | |
| UIImage(named: "rain"), | |
| UIImage(named: "rain"), | |
| UIImage(named: "rain"), | |
| UIImage(named: "rain")].map({ $0?.cgImage }).compactMap({ $0 }) | |
| } |
| #if os(iOS) | |
| import AVFoundation | |
| import RxCocoa | |
| import RxSwift | |
| extension AVSpeechSynthesizer: HasDelegate { | |
| public typealias Delegate = AVSpeechSynthesizerDelegate | |
| } |
| buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}") | |
| buildNumber=$(($buildNumber + 1)) | |
| /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}" |
| func makeTextureFromCVPixelBuffer(pixelBuffer: CVPixelBuffer, textureFormat: MTLPixelFormat) -> MTLTexture? { | |
| let width = CVPixelBufferGetWidth(pixelBuffer) | |
| let height = CVPixelBufferGetHeight(pixelBuffer) | |
| // Create a Metal texture from the image buffer. | |
| var cvTextureOut: CVMetalTexture? | |
| CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, nil, textureFormat, width, height, 0, &cvTextureOut) | |
| guard let cvTexture = cvTextureOut, let texture = CVMetalTextureGetTexture(cvTexture) else { | |
| CVMetalTextureCacheFlush(textureCache, 0) |
| class DownloadCircleProgressView: UIView { | |
| // Interface | |
| var progress: Float = 0.0 { | |
| didSet { | |
| // animate from [oldValue] to [newValue] | |
| animateProgressLayer(from: CGFloat(oldValue), to: CGFloat(progress), duration: 0.1) | |
| } | |
| } |
| class TriangleView: UIView { | |
| override func draw(_ rect: CGRect) { | |
| guard let context = UIGraphicsGetCurrentContext() else { return } | |
| context.beginPath() | |
| context.move(to: CGPoint(x: rect.midX, y: rect.minY)) | |
| context.addLine(to: CGPoint(x: rect.minX, y: rect.maxY)) | |
| context.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY)) | |
| context.closePath() | |
| context.setFillColor(UIColor.black.withAlphaComponent(0.6).cgColor) |