Skip to content

Instantly share code, notes, and snippets.

View Bradysm's full-sized avatar
🎯
Focusing

Brady Murphy Bradysm

🎯
Focusing
View GitHub Profile
# 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...
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:")
import XCTest
@testable import Mocking
class MockingTests: XCTestCase {
let username = "testusername"
/// mocked service for sending message
var mockedMessageService = MockedMessageService()
/**
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) {
/**
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);
}
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
struct WithDependencyInjection {
var module: Module
// inject the dependency through the initializer
// to explicitly show the dependency on Module
init(module: Module) {
self.module = module
}
}
struct WithoutDependencyInjection {
var module: Module
init() {
// creating the module ourselves in the init
// without stating the dependency on "Module"
self.module = Module()
}
}
struct WithDependencyInjection {
var module: Module
// inject the dependency through the initializer
// to explicitly show the dependency on Module
init(module: Module) {
self.module = module
}
}
@Bradysm
Bradysm / ColorManagerExample.swift
Last active July 25, 2020 14:12
Example of using the color manager within your application
import SwiftUI
struct SpotifyText: View {
var body: some View {
Text("Spotify Green")
.foregroundColor(ColorManager.spotifyGreen)
}
}