Skip to content

Instantly share code, notes, and snippets.

import sys
import six
url = 'https://api.thecatapi.com/api/images/get?format=src&type=gif&size=small'
if sys.version_info[0] < 3:
# python version is 2
try:
from six.moves import urllib
except exception as e:
raise e
import redis
import os
from abc import ABC, abstractmethod
redis_ins = redis.Redis(db=1)
class IBackend(ABC):
@abstractmethod
def get(self, resource_id):
import redis
import os
redis_ins = redis.Redis(db=1)
class Backend:
def __init__(self, ins):
self.ins = ins
def get(self, resource_id):
@umaparvat
umaparvat / dip_violation.py
Last active June 11, 2023 13:53
dependency inversion principle
import requests as req
import os
class Backend:
def get(self, full_str):
res = req.get(url=os.environ.get("uri")+full_str)
if res.status_code == 200:
return res.json().get("status")
raise Exception(message=str(res.json()))
from abc import ABC, abstractmethod
import sqlalchemy as db
from sqlalchemy.orm import sessionmaker
engine = db.create_engine("sqlite:///example.db")
Session = sessionmaker(bind=engine)
session = Session()
class IDataService(ABC):
@umaparvat
umaparvat / isp_violation.py
Last active May 23, 2023 17:03
Interface segregation principle violation
from abc import ABC, abstractmethod
import sqlalchemy as db
from sqlalchemy.orm import sessionmaker
engine = db.create_engine("sqlite:///example.db")
Session = sessionmaker(bind=engine)
session = Session()
class DatabaseService:
from abc import ABC, abstractmethod
class IMince(ABC):
@abstractmethod
def mince(self, item):
raise NotImplementedError
@umaparvat
umaparvat / lsp_violation.py
Created May 23, 2023 16:12
liskov substitution principle
class FoodProcessor:
def chop(self, item):
# code logic to chop the items
print(f"chopping the {item}")
def mince(self, item):
# code logic to mince the items
print(f"Minicing the {item}")
@umaparvat
umaparvat / grokking_to_leetcode.md
Created May 21, 2022 12:16 — forked from tykurtz/grokking_to_leetcode.md
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

@umaparvat
umaparvat / grokking_to_leetcode.md
Created May 17, 2022 01:26
Grokking the coding interview equivalent leetcode problems

EDIT: Forked the original list and added suggestions from comments

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window