Skip to content

Instantly share code, notes, and snippets.

View farhadmpr's full-sized avatar
😎
Try to be a professional

Farhad Mortezapour farhadmpr

😎
Try to be a professional
View GitHub Profile
@farhadmpr
farhadmpr / RichModel2.java
Created December 8, 2021 11:27
RichModel2
public class OrderTest {
/**
* This test shows that a rich model gurantees that it is in a legal state
* at any time.
*/
@Test
public void richDomainModelMustEnsureToBeConsistentAtAnyTime() {
Order order = new Order();
BigDecimal total = order.getTotal();
@farhadmpr
farhadmpr / RichModel1.java
Last active December 8, 2021 11:28
RichModel1
public class Order {
private BigDecimal total;
private List<OrderItem> items = new ArrayList<OrderItem>();
/**
* The total is defined as the sum of all {@link OrderItem#getTotal()}.
*
* @return the total of this {@link Order}.
*/
@farhadmpr
farhadmpr / fake
Created September 29, 2021 08:20
Ambient Context #5
class LocationManagerStub: LocationService {
var isLocationServiceAuthorized: Bool
init(isLocationServiceAuthorized: Bool) {
self.isLocationServiceAuthorized = isLocationServiceAuthorized
}
func isAuthorized() -> Bool {
return isLocationServiceAuthorized
@farhadmpr
farhadmpr / MapViewModel
Created September 29, 2021 08:19
Ambient Context #4
class MapViewModel {
// MARK: - Private Vars
private let locationService: LocationService
private let dateProviderService: DateProviderService
// MARK: - Init
init(locationService: LocationService, dateProviderService: DateProviderService) {
self.locationService = locationService
@farhadmpr
farhadmpr / Implementations
Created September 29, 2021 08:17
Ambient Context #3
class LocationManager: LocationService {
//....
func isAuthorized() -> Bool {
switch authorizationStatus() {
case .authorizedAlways,
.authorizedWhenInUse:
return true
default:
return false
@farhadmpr
farhadmpr / Abstractions
Created September 29, 2021 08:15
Ambient Context #2
protocol LocationService {
//....
func isAuthorized() -> Bool
func requestUserLocation(completion: ...)
//....
}
protocol DateProviderService {
//....
var date: Date { get }
@farhadmpr
farhadmpr / LocationManager
Created September 29, 2021 08:14
Ambient Context #1
class LocationManager {
//....
static func isAuthorized() -> Bool {
switch authorizationStatus() {
case .authorizedAlways,
.authorizedWhenInUse:
return true
default:
return false
@farhadmpr
farhadmpr / parenthesis-checker.py
Last active November 17, 2020 07:24
Check for Balanced Brackets in an expression using Stack
# Python3 program to check for
# balanced brackets.
# function to check if
# brackets are balanced
def areBracketsBalanced(expr):
stack = []
@farhadmpr
farhadmpr / telegram_2.py
Created August 9, 2020 07:33
Telegram channel crawler
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
# Define a few command handlers. These usually take the two arguments update and
# context. Error handlers also receive the raised TelegramError object in error.
def start(update, context):
"""Send a message when the command /start is issued."""
update.message.reply_text('Hi!')
@farhadmpr
farhadmpr / persian_matplotlib.py
Created May 20, 2020 05:25
Matplotlib with persian characters
import matplotlib.pyplot as plt
import pandas as pd
import arabic_reshaper
from matplotlib.pyplot import *
from bidi.algorithm import get_display
class Enums:
Year = 'سال'
Number = 'تعداد تخلفات'