Skip to content

Instantly share code, notes, and snippets.

View cuongitl's full-sized avatar

Kaizen cuongitl

View GitHub Profile
@cuongitl
cuongitl / python_mysql_connector.md
Created July 12, 2021 04:53
Mysql connector with python

First of all you have to start your xamp server

Install Package

pip install mysql-connector-python

Connection Establishment Code

@cuongitl
cuongitl / python_flask_nginx_befhind_cloudflare.conf
Created September 15, 2021 09:02
python flask nginx behind cloudflare
# https://support.cloudflare.com/hc/en-us/articles/200170786-Restoring-original-visitor-IPs#C5XWe97z77b3XZV
server {
server_name lecuong.info;
listen *:80;
client_max_body_size 100M;
proxy_read_timeout 600s;
proxy_buffers 16 4k;
proxy_buffer_size 2k;
location ^~ /.well-known/acme-challenge/ {
@cuongitl
cuongitl / python-flask-catch-all route.py
Created June 21, 2022 13:16
Python Flask Catch-all route
"""It may be useful to have one catch-all view where you handle complex logic yourself based on the path.
This example uses two rules:
- First rule specifically catches
- Second rule catches arbitrary paths with the built-in path converter.
The path converter matches any string (including slashes)."""
@app.route('/', defaults={'u_path': ''})
@app.route('/<path:u_path>')
def catch_all(u_path):
print(repr(u_path))
@cuongitl
cuongitl / python-call-an-async-function-contained-in-a-class.md
Created July 14, 2024 08:42
How to call a async function contained in a class

How to call a async function contained in a class?

#!/usr/bin/env python3

import sys, json
import asyncio
from websockets import connect
@cuongitl
cuongitl / python-dynamically-choose-the-database-and-table-based-on-input-with-SQLAlchemy.py
Created August 28, 2024 14:30
python-dynamically-choose-the-database-and-table-based-on-input-with-SQLAlchemy
"""
** SQLAlchemy with dynamically input:
- table
- db_url
This is creating a factory function to dynamically choose the database URL and table based on input,
dynamically creating the engine and session based on the input,
then dynamically loading the appropriate model.
** Install packages:
pip install sqlalchemy pymysql
@cuongitl
cuongitl / mariadb_install.sh
Created October 27, 2024 07:12
Shell Script to install MariaDB on Linux
#!/usr/bin/env bash
# exit on error
set -o errexit
params_file='params.ini'
#Including .ini file
. $params_file
if [ ! -f $params_file ]; then
@cuongitl
cuongitl / Get-ADGroupbyUser.ps1
Created November 8, 2024 07:03
How to get all groups that a user is a member of?
# Set the username for which to fetch the groups
# Usage: Get-memberOf-User.ps1 <username>
param (
[string]$username
)
# If no username is provided, prompt the user for input
if (-not $username) {
Write-Host "Please provide a username as an argument."
exit
@cuongitl
cuongitl / install-vnstat.sh
Created November 11, 2024 04:18
Shell Script to auto install vnStat on Linux
#!/bin/bash
# Built with ❤️ by Cuongitl (LE VAN CUONG)
# Telegram: https://t.me/Cuongitl
# Filename: install-vnstat.sh
# Modified: 2024-11-11
# Purpose: Install vnStat - a network traffic monitor for Linux
# Exit the script if any command fails
set -o errexit
# Define the version of vnStat here
@cuongitl
cuongitl / get_vbr_repos_to_json.ps1
Created November 27, 2024 03:20
Veeam: Powershell get Backup Repository Information: Returns a list of backup repositories.
# Veeam: Powershell get Backup Repository Information: Returns a list of backup repositories.
# Get-VBRBackupRepository | Format-List *
#Get-VBRBackupRepository |
# Select-Object Name, Id, Type, @{Name="Path";Expression={$_.Path.ToString()}}, Description |
# ConvertTo-Json -Depth 3
Get-VBRBackupRepository |
Select-Object Name,
Id,
@{Name="Type"; Expression={
@cuongitl
cuongitl / get_vbr_repos_to_json_v2.ps1
Created November 27, 2024 08:47
Powershell: getVeeam Backup & Replication's Repository Information
# Veeam: Powershell get Backup Repository Information: Returns a list of backup repositories.
# version 02
# Define the function
function Get-VBRBackupRepositoryDetails {
$Repos = Get-VBRBackupRepository
$RepoDetails = foreach ($repo in $Repos) {
[PSCustomObject]@{
'Name' = $repo.Name
'ID' = $repo.ID