Skip to content

Instantly share code, notes, and snippets.

View trilliwon's full-sized avatar
🎯
Focusing

WonJo trilliwon

🎯
Focusing
View GitHub Profile
let min = CGFloat(-30)
let max = CGFloat(30)
let xMotion = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.x", type: .TiltAlongHorizontalAxis)
xMotion.minimumRelativeValue = min
xMotion.maximumRelativeValue = max
let yMotion = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.y", type: .TiltAlongVerticalAxis)
yMotion.minimumRelativeValue = min
yMotion.maximumRelativeValue = max
extension Date {
var startOfDay: Date {
return Calendar.current.startOfDay(for: self)
}
var endOfDay: Date {
var components = DateComponents()
components.day = 1
components.second = -1
return Calendar.current.date(byAdding: components, to: startOfDay)!
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)
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)
}
}
@trilliwon
trilliwon / bobp-python.md
Created April 19, 2019 02:53 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@trilliwon
trilliwon / makeTextureFromCVPixelBuffer.swift
Created May 7, 2019 04:48
makeTextureFromCVPixelBuffer
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)
@trilliwon
trilliwon / increaseBuildNumber.sh
Created June 6, 2019 05:24
increaseBuildNumber.sh
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}"
@trilliwon
trilliwon / AVSpeechSynthesizer+Rx.swift
Created June 25, 2019 14:01
AVSpeechSynthesizer+Rx
#if os(iOS)
import AVFoundation
import RxCocoa
import RxSwift
extension AVSpeechSynthesizer: HasDelegate {
public typealias Delegate = AVSpeechSynthesizerDelegate
}
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 })
}
@trilliwon
trilliwon / PlayButton.swift
Created July 20, 2019 10:26
Play pause button
//
// PlayButton.swift
// ProgressView
//
// Created by WonJo on 10/03/2019.
// Copyright © 2019 WonJo. All rights reserved.
//
import UIKit