Skip to content

Instantly share code, notes, and snippets.

@justamanm
justamanm / tmux_auto.sh
Last active March 18, 2025 01:58
Now, if you have multiple tmux sessions, you can choose one to enter upon logging into the shell.
# 自动检查 tmux 会话并提示选择
function tmux_login() {
# 检查是否为交互式 shell
if [[ ! -t 0 ]]; then
# 非交互式环境(比如 Jenkins SSH),直接返回
echo "非交互式环境"
return
fi
# 检查是否有 tmux 会话
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import List
def diagonal_iter1(matrix: List[List[int]]):
"""
外层从上到下,内层从右到左
适合于根据上方和右方计算当前位置的值时
[
@justamanm
justamanm / colab_init.sh
Last active April 8, 2025 07:57
初始化colab:更换tf/keras/cuda版本等等
# 挂载google drive
from google.colab import drive
drive.mount('/content/drive')
# 查看系统版本
!sudo lsb_release -a
# 查看gpu型号
!nvidia-smi
@justamanm
justamanm / linux部署.py
Created November 12, 2020 01:32
linux部署web服务:离线包安装、supervisor、crontab
import os
import sys
import time
path = os.path.dirname(os.path.abspath(__file__))
_ = "-" * 30
# 输出颜色,(固定)\033[显示方式;文字颜色;背景颜色m 字符串 \033[0m(结束符)
def print_color(data, status=1):
@justamanm
justamanm / 请求头转字典.py
Created November 12, 2020 01:29
请求头转字典
with open("test.txt", "r", encoding="utf8") as f:
data = f.read()
b = data.split("\n")
dict1 = {}
for param in b:
ret = param.split("\t")
if len(ret) <= 1:
ret = param.split(":")
dict1[ret[0]] = ret[1] if ret[1] else ""
@justamanm
justamanm / remove_noise.py
Created November 12, 2020 01:24
去除一段音频的背景噪音
#!/usr/bin/env python
import numpy as np
import wave
import math
# 打开WAV文档
# # f = wave.open("input_file.wav")
# f = wave.open("cache.wav")
# # 读取格式信息
# # (nchannels, sampwidth, framerate, nframes, comptype, compname)
@justamanm
justamanm / get_microphone.py
Last active November 12, 2020 01:25
从麦克风读取音频数据,保存到wav文件
import os
import sys
import time
import pyaudio
import wave
import numpy as np
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(root_path)
@justamanm
justamanm / vec_distance.py
Created November 4, 2020 07:41
向量距离
import numpy as np
from scipy.linalg import norm
v1 = np.array([1, 2, 3])
v2 = np.array([1, 2, 3])
ret = np.dot(v1, v2) / (norm(v1) * norm(v2))
print(ret)
@justamanm
justamanm / last-line.py
Last active October 30, 2020 16:25
文件-从最后一行开始读|-|{"files":{"last-line.py":{"env":"python"}},"tag":"python"}
path = "path of file"
# file must be opened by rb
f = open(path, "rb")
# 定位到文件末尾
f.seek(0, 2)
def file_last_line(file=f):
# 排除最后一个是换行符的情况
f.seek(-1, 1)