Skip to content

Instantly share code, notes, and snippets.

a: AM/PM
A: 0~86399999 (Millisecond of Day)
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
@50percentgrey
50percentgrey / self-sizing-collectionview-cell.swift
Last active November 16, 2023 13:24
Self-sizing CollectionView/Cell
// setup your collectionView
private let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumInteritemSpacing = 20.0
layout.minimumLineSpacing = 20.0
// important!
layout.itemSize = UICollectionViewFlowLayout.automaticSize
// change estimatedItemSize for a vertical example
layout.estimatedItemSize = CGSize(width: UIScreen.main.bounds.width, height: 40.0)
@50percentgrey
50percentgrey / apple.sh
Created January 29, 2020 19:11
Delete-Clean Unnecessary files / Apple / Xcode
#!/bin/bash
# Delete Archived Applications
rm -r ~/Library/Developer/Xcode/Archives/*/
# Delete Devired Data
rm -r ~/Library/Developer/Xcode/DerivedData/*/
# Delete Apple cached files
rm -r ~/Library/Developer/CoreSimulator/Caches/dyld/*/*/
@50percentgrey
50percentgrey / incr.sh
Created December 5, 2019 19:30
Increment Build - Build Phases
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}"
@50percentgrey
50percentgrey / counterparts.cmd
Created November 18, 2019 14:17
MVVM jump to counterparts in Xcode
run in terminal
defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "ViewController" "Coordinator" "Repository"
close Xcode and open it again.
jump by using Ctrl+Cmd+Up and Ctrl+Cmd+Down
if you want to revert the change
defaults delete com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes
ref: https://gist.github.com/danielmartin/8411c303e5c8702c19c65950b49635b8
// camera roll folder simulator
~/Library/Developer/CoreSimulator/Devices/<device UDID>/data/Media/DCIM/100APPLE
//
~/Library/Developer/CoreSimulator/Devices/991FCB82-FA99-4C9E-AA2A-B8A6A33034B3⁩/⁨data⁩/⁨Media⁩/⁨DCIM⁩/100APPLE⁩
// Document Directory
~/Library/Developer/CoreSimulator/Devices/991FCB82-FA99-4C9E-AA2A-B8A6A33034B3⁩/⁨⁨data⁩/Containers⁩/⁨Data⁩/Application⁩/0A893DFE-05BC-44E7-9C65-314871273441⁩/Documents⁩
@50percentgrey
50percentgrey / observables.rx.swift
Created February 27, 2019 18:23
Extract Value from Observable
let obs1 = Observable.just(FakeObject(blood: [0,1], producers: [100,101]))
let obs2 = Observable.just(FakeObject(blood: [3,4], producers: [300,401]))
let objs = [Observable.just(obs1), Observable.just(obs2)]
// [Observable<Observable[FakeObject]>] to [FakeObject]
Observable.combineLatest(vitals)
.flatMap { Observable.combineLatest($0) }
// convert audio on mac for iOS
// afconvert -d [out data format] -f [out file format] [in file] [out file]
afconvert -d aac -f 'caff' -b 128000 background-music-lei.caf test_128.caf
afconvert -d aac -f 'caff' -b 32000 background-music-lei.caf test_32.caf
afconvert -d aac -f 'caff' background-music-lei.caf test_32.caf
// best formats
If space is not an issue, just encode everything with linear PCM. Not only is this the fastest way for your audio to play, but you can play multiple sounds simultaneously without running into any CPU resource issues.
@50percentgrey
50percentgrey / plistToJson.cmd
Last active August 15, 2019 18:22
Convert plist to json - json to plist
plutil -convert json Data.plist -o Data.json
plutil -convert xml1 Data.json -o Data.plist
xcrun simctl delete unavailable