Skip to content

Instantly share code, notes, and snippets.

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
NAL_BREAKER = b'\x00\x00\x00\x01'
def rtspsrc_pad_added(element, pad, target):
caps = pad.query_caps(None).to_string()
@ak64th
ak64th / gstreamer_rtsp_to_mp4.py
Last active June 15, 2023 10:57
Save rtsp video stream data into a .mp4 file without sounds, re-encoding with libx264.
import sys
import gi
gi.require_version('Gst', '1.0')
def rtspsrc_pad_added(element, pad, target):
caps = pad.query_caps(None).to_string()
if caps.startswith('application/x-rtp, media=(string)video'):
@ak64th
ak64th / train_with_imgaug.py
Created September 29, 2021 04:03
Use imgaug with detectron2
import argparse
import copy
import os
import pathlib
from datetime import datetime
import imgaug.augmenters as iaa
import imgaug.random as ia_random
import numpy as np
import torch
@ak64th
ak64th / htpasswd.py
Created September 14, 2021 07:08 — forked from eculver/htpasswd.py
htpasswd script in python (no need to install apache utils)
#!/usr/local/bin/python
"""Replacement for htpasswd"""
# Original author: Eli Carter
import os
import sys
import random
from optparse import OptionParser
# We need a crypt module, but Windows doesn't have one by default. Try to find
@ak64th
ak64th / config.dev.toml
Last active June 30, 2021 08:38
Settings deserialization for python: pydantic vs attrs+cattrs
secret_key = "3EEeX_v1exDXdE79CbLVDpQB4F1dmxm2cOC0eQB7Q1k="
[hops.aliyun]
ip = "112.112.112.2"
username = "kingo"
[hops.pi]
ip = "10.10.100.2"
username = "pi"
@ak64th
ak64th / mqtt_monitor.py
Last active January 9, 2020 10:00
Use hbmqtt with prompt_toolkit
import asyncio
import logging
from hbmqtt.client import MQTTClient, ClientException
from hbmqtt.mqtt.constants import QOS_0
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout import Layout
from prompt_toolkit.widgets import Frame, TextArea
from natsort import natsorted
@ak64th
ak64th / imap_login.py
Last active November 28, 2019 05:53
Use imaplib with socks proxy
# install PySocks first: pip install PySocks
import socket
import socks
import imaplib
socks.set_default_proxy(socks.SOCKS5, "localhost")
socket.socket = socks.socksocket
m = imaplib.IMAP4_SSL("imap.gmail.com")
@ak64th
ak64th / triple_des_decryption.py
Last active September 10, 2019 10:22
Use Triple DES with python. Package `cryptography` or `pyDes` is required.
import base64
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.padding import PKCS7
backend = default_backend()
ct = b'iWdEgY1YmHSjoW13UIQ52w==' # base64 encoded ciphertext
secret = b'olQFK9LzdoGnPcwBcBhvy8rG'
@ak64th
ak64th / unzip.sh
Created October 6, 2018 10:06
unzip files with unicode filenames
#! /bin/sh
LANG=C /usr/bin/7z x -y "$1" | sed -n 's/^Extracting //p' | sed '1!G;h;$!d' | xargs convmv -f gbk -t utf8 --notest &>/dev/null
@ak64th
ak64th / MySQL Replication Check
Created May 25, 2018 09:00 — forked from ssimpson89/MySQL Replication Check
Just a simple Mysql Replication Health Check script I wrote. You can put this in a cron.
#!/bin/bash
### VARIABLES ### \
EMAIL=""
SERVER=$(hostname)
MYSQL_CHECK=$(mysql -e "SHOW VARIABLES LIKE '%version%';" || echo 1)
LAST_ERRNO=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Last_Errno" | awk '{ print $2 }')
SECONDS_BEHIND_MASTER=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G"| grep "Seconds_Behind_Master" | awk '{ print $2 }')
IO_IS_RUNNING=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Slave_IO_Running" | awk '{ print $2 }')
SQL_IS_RUNNING=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Slave_SQL_Running" | awk '{ print $2 }')