Expression | How to Read This |
---|---|
a plus b | |
a minus b | |
a times b | |
a over b | |
a is greater than b | |
a is less than b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
system_profiler SPUSBDataType | awk -F": " '/^[[:space:]]*[^[:space:]].*:$/ { device=$1; sub(/^[[:space:]]*/, "", device); sub(/:$/, "", device) } /^[[:space:]]+Speed:/ { gsub(/^[[:space:]]+Speed: /, "", $0); if (device !~ /[Hh]ub/) print device " - " $0 }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by SHEN SHENG on 1/16/22. | |
// This code is a part of the Wordbook iOS app. | |
// Wordbook is an App to help memorize and learn new English words. | |
// website: https://www.wordbook.cool | |
struct WatchMasterView: View { | |
@FocusState private var focusTab: Int? | |
@State private var currentTab = 0 | |
var body: some View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by SHEN SHENG on 1/16/22. | |
// This code is a part of the Wordbook iOS app. | |
// Wordbook is an App to help memorize and learn new English words. | |
// website: https://www.wordbook.cool | |
@State private var tabSelection = 1 | |
var body: some View { | |
NavigationView { | |
VStack{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func simularWordSizes(a: [CGSize], b: [CGSize]) -> Bool { | |
if a == b { | |
return true | |
} | |
if a.count != b.count { | |
return false | |
} | |
var diff : CGFloat = 0 | |
for i in 0...(a.count-1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var positionCache = WordCloudPositionCache() | |
func calcPositions(canvasSize: CGSize, itemSizes: [CGSize]) -> [CGPoint] { | |
var pos = [CGPoint](repeating: CGPoint.zero, count: itemSizes.count) | |
if canvasSize.height == 0 { | |
return pos | |
} | |
if positionCache.canvasSize == canvasSize { | |
return positionCache.positions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func checkIntersects(rect: CGRect, rects: [CGRect]) -> Bool { | |
for r in rects { | |
if rect.intersects(r) { | |
return true | |
} | |
} | |
return false | |
} | |
func checkOutsideBoundry(canvasSize: CGSize, rect: CGRect) -> Bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func findSafePlace(for size: CGSize, avoid occupiedAreas: [CGRect]) -> CGRect { | |
// keep trying random places until it fit | |
for _ in 0...100 { | |
let randomRect = CGRect(origin: CGPoint(x: CGFloat.random(in: 0...canvasSize.width), | |
y: CGFloat.random(in: 0...canvasSize.height)), | |
size: size) | |
var collision = false | |
for rect in occupiedAreas { | |
if rect.intersects(randomRect) { | |
collision = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct WordCloudView: View { | |
private let words: [WordElement] = [WordElement].generate(forSwiftUI: true) | |
@State private var canvasRect = CGRect() | |
@State private var wordSizes: [CGSize] | |
init() { | |
self._wordSizes = State(initialValue:[CGSize](repeating: CGSize.zero, count: words.count)) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct RectGetterDemoView: View { | |
@State private var canvasRect = CGRect() | |
var body: some View { | |
Text("Demo").background(RectGetter($canvasRect)) | |
} | |
} | |
struct RectGetter: View { |
NewerOlder