Skip to content

Instantly share code, notes, and snippets.

View devmjun's full-sized avatar
🤔
 ( ͡°⁄ ⁄ ͜⁄ ⁄ʖ⁄ ⁄ ͡°) 

Minjun Ju(Leo) devmjun

🤔
 ( ͡°⁄ ⁄ ͜⁄ ⁄ʖ⁄ ⁄ ͡°) 
View GitHub Profile
@devmjun
devmjun / self.md
Last active November 20, 2018 10:33
To deal `self` keyword in swift

known bug

known bug that is [swift-evolution] Allowing guard let self = self else { ... } for weakly captured self in a closure. in previous version of swift 4.2

Backquotes are for forming a name that happens to overlap with a keyword.
In the case of self, this could be because you want to refer to the NSObject.self method for some reason.
Backquotes are not a way to name self, init, subscript or any of the other declarations that look like magic identifiers.

백쿼츠 키워드는 시스템 예약어와 겹치는 이름을 사용하기 위한것, guard let self = self else { return } 에 옵셔널 값을 할당하기 위해 사용하는게 아님.. 근데 Swift 4.2 이전 버전에서는 이유는 모르지만 동작함, Swift4.2에서도 동작함.. 컴파일 버그가 고쳐진것인지는 모르겠음.

@devmjun
devmjun / ConvertAngle.swift
Created November 18, 2018 18:57
Convert from degrees to radian or vice-versa
extension BinaryInteger {
var degreesToRadians: CGFloat { return CGFloat(Int(self)) * .pi / 180 }
}
extension FloatingPoint {
var degreesToRadians: Self { return self * .pi / 180 }
var radiansToDegrees: Self { return self * 180 / .pi }
}
@devmjun
devmjun / randomColor.swift
Created November 18, 2018 18:54
Random Color
extension UIColor {
static func randomColor() -> UIColor {
return UIColor(red: CGFloat(arc4random()) / CGFloat(UInt32.max),
green: CGFloat(arc4random()) / CGFloat(UInt32.max),
blue: CGFloat(arc4random()) / CGFloat(UInt32.max),
alpha: 1.0)
}
}
@devmjun
devmjun / git_alias.vi
Created November 11, 2018 16:06
git alias
[alias]
acp = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"
s = status
master = checkout master
ll = log --pretty=format:\"%C(yellow)%h\\\\ %ad%Cred%d\\\\ %Creset%s%Cblue\\\\ [%cn]\" --decorate --date=relative
l = log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
addedlist = log --stat --abbrev-commit
@devmjun
devmjun / setup_build_number_via_commitCount.sh
Created November 7, 2018 08:03
Automatically set up buildNumber via Git
# https://blog.curtisherbert.com/automated-xcode-build-numbers-late-2016-edition/
git=`sh /etc/profile; which git`
branch_name=`$git symbolic-ref HEAD | sed -e 's,.*/\\(.*\\),\\1,'`
git_count=`$git rev-list $branch_name |wc -l | sed 's/^ *//;s/ *$//'`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $git_count" "${PRODUCT_SETTINGS_PATH}"
echo "Updated build number in ${PRODUCT_SETTINGS_PATH} to $git_count"
@devmjun
devmjun / xcode-build-bump.sh
Created November 7, 2018 07:55 — forked from sekati/xcode-build-bump.sh
Xcode Auto-increment Build & Version Numbers
# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
@devmjun
devmjun / App-version.swift
Last active November 1, 2018 09:39
App Version
// https://gist.github.com/rarias84/610f76cedf3fe945da58ec6eb052305b
class AppInfo {
/// Returns DEBUG or RELEASE info with version and build number
static func buildInfo() -> String {
#if DEBUG
return "DEBUG" + versionInfo()
#else
return "RELEASE" + versionInfo()
#endif
@devmjun
devmjun / md5.swift
Created October 16, 2018 14:12
hashing to 'md5'
extension String {
var md5: String {
let length = Int(CC_MD5_DIGEST_LENGTH)
var digest = [UInt8](repeating: 0, count: length)
if let data = data(using: String.Encoding.utf8) {
_ = data.withUnsafeBytes { (body: UnsafePointer<UInt8>) in
CC_MD5(body, CC_LONG(data.count), &digest)
}
}
@devmjun
devmjun / URLdownloadDataTask.swift
Created October 16, 2018 08:46
download progress in URLSession
extension SearchViewController: URLSessionDownloadDelegate {
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask,
didWriteData bytesWritten: Int64, totalBytesWritten: Int64,
totalBytesExpectedToWrite: Int64) {
// 1
guard let url = downloadTask.originalRequest?.url,
let download = downloadService.activeDownloads[url] else { return }
// 2
download.progress = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite)
// 3