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
# convert all of the points to integers | |
points = [(int(p[0]), int(p[1]), int(p[2])) for p in pattern.findall(input_points)] | |
# use a heap of size k to complete the problem... |
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
def find_all_numbers(): | |
# create regex and then compile it into a regex object | |
regex = r'[+-]?\d+' | |
pattern = re.compile(regex) | |
# ask for an input from the user | |
input_str = input("Enter a string with numbers: ") | |
# find all numbers within the string using the regex | |
print("\nALL NUMBERS WITHIN THE STRING:") |
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
import XCTest | |
@testable import Mocking | |
class MockingTests: XCTestCase { | |
let username = "testusername" | |
/// mocked service for sending message | |
var mockedMessageService = MockedMessageService() | |
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
/** | |
Service for mocking a message sending service | |
Conforms to MessageSendable protocol | |
*/ | |
struct MockedMessageService: MessageSendable { | |
/** | |
Mocked version of send message | |
*/ | |
func sendMessage(username: String, message: String, completion: @escaping (Result<String, Error>) -> Void) { |
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
/** | |
Protocol used to define services that can send messages | |
*/ | |
protocol MessageSendable { | |
/// prototype of messaging function that must be defined within a module | |
/// that conforms to this protocol | |
func sendMessage(username: String, message: String, completion: @escaping (Result<String, Error>) -> Void); | |
} |
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
final class ChatRoomViewModel: ObservableObject { | |
/// service used to send message to chat room | |
private let messagingService: MessageSendable | |
/// username of current user of application | |
private(set) var username: String | |
/// current message typed in 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
struct WithDependencyInjection { | |
var module: Module | |
// inject the dependency through the initializer | |
// to explicitly show the dependency on Module | |
init(module: Module) { | |
self.module = module | |
} | |
} | |
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 WithoutDependencyInjection { | |
var module: Module | |
init() { | |
// creating the module ourselves in the init | |
// without stating the dependency on "Module" | |
self.module = Module() | |
} | |
} |
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 WithDependencyInjection { | |
var module: Module | |
// inject the dependency through the initializer | |
// to explicitly show the dependency on Module | |
init(module: Module) { | |
self.module = module | |
} | |
} | |
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
import SwiftUI | |
struct SpotifyText: View { | |
var body: some View { | |
Text("Spotify Green") | |
.foregroundColor(ColorManager.spotifyGreen) | |
} | |
} |
NewerOlder