Skip to content

Instantly share code, notes, and snippets.

View deepanshumehtaa's full-sized avatar
💭
If Good things are not coming to you, Snatch them™

Deepanshu mehta deepanshumehtaa

💭
If Good things are not coming to you, Snatch them™
View GitHub Profile
@deepanshumehtaa
deepanshumehtaa / SQL Tricks WINDOWS.sql
Last active March 18, 2024 04:58
SQL Tricks. WINDOWS
> Subtract two months from a date, then return the new date
SELECT DATEADD(month, -2, '2017/08/25') AS DateAdd;
> https://www.w3schools.com/sql/func_sqlserver_dateadd.asp
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
ELSE result
END
@deepanshumehtaa
deepanshumehtaa / SQL Tricks Sub Query & CTE.sql
Last active March 18, 2024 14:21
SQL Tricks Sub Query & CTE
https://console.clever-cloud.com/users/me/addons/addon_1315c43c-935c-4889-b9ab-1c64f93bcf61
Database@123
SQL execution:
FROM --> WHERE --> GROUP BY --> HAVING --> SELECT --> ORDER BY
1. WITH also known as a Common Table Expression (CTE):
> powerful tool for simplifying complex SQL queries and improving query readability.
WITH cte_name (column1, column2, ...) AS (
@deepanshumehtaa
deepanshumehtaa / React Js Practice.js
Last active March 15, 2024 14:39
React Js Practice
TWO Rules for writing component function in ReactJS:
1. should start with Upper case char
2. should return that could be render on the screen
ex:
"""
from MyComp import "./App.jsx";
export default function MyReducerComp(){
const [count, dispatchCount] = useReducer(reducerFunc, 0);
@deepanshumehtaa
deepanshumehtaa / sqlalchemy.py
Last active March 14, 2024 14:06
sqlalchemy
https://chat.openai.com/share/3f1472a2-ff59-4b88-bec4-36c75421e3ed
"""
from sqlalchemy import (
Column, BigInteger, Integer, String, Text, ForeignKey, Uuid, Enum, DateTime, CheckConstraint,
)
from sqlalchemy import func, select
from sqlalchemy.sql.expression import (
case as sql_case,
cast as sql_cast,
@deepanshumehtaa
deepanshumehtaa / Singleton Aiohttp.py
Last active March 10, 2024 07:20
Singleton Aiohttp
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
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;
}
@deepanshumehtaa
deepanshumehtaa / PySpark.py
Last active March 19, 2024 19:30
PySpark
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
@deepanshumehtaa
deepanshumehtaa / django advanced queryset.py
Last active March 7, 2024 10:05
django advanced queryset
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)
<!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;
@deepanshumehtaa
deepanshumehtaa / Bulk Insert Update.py
Created February 22, 2024 14:04
Bulk Insert Update
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()