Skip to content

Instantly share code, notes, and snippets.

View jeffery812's full-sized avatar
😜

Jeffery jeffery812

😜
View GitHub Profile
@jeffery812
jeffery812 / spmResolve.py
Last active December 25, 2022 13:00
This script is a workaround to resolve SPM versions.
#!/opt/homebrew/bin/python3
# Sometimes Xcode cannot resolve SPM(File -> Packages -> Resolve Package versions) if the dependency url is ssh
# This script is a workaround to resolve package versions.
# Usage:
# python spmResolve.py
# or
# python3 spmResolve.py
import os.path
import subprocess
struct AvatarView: View {
/// image
let image: String
/// size
let size: CGFloat
/// body
var body: some View {
@jeffery812
jeffery812 / appdocdir.zsh
Created November 10, 2020 15:36 — forked from nickcheng/appdocdir.zsh
Open your app's Documents folder on iOS simulator.
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
//------------------------------------------------------------------------
// 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 {
# 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]
// 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))
}
}
// 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
// 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 {}
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()
#!/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
}