Skip to content

Instantly share code, notes, and snippets.

@feiandxs
feiandxs / isEmail.js
Created April 17, 2024 03:03
validate email, not that simple
/*
Check if a string is in valid email format.
Returns true if valid, false otherwise.
*/
function isEmail(str)
{
var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])
@feiandxs
feiandxs / tencent_translation_example.py
Created August 20, 2023 10:45
使用腾讯交互翻译API进行自动翻译的示例代码
"""
该脚本演示了如何使用翻译API进行自动翻译。
它生成翻译请求的JSON,发送请求到API端点,并打印翻译结果。
脚本使用Pydantic库定义请求和响应模型,确保数据验证和类型安全。
它还包括生成客户端密钥、生成翻译请求JSON和发送翻译请求的函数。
翻译请求JSON包括源语言、目标语言和要翻译的文本列表。
响应包含翻译后的文本。
@feiandxs
feiandxs / timer.py
Created June 29, 2022 09:23
timer.py
'''
Date: 2022-06-01 13:49:12
LastEditors: ibegyourpardon
LastEditTime: 2022-06-01 13:52:47
FilePath: /undefined/Users/feiandxs/Downloads/timer.py
'''
import time
class TimerError(Exception):
"""
'''
Date: 2022-06-01 15:25:41
LastEditors: ibegyourpardon
LastEditTime: 2022-06-01 15:29:35
FilePath: /undefined/Users/feiandxs/Downloads/8.py
'''
import datetime
eta_temp = '2022-06-01 13:15:02'
@feiandxs
feiandxs / number_to_hanzi.py
Created June 10, 2022 05:53
数字转汉字
han_list = ["零" , "一" , "二" , "三" , "四" , "五" , "六" , "七" , "八" , "九"]
unit_list = ["","","十" , "百" , "千"]
def four_to_han(num_str: str):
result = ""
num_len = len(num_str)
for i in range(num_len):
num = int(num_str[i])
if i!=num_len-1:
if num!=0:
@feiandxs
feiandxs / delete_pycache_dir.py
Created April 1, 2022 10:01
delete all pycache directory
import os
def clear(filepath):
files = os.listdir(filepath)
for fd in files:
cur_path = os.path.join(filepath, fd)
if os.path.isdir(cur_path):
if fd == "__pycache__":
print("rm %s -rf" % cur_path)
os.system("rm %s -rf" % cur_path)
@feiandxs
feiandxs / gufeng_word_generator.py
Created January 21, 2022 08:28
一个没啥用的古风生成器
'''
Date: 2022-01-21 16:11:31
LastEditors: ibegyourpardon
LastEditTime: 2022-01-21 16:25:48
'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# feiandxs
@feiandxs
feiandxs / ffmpeg-commands-list.md
Last active June 15, 2022 03:04
FFmpeg commands

There are too many ffmpeg parameters, but there is no need to remember them.

Use 'convert FormatA to FormatB' to search.

convert jpeg to gif

ffmpeg -i A.jpeg A.gif

convert png to gif

@feiandxs
feiandxs / fastapi_export_xls.py
Created August 16, 2021 05:33
fastapi输出xls 下载
from fastapi import FastAPI
from fastapi.responses import Response
import xlwt
from io import BytesIO
app = FastAPI()
@app.get("/")
@feiandxs
feiandxs / reporter.sh
Created February 1, 2021 05:42 — forked from archichen/reporter.sh
一行命令生成所有占用端口及其进程报告|Generate a report for all occupied port and their program with a line command
# Choose one command, Copy it and execute, no need for execute reporter.sh file.
# Report file was place at /tmp/reporter.csv|md
# CSV version
# Preview: https://imgur.com/c5E0T1v
netstat -ntlp | awk 'BEGIN{ system("echo IP, Port, PID, Parameter > /tmp/reporter.csv") } NR>2 {if($4 !~ "::" && $7 != "-"){split($4,ipAndPort,":"); split($7,pidAndProgress,"/"); system("echo "ipAndPort[1]","ipAndPort[2]","pidAndProgress[1]", `cat /proc/"pidAndProgress[1]"/cmdline` >> /tmp/reporter.csv")}}'
# Markdown version
# Preview: https://imgur.com/ivmUhgu
netstat -ntlp | awk 'BEGIN{ system("echo \\|IP\\|Port\\|PID\\|Parameter\\| > /tmp/reporter.md; echo \\|-\\|-\\|-\\|-\\| >> /tmp/reporter.md") } NR>2 {if($4 !~ "::" && $7 != "-"){split($4,ipAndPort,":"); split($7,pidAndProgress,"/"); system("echo \\|"ipAndPort[1]"\\|"ipAndPort[2]"\\|"pidAndProgress[1]"\\|`cat /proc/"pidAndProgress[1]"/cmdline`\\| >> /tmp/reporter.md")}}'