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 / chain-of-responsibility.py
Created December 25, 2019 07:42
Chain of responsibility design pattern in python
class ReportFormat(object):
PDF = 0
TEXT = 1
class Report(object):
def __init__(self, format_):
self.title = 'title'
self.format_ = format_
@farhadmpr
farhadmpr / cloudSettings
Last active January 1, 2020 04:36
VSCode
{"lastUpload":"2020-01-01T04:35:52.146Z","extensionVersion":"v3.4.3"}
@farhadmpr
farhadmpr / diamond.py
Created January 26, 2020 08:08
Python draw a diamond on the console
n = int(input('enter number: '))
lines_count = n * 2 - 1
for line in range(1, lines_count+1):
tabs = (n-line) * -1 if n-line < 0 else n-line
for tab in range(tabs):
print('\t', end='')
for col in range(n-tabs):
@farhadmpr
farhadmpr / Handler.cs
Created February 2, 2020 07:04
Replace Conditional Statements (IF/ELSE or SWITCH) With Polymorphism
class Handler
{
public void increaseSpeed(GameObject go1)
{
if(typeOf(go1) == Rabbit )
{
// increase speed by 3
}
else if(typeOf(go1) == Bear)
{
@farhadmpr
farhadmpr / Polymorphism.cs
Created February 2, 2020 07:17
Replace Conditional Statements (IF/ELSE or SWITCH) With Polymorphism
Interface GameObject() {
increaseSpeed() {};
}
class Rabbit implements GameObject {
increaseSpeed() {
//increase speed by 3
}
}
class Bear implements GameObject {
increaseSpeed() {
@farhadmpr
farhadmpr / items.py
Created February 10, 2020 10:22
Python scrapy image custom pipeline
import scrapy
class ImgItem(scrapy.Item):
image_urls = scrapy.Field()
images = scrapy.Field()
@farhadmpr
farhadmpr / AnemicDomainModel.java
Created February 16, 2020 08:00
simple anemic model
public class Order {
private BigDecimal total = BigDecimal.ZERO;
private List<OrderItem> items = new ArrayList<OrderItem>();
public BigDecimal getTotal() {
return total;
}
public void setTotal(BigDecimal total) {
this.total = total;
@farhadmpr
farhadmpr / AnemicDomainService.java
Created February 16, 2020 08:03
anemic domain service for calculating the total of an order
public class OrderService {
public void calculateTotal(Order order) {
if (order == null) {
throw new IllegalArgumentException("order must not be null");
}
BigDecimal total = BigDecimal.ZERO;
List<OrderItem> items = order.getItems();
@farhadmpr
farhadmpr / instagram.py
Last active July 21, 2020 06:39
instagram
import instaloader
import sqlite3
L = instaloader.Instaloader()
L.login('', '')
profile = instaloader.Profile.from_username(L.context, '')
@farhadmpr
farhadmpr / follow_user.py
Created February 23, 2020 09:18
follow user instagram
from instagram_private_api import Client, ClientCompatPatch
u = ''
p = ''
api = Client(u, p)
# https://www.instagram.com/{username}/?__a=1
print(api.friendships_create('user_id'))