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 / Exception Handler Java.java
Last active April 24, 2024 07:28
Exception Handler Java
3 steps:
1. create custom errors and sxtend from `RuntimeException`
2. create a global Exception Handler
3. directly throw the exception from anywhere
.................................................................................................................
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class BadReq extends RuntimeException {
@deepanshumehtaa
deepanshumehtaa / My Wix Component.js
Last active April 29, 2024 07:20
My Wix Component
import wixdata from 'wix-data';
import wixWindowFrontend from 'wix-window-frontend';
let collection = "";
let x_axis_field = null;
let y_axis_field = null;
let animationDuration = 1000;
let chartData = {};
let chartClass = ".LCNC-Charts"
let toggleGrid = {
@deepanshumehtaa
deepanshumehtaa / charts.js
Last active May 9, 2024 02:51
charts.js
console.log("chart called");
const plu = {
htmlLegend: {
// ID of the container to put the legend in
containerID: 'legend-container',
},
legend: {
display: true,
@deepanshumehtaa
deepanshumehtaa / db.py
Last active February 9, 2025 14:38
db.py
/**
sudo mysql -u root
> CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';
> ALTER USER 'sammy'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
> GRANT ALL PRIVILEGES ON dbTest.* To 'user'@'hostname' IDENTIFIED BY 'password';
> FLUSH PRIVILEGES;
> mysql://deepanshu:deepanshu@localhost:3306/my_db
**/
@deepanshumehtaa
deepanshumehtaa / populate_db_pandas.py
Last active July 28, 2024 14:47
populate_db_pandas.py
from db_connector import SQLHelper
import pandas as pd
chunk_size = 20 # Number of rows in chunks
chunks = []
file_name = 'customers-100.csv'
for chunk in pd.read_csv(file_name, chunksize=chunk_size, delimiter=","):
df: pd.DataFrame = chunk
@deepanshumehtaa
deepanshumehtaa / python_timed_cache.py
Last active January 20, 2025 08:34
python_timed_cache.py
import time
from functools import wraps
def timed_cache(expiration):
cache = {}
def decorator(func):
@wraps(func)
def wrapper(*args):
now = time.time()
@deepanshumehtaa
deepanshumehtaa / Java Rest Template.java
Last active February 5, 2025 19:57
Java Rest Template.java
package com.example.DemoApp.service;
import com.example.DemoApp.Dtos.BirdDTO;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.modelmapper.ModelMapper;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.*;
@deepanshumehtaa
deepanshumehtaa / Start ReactJS + Vite
Last active April 9, 2025 19:22
Start ReactJS + Vite
Vite is a fast and efficient WebD build tool to build and serve web apps
1. instant server start and fast code reloading make development a breeze.
2. PROD builds are optimized for performance, resulting in smaller bundle sizes and faster load times.
3. not work seamlessly with older browsers.
4. Hot Module Replacement (HMR) is a feature that allows developers to update and reload individual modules (e.g., JavaScript files) without requiring a full page reload.
This enables a faster and more efficient development experience.
Install Node (Linux)
@deepanshumehtaa
deepanshumehtaa / Enums Python.py
Last active March 5, 2025 05:20
Enums Python.py
from enum import Enum
class Xyz(Enum):
"""Xyz._member_map_.values()"""
A = 100
B = 200
# Key: Pair of Enums
map = Xyz._member_map_
@deepanshumehtaa
deepanshumehtaa / SSE - Server-Sent Events
Last active March 5, 2025 05:18
SSE - Server-Sent Events
what is the time duration of SSE for keep-alive connection ?
The time duration of an SSE (Server-Sent Events) keep-alive connection can vary depending on several factors, including:
Server configuration: The server can specify a keep-alive timeout using the Keep-Alive header or other configuration settings.
Client configuration: The client can also specify a keep-alive timeout using the Keep-Alive header or other configuration settings.
Network conditions: Network conditions, such as latency and packet loss, can affect the keep-alive timeout.
Typically, the keep-alive timeout for SSE connections ranges from a few seconds to several minutes. Here are some common values:
Default timeout: 30 seconds to 1 minute
Typical timeout: 1-5 minutes
Maximum timeout: 30 minutes to 1 hour