Skip to content

Instantly share code, notes, and snippets.

View zmeyc's full-sized avatar

Andrey Fidrya zmeyc

  • https://www.door3.com
  • Ukraine
View GitHub Profile
@zmeyc
zmeyc / multiple-await-with-loop.swift
Created October 21, 2023 19:24
Swift concurrency: multiple await for single result with loop
import Foundation
func generateSecureHash() async -> UUID {
print("Generating hash")
do {
try await Task.sleep(for: .seconds(100))
} catch {
print("Sleep: \(error)")
}
print("Generating hash: done")
// Merged other forks and updated to Swift 2.0.
// Original code:
// https://gist.github.com/haipham/d169cdea2f28222db7f3
// http://stackoverflow.com/questions/24007129/how-does-one-generate-a-random-number-in-apples-swift-language
// https://gist.github.com/pontusarmini/169bc5b3c3fc552a4c3d
import Foundation
import CoreGraphics
// Suppress a warning
//
// Original Objective C version: https://gist.github.com/bobmoff/7110052
//
// Fix SpriteKit's SKNode bug on iOS 7 & 8: nodes capture touch events
// even when userInteractionEnabled is false and the nodes are hidden.
//
// Details:
// http://stackoverflow.com/questions/19511334/sprite-with-userinteractionenabled-set-to-yes-does-not-receive-touches-when-cove
//
// How to use:
@zmeyc
zmeyc / Router.swift
Created July 31, 2015 11:01
Router pattern in Swift
// Playing with router pattern in Swift. Paste to a playground.
//
// This code is in public domain, feel free to copy/paste.
import Cocoa
extension NSScanner {
func scanUpToString(string: String) -> String? {
var result: NSString? = nil
if scanUpToString(string, intoString: &result) {