Skip to content

Instantly share code, notes, and snippets.

@heimoshuiyu
heimoshuiyu / walk_file.py
Last active October 14, 2017 00:48
walk_file_function
import os, os.path
def do_dir(file): #What you want to do with the file
pass
def do_file(file): #What you want to do with the
pass
def walk(where): #Walk file and dir in where
for localtion,dirlist,filelist in os.walk(where):
if dirlist:
@heimoshuiyu
heimoshuiyu / openssl.sh
Created April 16, 2021 07:13
openssl 用例
# 生成私钥
openssl genrsa -out myselfsigned.key 2048
# 利用私钥生成自签名证书
openssl req -new -x509 -key myselfsigned.key -out myselfsigned.cer -days 36500
# 利用私钥生成自签名证书,直接指定CN
openssl req -new -x509 -key myselfsigned.key -out myselfsigned.cer -days 36500 -subj /CN="*.abc.com"
# 创建一个CA的私钥和CA的证书
@heimoshuiyu
heimoshuiyu / python-docx-replace-text-and-retain-style.py
Last active February 6, 2023 15:31 — forked from adejones/python-docx-replace-text-and-retain-style.py
Updated to support if key across multiple runs
def shuttle_text(shuttle):
t = ''
for i in shuttle:
t += i.text
return t
def docx_replace(doc, data):
for key in data:
for table in doc.tables:
@heimoshuiyu
heimoshuiyu / fastapi_whisper.py
Last active September 2, 2023 08:53
Self-hosted OpenAI Whisper model with fastapi, support OpenAI API Format and alumae/ruby-pocketsphinx-server
import wave
import hashlib
import argparse
from datetime import datetime
import os
from typing import Any
from fastapi import File, UploadFile, Form, FastAPI, Request
from src.whisper_ctranslate2.whisper_ctranslate2 import Transcribe, TranscriptionOptions
from src.whisper_ctranslate2.writers import format_timestamp
import opencc