Skip to content

Instantly share code, notes, and snippets.

Avatar
😜

Zhihui Tang zhihuitang

😜
View GitHub Profile
View AvatarView
struct AvatarView: View {
/// image
let image: String
/// size
let size: CGFloat
/// body
var body: some View {
@zhihuitang
zhihuitang / appdocdir.zsh
Created Nov 10, 2020 — forked from nickcheng/appdocdir.zsh
Open your app's Documents folder on iOS simulator.
View appdocdir.zsh
function myappdocdir() {
devid=$(xcrun simctl list devices | grep Booted | sed -n 's/^.*\([A-F0-9]\{8\}-\([A-F0-9]\{4\}-\)\{3\}[A-F0-9]\{12\}\).*$/\1/p')
for folder in ~/Library/Developer/CoreSimulator/Devices/$devid/data/Containers/Data/Application/*; do
if [[ -a $folder/.com.apple.mobile_container_manager.metadata.plist ]]; then
if [[ 'com.apple.phone' = $(/usr/libexec/PlistBuddy -c 'Print :MCMMetadataIdentifier' $folder/.com.apple.mobile_container_manager.metadata.plist) ]]; then
echo $folder
break
fi
fi
done
View advanced-swiftui-animations.swift
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
View .gitconfig
# Git Fuzzy Checkout
#
# Add the following script to your ~/.gitconfig by run:
# git config --global alias.fuzzy '!f() { git branch -a | grep -m1 -e ${1}.*${2} | sed "s/remotes\/origin\///" | xargs git checkout; }; f'
#
# alias of .gitconfig looks:
[alias]
View DateExtensions
// https://stackoverflow.com/questions/33145005/swift-nsdateformatter-not-using-correct-locale-and-format/61094162#61094162
extension Date {
var timestamp: String {
let dataFormatter = DateFormatter()
dataFormatter.locale = Locale(identifier: "en_US_POSIX")
dataFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSS"
return String(format: "%@", dataFormatter.string(from: self))
}
}
View Atomic
// https://www.vadimbulavin.com/swift-atomic-properties-with-property-wrappers/
/*
Although get and set are individually atomic, the combination of both is not.
Incrementing x is not atomic, since it first calls get and then set:
*/
@propertyWrapper
struct Atomic<Value> {
private let queue = DispatchQueue(label: "com.vadimbulavin.atomic")
private var value: Value
View UserDefaultExtensions
// https://www.vadimbulavin.com/advanced-guide-to-userdefaults-in-swift/
// what is the difference between WWDC2019 https://devstreaming-cdn.apple.com/videos/wwdc/2019/402fd460n3p3w5c/402/402_whats_new_in_swift.pdf
// The marker protocol
protocol PropertyListValue {}
extension Data: PropertyListValue {}
extension String: PropertyListValue {}
extension Date: PropertyListValue {}
extension Bool: PropertyListValue {}
extension Int: PropertyListValue {}
View AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
let timeline = TimelineViewController()
let navigation = UINavigationController(rootViewController: timeline)
let frame = UIScreen.main.bounds
window = UIWindow(frame: frame)
window!.rootViewController = navigation
window!.makeKeyAndVisible()
View sh_kits
#!/bin/bash
set -o nounset
set -o errexit
set -o verbose
set -o xtrace
log() {
local prefix="[$(date +%Y/%m/%d\ %H:%M:%S)]:"
echo "${prefix} $@" >&2
}
@zhihuitang
zhihuitang / Python3 Virtualenv Setup.md
Created Apr 22, 2019 — forked from pandafulmanda/Python3 Virtualenv Setup.md
Setting up and using Python3 Virtualenv on Mac
View Python3 Virtualenv Setup.md

Python3 Virtualenv Setup

Requirements
  • Python 3
  • Pip 3
$ brew install python3