This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 自动检查 tmux 会话并提示选择 | |
| function tmux_login() { | |
| # 检查是否为交互式 shell | |
| if [[ ! -t 0 ]]; then | |
| # 非交互式环境(比如 Jenkins SSH),直接返回 | |
| echo "非交互式环境" | |
| return | |
| fi | |
| # 检查是否有 tmux 会话 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| from typing import List | |
| def diagonal_iter1(matrix: List[List[int]]): | |
| """ | |
| 外层从上到下,内层从右到左 | |
| 适合于根据上方和右方计算当前位置的值时 | |
| [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 挂载google drive | |
| from google.colab import drive | |
| drive.mount('/content/drive') | |
| # 查看系统版本 | |
| !sudo lsb_release -a | |
| # 查看gpu型号 | |
| !nvidia-smi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |