Skip to content

Instantly share code, notes, and snippets.

View NothingCtrl's full-sized avatar

Thang Duong Bao NothingCtrl

View GitHub Profile
@NothingCtrl
NothingCtrl / test_speed_JSON_SQLITE.py
Created December 22, 2019 16:53
Test a simple database by using JSON file vs SQLITE
import json
import sqlite3
import string
import random
import os
import time
dir_path = os.path.dirname(os.path.realpath(__file__))
def randomString(stringLength=10):
@NothingCtrl
NothingCtrl / subsync.py
Last active March 12, 2020 16:00
Sync subtile, ex: python sybsync.py -s "path/to/subtitle" -t 1000
# -*- coding: utf-8 -*-
# Sync subtitle
# author: thang@camratus.com
# addition package: chardet
# Usage:
# to make subtitle slower 1000 millisecond: python sybsync.py -s "path/to/subtitle" -t 1000
# to make subtitle faster 1000 millisecond: python sybsync.py -s "path/to/subtitle" -t -1000
import os
import argparse
@NothingCtrl
NothingCtrl / pysyslog.py
Created March 15, 2020 14:15 — forked from marcelom/pysyslog.py
Tiny Python Syslog Server
#!/usr/bin/env python
## Tiny Syslog Server in Python.
##
## This is a tiny syslog server that is able to receive UDP based syslog
## entries on a specified port and save them to a file.
## That's it... it does nothing else...
## There are a few configuration parameters.
LOG_FILE = 'youlogfile.log'
@NothingCtrl
NothingCtrl / python_encrypt_decrypt_example.py
Created June 6, 2020 16:45
Example encrypt - decrypt string with unicode
import base64
import hashlib
from Crypto import Random
from Crypto.Hash import SHA256
from Crypto.Cipher import AES
from cryptography.fernet import Fernet
def encrypt(message: bytes, key: bytes) -> bytes:
return Fernet(key).encrypt(message)
@NothingCtrl
NothingCtrl / error.log
Created June 16, 2020 03:58
OpenAPI test create new user error message
{"error": {"message": "Odoo Server Error", "data": {"name": "werkzeug.exceptions.HTTPException", "debug": "Traceback (most recent call last):\n File \"/mnt/odoo-extra/runbot/static/build/25065-13-0-eeeb39/odoo/addons/openapi/controllers/apijsonrequest.py\", line 108, in _handle_exception\n return super(ApiJsonRequest, self)._handle_exception(exception)\n File \"/mnt/odoo-extra/runbot/static/build/25065-13-0-eeeb39/odoo/http.py\", line 310, in _handle_exception\n raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n File \"/mnt/odoo-extra/runbot/static/build/25065-13-0-eeeb39/odoo/tools/pycompat.py\", line 14, in reraise\n raise value\n File \"/mnt/odoo-extra/runbot/static/build/25065-13-0-eeeb39/odoo/addons/openapi/controllers/apijsonrequest.py\", line 159, in dispatch\n result = self._call_function(**self.params)\n File \"/mnt/odoo-extra/runbot/static/build/25065-13-0-eeeb39/odoo/http.py\", line 350, in _call_function\n return checked_call(self.db, *args, **kwargs)\n Fi
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-resource
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
@NothingCtrl
NothingCtrl / nginx-tuning.md
Created August 16, 2020 15:15 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@NothingCtrl
NothingCtrl / miner_process_kill.py
Last active February 16, 2022 11:06
Kill process of Kinsing miner virus
# -*- coding: utf-8 -*-
# Create: 07.12.2020
# Author: nothingctrl (nothingctrl@gmail.com)
# ---------------------------------------------------------------------------------------------------------------------
# Detect mail server (Zimbra) inject by miner virus name `kinsing`
# this virus use all CPU resource and have some behaviour:
# - Create a crontab as zimbra to download .sh script using wget
# - Download / create execute file in /var/tmp, /tmp, /opt/zimbra/log/
# - Run process with name: `kinsing...`, `kdevtmpfsi...`
# - In log file `/opt/zimbra/log/zmmailboxd.out`, every time virus file create, have a log: `/opt/zimbra/log/kinsing...`
@NothingCtrl
NothingCtrl / get_datetime_by_time_zone.py
Created November 19, 2021 04:23
Python: get current datetime object by timezone
from datetime import datetime
from dateutil import tz
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('Asia/Ho_Chi_Minh')
utc = datetime.utcnow()
# Tell the datetime object that it's in UTC time zone since
# datetime objects are 'naive' by default
@NothingCtrl
NothingCtrl / network_status_check.py
Created November 29, 2021 02:03
Check for network status by request a URL (eg: LAN router URL), if not success, reboot OS or refresh interface
import ssl
import urllib.request
import time
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--url", "-u", help="URL to check for network status")
parser.add_argument("--refresh-interface", "-ri", help="Name interface to refresh (Windows only), if not set, will call OS reboot if network status check failed")
args = parser.parse_args()