Skip to content

Instantly share code, notes, and snippets.

View klement97's full-sized avatar
🌍
Open for opportunities

Klement Omeri klement97

🌍
Open for opportunities
View GitHub Profile
@klement97
klement97 / fibonacci.py
Last active April 15, 2019 00:22
Prints out first n numbers of fibonacci sequence. Try smth like 1000 or 10 000 if you have some time and check out its length!
n = int(input("enter n: "))
number = []
number.append(1)
number.append(1)
print(number[0])
print(number[1])
for i in range(2, n):
number.append(number[i-1] + number[i-2])
print(number[i])
@klement97
klement97 / random password generator and breaker
Last active April 15, 2019 12:05
This code generates a random password with selecting randomly from all charachters and then tries to break this password
import random
def get_char():
return random.choice(characters)
def print_password(password):
print("auto-generated password is:")
print(password)
@klement97
klement97 / error.handler.ts
Last active June 26, 2023 12:16
A central solution to error handling in Angular Reactive Forms
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms';
import {Injectable} from '@angular/core';
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
export declare interface ServerError {
[key: string]: [];
}
<!-- first name -->
<mat-form-field appearance="outline">
<mat-label> First Name</mat-label>
<input matInput type="text" formControlName="first_name">
<mat-error *ngIf="signUpForm.get('first_name').errors.required">
This field is required
</mat-error>
<mat-error *ngIf="signUpForm.get('first_name').errors.minlength">
Min length is {{signUpForm.get('first_name').errors.minlength.requiredLength}}
</mat-error>
@klement97
klement97 / form-error-objects.ts
Created March 26, 2020 19:19
error object's representation for error handler class
const errorObject = {
first_name: 'This field is required',
last_name: 'This field is required',
email: 'This field is required',
password: 'This field is required',
re_password: 'This field is required',
};
this.signUpForm = this.fb.group({
first_name: ['', [
Validators.required,
Validators.maxLength(100)
]],
last_name: ['', [
Validators.required,
Validators.maxLength(100)
]],
email: ['', [
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
import re
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _
class NumberValidator(object):
@staticmethod
def validate(password, user=None):
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
@property
def total_price(self) -> Decimal:
"""
Total price is sum of all topping prices.
"""
price = Decimal(0)
for topping in self.toppings.all():
price += topping.price
return price