- 博客(80)
- 收藏
- 关注
原创 【python小工具】chardet.detect 检测、转换文本编码
from chardet import detect as char_detectdef change_encode_type(file_path, des='utf-8'): # 获取原文本的编码类型 with open(file_path, 'rb') as f: detect_result = char_detect(f.read(200)) src = detect_result['encoding'].lower() print('
2021-08-06 18:27:07 1661
原创 【python小工具】itertools.groupby 按连续数分组,可设置步长
from itertools import groupbydef group_number(ls, step=1): """对连续数分组,step设置连续数的步长""" result = [] for _, i in groupby(map(lambda x: [x[0] * step, x[1]], enumerate(ls)), lambda x: x[1]-x[0]): result.append([j for _, j in i]) return
2021-08-06 17:40:21 581
原创 【sublime】个性化配置
settings-User// 保存自动去除行末空格"trim_trailing_white_space_on_save": truekeymap-User// 代码格式化{ "keys": ["alt+shift+f"], "command": "reindent" },// 替换原功能transpose{ "keys": ["ctrl+t"], "command": "new_file" },// 隐藏行数{ "keys": ["alt+l"], "comma
2021-04-14 15:19:09 198
原创 【mac】navicat 保存密码失败 -34018
navicat 选择保存密码时会出现 Failed to save password Error code: -34018解决方法打开 钥匙串访问(keychain access)新建钥匙串输入钥匙串名称,将<连接名>替换成自己的输入数据库的用户名和密码保存重启navicatcom.prect.Navicat.conn {Conn:MySQL; Db:<连接名>; UserID:local; ProjectID:local}...
2021-03-30 09:32:35 10146 4
原创 【工具】三元运算符格式化
phpstorm遇到这种神级代码也无法进一步美化,只能借用在线工具pretty diff完成for (var n = 0; n < o.length; n++) "刷卡支付" == o[n].value ? 1 == i.skzf ? o[n].checked = !0 : o[n].checked = !1 : "免费wifi" == o[n].value ? 1 == i.wifi ? o[n].checked = !0 : o[n].checked = !1 : "免费停车" == o[n].
2021-03-28 18:49:03 637
原创 【php】获取access_token
function getAccessToken() { $table_name = 'xxx'; $system = pdo_get($table_name, ['id' => 1]); $token = $system['access_token']; // 校验是否失效 $check_url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=".$token; $res = se
2021-03-17 13:46:27 816
转载 【chmod】修改文件夹、子文件夹权限,不包含文件
How to recursively chmod all directories except files?To recursively give directories read&execute privileges:find /path/to/base/dir -type d -exec chmod 755 {} +To recursively give files read privileges:find /path/to/base/dir -type f -exec chmod 64
2021-03-01 10:28:26 792
原创 【mac.rpa】rpa.init()
tagui.py 路径 /usr/local/Cellar/anaconda/envs/your_env/lib/python3.7/site-packages/tagui.py下载TagUI_macOS.zip [150.5 MB]注释 if not os.path.isfile('rpa_python.zip')和else的代码注释# set correct tagui folder for different operating systems下的if platform.system()
2021-02-19 18:39:42 982 2
转载 【python】Install Certificates.command
来源:Install Certificates.command · GitHub# install_certifi.py## sample script to install or update a set of default Root Certificates# for the ssl module. Uses the certificates provided by the certifi package:# https://pypi.python.org/pypi/certi
2021-02-19 16:12:58 3717
原创 【php.yii】Operator ‘FIND_IN_SET()‘ requires two operands.
$filter = ['and', ['=', 'is_del', 0], ['like', 'title', $where['title'] ?? ''], ['=', 'status', $where['status'] ?? ''], ['or', ['like', 'desc', $where['key'] ?? ''], ['like', 'content', $where['key'] ?? ''], ]];$tmp
2021-01-18 23:56:26 2219
原创 【js】获取表单name[]的数组
<input name="content[]" value="content1"><input name="content[]" value="content2"><script>content = $("input[name='content[]']");for (i=0; i < content.length; i++) { content[i] = content[i].value;}content = content.toArray()
2021-01-04 13:19:59 1603
原创 【公众号】获取用户信息
接口https://api.weixin.qq.com/cgi-bin/user/info?access_token=xxxxx&openid=xxxxx返回数据(关注中){ subscribe: 1, openid: "xx", tagid_list: [ ], nickname: "xx", sex: 1, language: "zh_CN", city: "", province: "", country: "中国", headimgurl: "http://thir
2020-12-28 16:29:28 265
转载 【php小工具】文件大小单位转换
function convertFilesize($bytes, $decimals=2){ $size = ['B', 'kB', 'MB', 'GB', 'TB']; $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];}
2020-12-14 17:23:10 149
原创 【php小工具】实用的字段映射方法
/** * 字段映射,配合映射字典 $field_map * [[目标字段$field, 检索模型$class, 检索字段$from(默认id), 取出字段$to(默认name)]] * * 例如 ["rid", Role::class, "id", "name"] * Role表检索 id=$data['rid'],取出 name,最后 $data['rid_t']=name */public static function fetchScalarByField($data, $field
2020-12-12 19:51:25 451
原创 【php】下载文件
if (is_file($file)) { // 判断是否文件 bool header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=" . $file); readfile($file);}ZipArchive类打包多个文件public static function PackDown($file_arr, $download_n
2020-12-01 12:10:03 93
原创 【js】监听输入框,填入数据
$("#src_input").blur(function(){ var val = $(this).val(); if (val == '') return; $.ajax({ type: 'get', url: "/get-list", dataType : 'json', success: function(res) { if (res.code == 0){
2020-11-27 12:33:36 344
原创 【apache】切换php
# vim /etc/apache2/httpd.conf# 把下面一行注释掉,换成自己的php# LoadModule php7_module libexec/apache2/libphp7.soLoadModule php7_module local/php5-7.2.21-20190811-210031/libphp7.so
2020-10-22 19:33:56 147
原创 【mac.apache】报错 AH00557 AH00558
AH00557: httpd: apr_sockaddr_info_get() failed for liumoujiadeMacBook-Pro.localAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message原因是存在两
2020-10-22 18:56:09 1170 2
转载 【python小工具】vbb文件提取json
参考 github caltech-pedestrian-converterfrom scipy.io import loadmatimport osdef vbb2json(vbb_path): vbb = loadmat(vbb_path)['A'][0][0] nFrame = int(vbb[0][0][0]) objLists = vbb[1][0] maxObj = int(vbb[2][0][0]) objInit = vbb[3][0].
2020-10-21 19:56:25 754
原创 【python小工具】seq文件提取jpg图片
def seq2jpg(seq_path): with open(seq_path, 'rb') as f: seq = f.read() header = b"\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46" img_ls = seq.split(header)[1:] # 去掉第1个 # 保存在当前路径,新建同名文件夹 save_dir = seq_path[:-4] if not os.pa
2020-10-21 16:11:36 1029 2
原创 【python小工具】zipfile打包指定文件
def make_zip(fp_ls, zip_path): """将指定文件打包成zip文件""" zipf = zipfile.ZipFile(zip_path, 'w') for file_path in fp_ls: file_name = os.path.split(file_path)[-1] zipf.write(file_path, file_name) zipf.close()
2020-10-21 10:09:15 177 1
原创 【python小工具】图片image由ndarray转换成bytes格式
def ndarray2bytes(img_arr): """ndarray的图片转换成bytes""" imgByteArr = io.BytesIO() Image.fromarray(img_arr).save(imgByteArr, format='PNG') img_data = imgByteArr.getvalue() return img_data
2020-10-16 11:54:06 1735
原创 【python小工具】递归遍历所有文件
import osdef get_file(dir): file_ls = [] for i in os.listdir(dir): new_path = os.path.join(dir, i) if os.path.isdir(new_path): file_ls.extend(get_file(new_path)) elif os.path.isfile(new_path): file_l
2020-10-13 20:44:52 172
原创 python 上传公众号图文素材报错:44003
报错: {“errcode”:44003,“errmsg”:“empty news data hint: [QGI6fA08690015]”}解决方法data是字符串格式,不是字典格式import jsondata = json.dumps(data, ensure_ascii=False).encode('utf-8')
2020-10-09 22:10:29 1346 1
原创 【web】视差滚动
效果无插件<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script><style type="text/css"> .parallax { height: 550px; background-attachment: fixed; background-size: cover; /* background-repeat: no-rep
2020-09-25 17:48:27 320
原创 【python小工具】图片生成滚动效果的gif
# 相关库import imageiofrom PIL import Image# 以下库用来识别图片主颜色import pandas as pdimport numpy as npdef img2gif(image, offset=10, from_='r', show_size=0, has_out=False, bgc=''): """ offset: 每次移动像素 from: l, r, u, d 对应左右上下 show_size: 滚动窗口大小
2020-09-21 20:54:15 1046
原创 【python小工具】1行代码提取照片主要颜色
使用的图片准备# 相关库from PIL import Imageimport pandas as pdimport numpy as np# 打开图片img = Image.open(img_path)运行pd.Series([','.join(j) for i in np.array(img).astype('str') for j in i]).value_counts()[:5]前5种147,156,189 67150,155,185 53149,147
2020-09-21 16:52:07 465
原创 小程序读取本地json数据
/utils/data.jsvar json=[ { "cat_id": 1, "cat_name": "电视", }, { "cat_id ": 2, "name": "空调", }]// 定义数据出口module.exports = { dataList: json}/pages/index/index.jsonLoad: function (options) { var d
2020-08-09 12:17:15 2277 1
原创 subplots, subplot, axes的参数和属性
set属性 set_adjustable{‘box’, ‘datalim’}set_agg_filtera filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) arrayset_alphafloat or Noneset_anchor2-tuple of floats or {‘C’, ‘SW’, ‘S’
2020-07-17 12:14:58 4326
原创 【python.matplotlib】tick_params参数
参数说明axis{‘x’, ‘y’, ‘both’}, optional坐标轴;默认 ‘both’.resetbool, default: FalseIf True, set all parameters to defaults before processing other keyword arguments.which{‘major’, ‘minor’, ‘both’}主、副刻度线;默认 ‘major’direction{‘in’, ‘out’, ‘inou...
2020-07-17 11:44:58 2742
原创 【python.matplotlib】显示标签在线条上
线条中间使用 matplotlib-label-lines 库from labellines import labelLines # pip install matplotlib-label-linesfrom matplotlib.dates import date2numfrom datetime import datetimedf = pd.DataFrame([[0, 2, 4], [3, 3, 3], [4, 3, 2]], columns=['A
2020-07-14 21:31:20 5108 1
转载 决策树可视化
import pydotplusfrom IPython.display import Imagefrom sklearn.tree import export_graphviz# Graphviz临时环境变量import osos.environ['PATH'] += r'.\Graphviz2.38\bin'def print_graph(dtr, feature_names): """绘制决策树""" graph = export_graphviz(dtr, featu
2020-07-12 23:42:45 185
原创 pandas分块处理数据
之前数据列太多,独热编码内存不够,想着分块处理。但我选出一些关键特征列后结果还好,以下方法没有实际用过。from sklearn.model_selection import train_test_split# 设置随机种子SEED = 0np.random.seed(SEED)def get_train_test(chunk, test_size=0.95, SEED=SEED): """划分训练集测试集""" y = 1 * (chunk['target'] == "REP
2020-07-12 22:48:13 768
原创 【pandas】DataFrame去掉整列相同的数据
法一不适用于字符串类型的数据X.drop(X.columns[X.std() == 0], axis=1, inplace=True)法二通用X = X.loc[:, (X != X.iloc[0]).any()]
2020-07-12 22:27:13 1722
原创 matplotlib隐藏刻度线、标签和边线
一般情况plt.figure(figsize=(3, 3))plt.plot([0, 1], [0, 1])隐藏所有刻度线和标签plt.axis('off')隐藏刻度线默认左下True 右上Falseplt.tick_params(bottom=False, top=False, left=False, right=False)隐藏边线ax = plt.gca()for i in ['top', 'right', 'bottom', 'left']: ax.spine
2020-07-11 23:24:05 26241 2
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人