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
| import SceneKit | |
| import PlaygroundSupport | |
| var sceneView = SCNView() | |
| PlaygroundPage.current.liveView = sceneView | |
| sceneView.backgroundColor = .black | |
| var scene = SCNScene() | |
| sceneView.scene = scene | |
| var universe = scene.rootNode |
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
| import numpy as np | |
| np.random.seed(0) | |
| def sigmoid(t): | |
| return 1 / (1 + np.exp(-t)) | |
| def sigmoid_derivative(p): | |
| return p * (1 - p) | |
| class NeuralNetwork: | |
| def __init__(self, training_input, known_output, weights=10, training=10000): |
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
| import SceneKit | |
| import PlaygroundSupport | |
| var sceneView = SCNView() | |
| PlaygroundPage.current.liveView = sceneView | |
| var scene = SCNScene() | |
| sceneView.scene = scene | |
| var object = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 1) | |
| var objectMaterial = object.firstMaterial! |
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
| import Foundation | |
| import Combine | |
| import PlaygroundSupport | |
| func await<T>(_ body: @escaping (@escaping (T) -> Void) -> AnyCancellable) -> T { | |
| return { | |
| var result: T! = nil | |
| let semaphore = DispatchSemaphore(value: 0) | |
| body { value in | |
| result = value |
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
| let lat = Float.random(in: -70...70), long = Float.random(in: -180..<180) | |
| let query = "api=1&query=\(lat),\(long)" | |
| NSWorkspace.shared.open(URL(string: "https://www.google.com/maps/search/?\(query)")!) |
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
| let query = "api=1&query=51.509865, -0.118092" | |
| .addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! | |
| NSWorkspace.shared.open(URL(string: "https://www.google.com/maps/search/?\(query)")!) |
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
| import Cocoa | |
| NSWorkspace.shared.open(URL(string: "https://www.google.com/maps")!) |
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
| typealias Action = ()->Void | |
| class Service { | |
| var closure: Action? | |
| func setClosure(_ closure: @escaping Action) { | |
| self.closure = closure | |
| } | |
| func executeClosure() { | |
| closure?() | |
| } |
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 run() { | |
| let service1 = Service("S1") | |
| let service2 = Service("S2") | |
| let client1 = Client("C1", subscribingTo: service1) | |
| let client2 = Client("C2", subscribingTo: service2) | |
| service1.doSomething(1) | |
| service2.somethingWasDone.addHandler(client1.somethingWasDoneHandler) | |
| service2.doSomething(2) | |
| service2.somethingWasDone.removeHandler(client1.somethingWasDoneHandler) | |
| service2.doSomething(3) |
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
| class Service { | |
| init(_ name: String = "default") { | |
| self.name = name | |
| } | |
| var name: String | |
| func doSomething(_ info: Int) { | |
| somethingWasDone.raise(info) | |
| } | |
| var somethingWasDone = Event<Int>() | |
| deinit { |