This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useReducer } from "react"; | |
// where we need to manage multiple states | |
// and one solution for multiple states reduce to one i.e. `reducer` | |
function reducerFunc(state, action){ | |
if(action.type === "INC"){ | |
return state + 1 | |
} else if (action.type === "DEC"){ | |
return state - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import BaseModel | |
from typing import Generic | |
Generics ............................................................ | |
T = TypeVar("T") | |
class SuccessResponseModel(BaseModel, Generic[T]): | |
""" | |
now we don't need to define multiple Success model for like `Items`, `User`, etc | |
just use this like: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeDataClass: | |
url_img1 = ( | |
"https://test-m-invoice.s3.amazonaws.com/ttl-public/images/valid+image.jpg" | |
) | |
url_img2 = ( | |
"http://s3.pdd-1623763075688.jpeg" | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
class ColoredFormatter(logging.Formatter): | |
RESET_CODE = '\033[0m' # Reset color | |
COLOR_CODES = { | |
'DEBUG': '\033[94m', # Blue | |
'INFO': '\033[92m', # Green | |
'WARNING': '\033[93m', # Yellow | |
'ERROR': '\033[91m', # Red |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bulk Insert: | |
def bulk_insert(self, sql, sql_parameters, batch_size=1000): | |
for i in range(0, len(sql_parameters), batch_size): | |
batch = sql_parameters[i:i+batch_size] | |
cursor = self.get_connection_cursor() | |
cursor.executemany(sql,batch) | |
self.connection.commit() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Welcome Page</title> | |
<style> | |
body { | |
background-color: #f0f0f0; | |
font-family: Arial, sans-serif; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m2m | |
class Post(models.Model): | |
slug = models.SlugField(max_length=200, unique=True) | |
likes = models.ManyToManyField(User, related_name='blogpost_like', blank=True) | |
post = get_object_or_404(Post, slug=slug) | |
if post.likes.filter(id=request.user.id).exists(): | |
post.likes.remove(request.user) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lect 0: https://colab.research.google.com/drive/1crwg2yOosVEQATTlMfPe-FdiQKZF-gFN?usp=sharing | |
lec 1: https://drive.google.com/file/d/1_H5jhUut-DPjT5U0vmgCkg30DKZCa_-G/view?usp=sharing | |
lect 2: https://colab.research.google.com/drive/1DxeRBxRaqENX-HnxqSj-fexuRxBaTp9R?usp=sharing | |
lect 3: https://colab.research.google.com/drive/1fzTxGc0ttQeUV4D4VQf0zYDSOb6gDkoH?usp=sharing | |
databrick NB: https://databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/6073444084857434/2270297475493747/7614095282524650/latest.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adaptable: | |
1. Responsive (Adaptable): | |
- web application is designed to adapt and respond to different screen sizes, resolutions, and orientations. | |
- CSS media queries. | |
/* Responsive styles */ | |
@media screen and (max-width: 768px) { | |
/* Adjust styles for screens up to 768px wide */ | |
.container { | |
padding: 10px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from collections.abc import Coroutine | |
from socket import AF_INET | |
# AF_INET specifies the Internet address family for IPv4. | |
from typing import List, Optional, Any, Dict | |
import aiohttp | |
from fastapi import FastAPI | |
from fastapi.logger import logger as fastAPI_logger # convenient name |