Skip to content

Instantly share code, notes, and snippets.

View azamsharp's full-sized avatar

Mohammad Azam azamsharp

View GitHub Profile
import datetime
from datetime import timedelta
first_time = datetime.datetime.now()
later_time = datetime.datetime.now() + timedelta(minutes=10)
difference = later_time - first_time
# Exceptions
def ask_user_for_input():
print("asking user for input")
number = int(input("Enter number: "))
try: # capturing runtime errors
#ask_user_for_input()
#result = 1/0
result = 4/2
# Ask the user for input for name
# Ask the user for priority
# create a task using name and priority
# add the task to list of tasks
# list to hold al the tasks
all_tasks = []
class Task:
@azamsharp
azamsharp / .py
Created April 6, 2020 16:56
Classes and Objects in Python
# Creating a Class
class Car:
def __init__(self, make, model): # initializer/constructor
# define properties of the car
self.make = make
self.model = model
self.color = "White"
//ContentView:
NavigationLink(destination: LoginView().accessibility(identifier: "loginView"), isActive: self.$registrationVM.showLoginView) {
EmptyView()
}
// Test
func test_should_register_successfully() {
class RegistrationViewModel: ObservableObject {
@Validated(.required(errorMessage: "First name cannot be empty"))
var firstname: String? = ""
@Validated(.required(errorMessage: "Last name cannot be empty"))
var lastname: String? = ""
@Validated(.required(errorMessage: "Username cannot be empty"))
var username: String? = ""
static func required(errorMessage: String = "Is Empty") -> Validation {
return .init { value in
value.isEmpty ? .failure(.init(message: errorMessage)) : .success(())
}
}
class RegistrationViewModel: ObservableObject {
@Validated(.required)
var firstname: String? = ""
@Validated(.required)
var lastname: String? = ""
@Validated(.required)
import Foundation
import ValidatedPropertyKit
extension Validation where Value == String {
static var required: Validation {
return .init { value in
value.isEmpty ? .failure("\(value) cannot be empty") : .success(())
}
}
struct ContentView: View {
@ObservedObject private var registrationVM = RegistrationViewModel()
var body: some View {
NavigationView {
Form {
VStack(spacing: 10) {
TextField("First name", text: $registrationVM.firstname.bound)