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
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
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
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
// npm install axios | |
import axios from 'axios'; | |
import { useEffect, useState } from 'react'; | |
export default function StudentDataCompoenet(){ | |
const [data, setData] = useState([]); |
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 re | |
import scrapy | |
from scrapy.http import Request, Response | |
class MyscraperSpider(scrapy.Spider): | |
""" | |
> scrapy runspider MyScraper.py -o quotes.jsonl | |
""" |
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
// go run . | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"math/rand" | |
"net/http" |
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
// go run main.go | |
// create a static folder and create `static.html` | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) |
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
/* | |
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` |
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 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); |