This file contains hidden or 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 hidden or 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 hidden or 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 { |
This file contains hidden or 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
| var body: some View { | |
| Image(uiImage: wordCloudImage(words)) | |
| .resizable() | |
| .aspectRatio(contentMode: .fit) | |
| .padding(10) | |
| } | |
| func wordCloudImage(_ words: [WordElement]) -> UIImage { | |
| UIGraphicsBeginImageContextWithOptions(canvasSize, false, 1.0) | |
This file contains hidden or 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
| // Singleton makes sure there is only one "single" instance across the system. | |
| // by binding to a tcp resource as specified by addr, eg. "127.0.0.1:51337". | |
| func Singleton(addr string) { | |
| go singletonServer(addr) | |
| for { | |
| // wait and confirm that server was started successfully | |
| pid, err := getSingletonPID(addr) | |
| if err == nil && pid == strconv.Itoa(os.Getpid()) { | |
| return | |
| } |
This file contains hidden or 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
| IKE:3DES_CBC/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1024, | |
| IKE:3DES_CBC/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_1024, | |
| IKE:3DES_CBC/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_1024, | |
| IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1024, | |
| IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_1024, | |
| IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_1024, | |
| IKE:AES_CBC_192/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1024, | |
| IKE:AES_CBC_192/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_1024, | |
| IKE:AES_CBC_192/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_1024, | |
| IKE:AES_CBC_256/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1024, |
This file contains hidden or 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
| # ipsec.secrets | |
| # RSA private key for this host, authenticating it to any other host which knows the public part. | |
| your.host.name : RSA "privkey.pem" | |
| # username password list | |
| your.username : EAP "your.password" |
This file contains hidden or 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
| # ipsec.conf - strongSwan IPsec configuration file | |
| … | |
| # use IKEv2 protocol | |
| keyexchange=ikev2 | |
| # server certificate | |
| leftcert=cert.pem | |
| # use eap-mschapv2 protocol - auth by username/password |
This file contains hidden or 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
| FlipView( | |
| VStack { Text("Front") }, | |
| VStack { Text("Back") }, | |
| tap: { | |
| PlaySound(sound) | |
| }, | |
| flipped: self.$flipped, | |
| disabled: self.$disabled | |
| ) |
This file contains hidden or 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 RandomFetch() -> Item? { | |
| let req = NSFetchRequest<NSFetchRequestResult>(entityName: "MyEntity") | |
| req.predicate = NSPredicate(format: "duedate > %@", due as NSDate) | |
| // find out how many items are there | |
| let totalresults = try! mContext.count(for: req) | |
| if totalresults > 0 { | |
| // randomlize offset | |
| req.fetchOffset = Int.random(in: 0..<totalresults) | |
| req.fetchLimit = 1 |