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 / logger.py
Created February 13, 2024 10:11
Python Logger
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
@deepanshumehtaa
deepanshumehtaa / test.py
Last active December 21, 2023 11:59
pytest
class SomeDataClass:
url_img1 = (
"https://test-m-invoice.s3.amazonaws.com/ttl-public/images/valid+image.jpg"
)
url_img2 = (
"http://s3.pdd-1623763075688.jpeg"
)
@deepanshumehtaa
deepanshumehtaa / pydantic.py
Last active November 21, 2023 21:14
Pydantic Hack
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:
@deepanshumehtaa
deepanshumehtaa / useReducer.jsx
Last active November 5, 2023 13:35
useReducer
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
// npm install axios
import axios from 'axios';
import { useEffect, useState } from 'react';
export default function StudentDataCompoenet(){
const [data, setData] = useState([]);
@deepanshumehtaa
deepanshumehtaa / MyScrapy.py
Last active March 1, 2024 04:27
Scrapy boilerPlate
import re
import scrapy
from scrapy.http import Request, Response
class MyscraperSpider(scrapy.Spider):
"""
> scrapy runspider MyScraper.py -o quotes.jsonl
"""
@deepanshumehtaa
deepanshumehtaa / main.go
Created October 8, 2023 12:18
Go-mux-server
// go run .
package main
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"net/http"
// go run main.go
// create a static folder and create `static.html`
package main
import (
"fmt"
"log"
"net/http"
)
@deepanshumehtaa
deepanshumehtaa / main.go
Last active October 1, 2023 14:31
Simple Gin App
/*
create `go.mod` (requirements.txt of go):
> go mod init myApp/web-service-gin
then run
> go get github.com/gin-gonic/gin
> github.com/thoas/go-funk
create `main.go`
@deepanshumehtaa
deepanshumehtaa / CountDownSolution.jsx
Last active July 31, 2024 11:03
React CountDown Timer
import React, { Fragment } from 'react';
import { useState, useEffect } from 'react';
export default function Solution() {
const [totalSeconds, setTotalSeconds] = useState(0);
const [isPaused, setPaused] = useState(true); // Start with paused state
const [time_str, setTime_str] = useState("00:00");
function MyStart() {
let seconds = parseInt(document.getElementById("secs").value);