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 functools import wraps | |
# Defining our custom decorator | |
def my_decorator(function): | |
@wraps(function) | |
def wrapper(a, b, c): | |
print("wrapper running!") | |
a += 1 | |
b += 2 |
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 flask import Flask | |
from flask import session, g | |
app = Flask(__name__) | |
app.secret_key = "iufh4857o3yfhh3" | |
@app.before_first_request | |
def before_first_request_func(): |
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 base64 | |
""" | |
step 1. python -m compileall app.py | |
step 2. run python with compiled files | |
python __pycache__/app.cpython-39.pyc | |
""" | |
def encode_message(msg): |
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
# Python code to convert video to audio | |
import moviepy.editor as mp | |
def convert_mp4_to_mp3(): | |
print("convert".center(20, "#")) | |
# Insert Local Video File Path | |
clip = mp.VideoFileClip("videoplayback.mp4") | |
# get duration file video in seconds | |
duration = clip.duration |
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 dataclasses import dataclass | |
@dataclass() | |
class Hobby: | |
name: str = None | |
@dataclass() | |
class Student: |
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 collections import namedtuple | |
HobbyNameTuple = namedtuple("Hobby", ["name"]) | |
StudentNameTuple = namedtuple("Student", ["name", "age", "hobby"]) | |
if __name__ == "__main__": | |
h = HobbyNameTuple("swimming") | |
s = StudentNameTuple("John toer", 18, [h._asdict()]) | |
result = s._asdict() |
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
type Hobby struct { | |
Name string `json:"name"` | |
} |
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 json | |
import http.server | |
import socketserver | |
from typing import Tuple | |
from http import HTTPStatus | |
class Handler(http.server.SimpleHTTPRequestHandler): | |
def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer): |
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
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md | |
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192 | |
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB. | |
------------ | |
-- Basics -- | |
------------ | |
-- Get indexes of tables |