Skip to content

Instantly share code, notes, and snippets.

View NothingCtrl's full-sized avatar

Thang Duong Bao NothingCtrl

View GitHub Profile
@NothingCtrl
NothingCtrl / remove_vietnamese_accents.py
Created November 21, 2023 04:50
(Python) Remove Vietnamese accents in text
import re
import unicodedata
def remove_vietnamese_accents(input_str: str) -> str:
# normalize input to unicode composed
input_str = unicodedata.normalize('NFC', input_str)
s1 = 'ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚÝàáâãèéêìíòóôõùúýĂăĐđĨĩŨũƠơƯưẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặẸẹẺẻẼẽẾếỀềỂểỄễỆệỈỉỊịỌọỎỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợỤụỦủỨứỪừỬửỮữỰựỲỳỴỵỶỷỸỹ'
s0 = 'AAAAEEEIIOOOOUUYaaaaeeeiioooouuyAaDdIiUuOoUuAaAaAaAaAaAaAaAaAaAaAaAaEeEeEeEeEeEeEeEeIiIiOoOoOoOoOoOoOoOoOoOoOoOoUuUuUuUuUuUuUuYyYyYyYy'
s = ''
for c in input_str:
@NothingCtrl
NothingCtrl / 2871.vietnamese.word.txt
Created November 2, 2023 03:02
2871.vietnamese.word.txt
ai
am
an
anh
ba
ban
bang
bao
bay
be
@NothingCtrl
NothingCtrl / cloudflare_proxy.py
Last active October 19, 2023 17:11
Set proxy ON / OFF for selected domain on CloudFlare DNS
# Python 3.6+
# Required library: requests
import json
import requests
import os
import sys
from sys import exit
if getattr(sys, 'frozen', False):
# frozen
@NothingCtrl
NothingCtrl / pfsense_toggle_captive_portal.py
Created September 15, 2023 07:14
Toggle a captive portal on PfSense
# +-----------------------------------------+
# | PFSENSE PORTAL TOGGLE |
# +-----------------------------------------+
# This script is used to automatic toggle a captive portal on pfSense
# Requirements: Python 3.x, additional packages: html_form_to_dict, requests, six
# ---
# Adapt these variables with your server config:
# - pfsense_url: the base url of pfSense (include port, example: https://1.2.3.4:1234)
# - portal_name: name of portal to toggle
# - admin_username: the user account that is allowed to login to pfSense and change the configuration of the captive portal
@NothingCtrl
NothingCtrl / docker-compose.yml
Created September 6, 2023 08:28
Docker compose for `croc` relay server
version: '3.1'
services:
croc-relay:
image: schollz/croc
restart: always
container_name: croc-relay
ports:
- 9009-9013:9009-9013
@NothingCtrl
NothingCtrl / xoa_dau.md
Created August 9, 2023 17:11 — forked from phineas-pta/xoa_dau.md
xoá dấu tiếng Việt với Python

xoá dấu tiếng Việt với Python

phương pháp nhanh hơn và không cần cài thêm package

code hoàn chỉnh:

import unicodedata

BANG_XOA_DAU = str.maketrans(
@NothingCtrl
NothingCtrl / dev_xml_id.py
Last active August 3, 2023 05:16
Get XML ID of menu or action view in Odoo (OpenERP)
# -*- coding: utf-8 -*-
import os
from psycopg2 import connect
import sys
import logging
_logger = logging.getLogger(__name__)
DB_NAME = "demo_db"
DB_USER = 'odoo'
@NothingCtrl
NothingCtrl / watchdog_example.py
Created July 7, 2023 08:41
(Python) Using watchdog module example
import sys
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class WatchDogEventHandler(FileSystemEventHandler):
def on_modified(self, event):
print(f'event type: {event.event_type} path : {event.src_path}')
def on_created(self, event):
@NothingCtrl
NothingCtrl / file_md5.py
Created June 12, 2023 09:27
Get file md5 hash
# python3
import sys
import hashlib
import os
def file_hash_info(file_path: str):
with open(file_path, "rb") as f:
file_hash = hashlib.md5()
while chunk := f.read(8192):
file_hash.update(chunk)
@NothingCtrl
NothingCtrl / wait-for-remote-host.sh
Created May 30, 2023 07:24
Delay command execute until remote host available
#!/bin/bash
REMOTE_HOST=$1
REMOTE_PORT=$2
TIMEOUT=1
shift 2
cmd="$@"
if [ -n "$REMOTE_HOST" ] && [ -n "$REMOTE_PORT" ]; then
while ! nc -w $TIMEOUT -z $REMOTE_HOST $REMOTE_PORT; do
>&2 echo "Wait for remote host $REMOTE_HOST:$REMOTE_PORT"