1. Selenium

Selenium 是一个JavaScript框架,调用 webdriver 模拟在浏览器内的操作,可以适用 Chrome、 Firefox 、IE 等浏览器。

本文用的是 PhantomJS,一个在可以后台运行的无头浏览器(Scriptable Headless Browser)。

  • PhantomJS 项目目前已经暂停更新。
  • Selenium 推荐用 Chrome 或 Firefox 的无头模式。
  • 但 chromedriver 无头模式启动时,还是会有一个空白的命令行窗口,比较讨厌,因此还是用 PhantomJS。
阅读全文 »

1. 用 matplotlib animation 绘制动画

ref: https://matplotlib.org/3.1.1/api/animation_api.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np

# 数据集:X轴数据固定;Y轴的数据更新
X = np.arange(0, 10, 0.01) # X shape: (N,)
Ys = [np.sin(X + k / 10) for k in range(100)] # Ys shape: (k, N)


def my_ani(x, ys):
fig, ax = plt.subplots()
ax.set_title('y = sin(x + k/10)')
ax.set_xlim([0, 10]), ax.set_xlabel('X')
ax.set_ylim([-1, 1]), ax.set_ylabel('Y')

line, = ax.plot(x, ys[0])
ano = plt.annotate('k: 0', (1, 1))

def animate(i):
line.set_ydata(ys[i]) # update the y data.
ano.set_text('k: %d' % i) # update the annotate.
return line,

# animation.FuncAnimation 参数说明
# fig: figure 对象
# func: 动画函数,自定义函数 animate
# frames: 总帧数
# interval: 间隔时间,ms
ani = animation.FuncAnimation(fig, animate, frames=30, interval=50)
# ani.save('sin_ani.mp4', dpi=300, writer='ffmpeg') # scoop install ffmpeg
# ani.save('sin_ani.gif', dpi=300, writer='pillow') # pip install pillow
plt.show()


my_ani(X, Ys)

阅读全文 »

问题

XPS13 9370用了之后发现屏幕亮度会随显示内容而自动调节。调节机制太弱智,眼睛都要瞎了。

解决方案:

  • 开机后立即点 F2,进入Bios,我的版本是1.10.0
  • 找到 Video - Dynamic Backlight Control,然后选择 Disabled, 然后单击右下角 Apply
  • OK !
阅读全文 »

ref: (https://github.com/lukesampson/scoop)

1. 安装 scoop

阅读全文 »

runcat-pyqt5-win

RunCat是一款 mac应用,用奔跑的猫来显示当前系统资源(CPU)占用情况。

但是只有mac版,于是用python撸了一个,可以在windows任务栏(通知区域)养猫。

首先用psutil
获得CPU或内存的使用情况,然后用pyqt5创建QSystemTrayIcon显示在任务栏的托盘区域。

GPU的使用情况可以用 nvidia-ml-py, https://pypi.org/project/nvidia-ml-py/
的pynvml模块(仅限nvidia gpu)。

阅读全文 »

2019年升级了装备 XPS 9370,但是 Solidworks 2014使用时非常卡。
XPS 9370 配置的是 Intel UHD 620 集显,公司还有个笔记本是 ThinkPad New S2,是HD 620显卡,solidworks 却不卡。

解决办法:改注册表

将 Solidworks 2016 原有的显卡系列随便选一个导出来,然后用文本编辑器打开,将显卡系列的名称(如 HD Graphics)改为 UHD Graphics 620,Workarounds 值改为 00000009。

或直接将以下导入注册表。

1
2
3
4
5
6
7
8
9
10
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\SolidWorks\SOLIDWORKS 2016\Performance\Graphics\Hardware\Intel\Intel(R) UHD Graphics 620]
"Workarounds"=dword:00000009

[HKEY_CURRENT_USER\Software\SolidWorks\SOLIDWORKS 2016\Performance\Graphics\Hardware\Intel\Intel(R) UHD Graphics 620\V001_FG_X614105256_V815102256]
"Workarounds"=dword:10000480

[HKEY_CURRENT_USER\Software\SolidWorks\SOLIDWORKS 2016\Performance\Graphics\Hardware\Intel\Intel(R) UHD Graphics 620\V002_FG_V815102345]
"Workarounds"=dword:10000080

以下方法已失效!


在网上搜了一圈大致有以下几个解决方法:

  • 一、在 Solidworks 的选项里,勾选启动 OpenGL 软件加速
    • 找到了 OpenGL 选项,发现默认是已勾选的,状态还是灰色的,根本改不了;
阅读全文 »

1.硬件安装

前一段用 tensorflow 玩深度学习,笔记本只能跑个 mnist,再大点的模型都跑不动。
试了腾讯云、极客云,用着也不方便。

还是上显卡吧!

  • 本来一门心思想买1080,看着看着RTX20系列出了,买新不买旧,那就买2070吧。
  • 学校有个台式机是dell optix 7020,小机箱,原装电源只有~300w。还得换个电源。
  • 机械硬盘还得再换个ssd。。。
阅读全文 »

前一段做试验,需要远程监控现场的电脑;
写了一个定时截屏并把图片发送至邮箱的脚本,这样微信就可以得到通知。

1. 截屏,并保存图片

1
2
3
4
5
6
7
from PIL import ImageGrab
import time

time_now = time.strftime('%Y%m%d-%H%M%S')
pic = ImageGrab.grab()
pic_name = time_now+'.jpg'
pic.save(pic_name)

2. 定时任务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import threading

def func():
t = time.localtime(time.time())
min, hour, wkday = t.tm_min, t.tm_hour, t.tm_wday
# --------add tasks here--------------------------
if min in [0, 15, 30, 45]:
print('tasks')
# --------tasks end----------------------------

global timer
timer = threading.Timer(60, func, [])
timer.start()


timer = threading.Timer(1, func, [])
timer.start()

阅读全文 »

处理excel数据时遇到了个问题,数据导出来总是不全。

后来发现是 *.xls 格式的问题:

xls格式 最大行数为65535

xlsx格式 最大行数为1048576(满足要求了)

而且xlsx文件大小只有原来的1/3左右。

但是手上有一大堆旧的xls文件需要转换。

解决方法:

安装pywin32

1
pip install pywin32

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os
import os.path
import win32com.client as win32

## 根目录
rootdir = u'E:\\temp1'
# 三个参数:父目录;所有文件夹名(不含路径);所有文件名
for parent, dirnames, filenames in os.walk(rootdir):
for fn in filenames:
filedir = os.path.join(parent, fn)
print(filedir)

excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(filedir)
# xlsx: FileFormat=51
# xls: FileFormat=56,
wb.SaveAs(filedir.replace('xls', 'xlsx').replace('XLS', 'xlsx'), FileFormat=51)
wb.Close()
excel.Application.Quit()

在vps上安装jupyter,设置远程访问。

0. 安装jupyter

1
pip install jupyter

1. 生成密码

打开python:

1
2
from notebook.auth import passwd
passwd()

根据提示输入密码,得到类似下面的密文:
‘sha1:ce23d945972*********’
复制下来。

2. 生成配置文件:

1
2
jupyter notebook --generate-config
# 生成完可以看到配置文件的存储位置

3. 修改配置文件

sudo nano jupyter_notebook_config.py

1
2
3
4
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha:ce..粘贴密文..'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 3333

4. 启动jupyter

1
nohup jupyter notebook  &

5. 远程登录

试试打开 http://xxx.xxx.xxx.xxx:3333
输入第一步设置的密码即可

PPT导出高分辨率的图片(300dpi)

1. 打开注册表

  • win + R 调出命令行, 键入 regedit , 回车

2. 查找注册表路径(Office 2016版):

1
HKEY_CURRENT_USER\Software\Microsoft\Office\16\PowerPoint\Options

3. 新建 DWORD 值(D)

  • 名称为 ExportBitmapResolution
  • 数值为 300 (十进制)

4. 打开需要的PPT,另存为或导出为图片格式。

准备

  • 需要两个 github 仓库:
    • 一个用于发布页面: shenbo.github.io
    • 一个用于放源码: hexo-source
  • 已配置好 hexo 的 VPS 服务器

1. 创建 hexo-source 仓库

  • 在hexo的source目录下( ~/hexo/source)运行:
    1
    2
    3
    4
    5
    6
    7
    8
    cd hexo/source

    git init
    git add .
    git commit -m "first commit"
    git remote add origin https://github.com/shenbo/hexo-source.git

    git push -u origin master
阅读全文 »

生成一个 dataframe

1
2
3
4
5
6
7
8
9
10
import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.rand(2, 4))
print(df)

#
# 0 1 2 3
# 0 0.714730 0.566612 0.764352 0.728862
# 1 0.823414 0.662657 0.800281 0.711702
阅读全文 »

pandas显示完整的行或列,避免省略中间行或列、以及自动换行。

1
2
3
4
5
import pandas as pd

pd.set_option('display.width', 1000)
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)

1. 由字符串格式生成时间数据

1
2
3
4
5
6
7
8
9
import pandas as pd
import numpy as np

# string datetime --> pandas datetime
dt_start = '2018-07-04 12:00'
pd_dt_start = pd.datetime.strptime(dt_start, '%Y-%m-%d %H:%M')

print(dt_start) # 2018-07-04 12:00
print(pd_dt_start) # 2018-07-04 12:00:00
阅读全文 »

pip 安装 pyqt5-tools

1
pip install pyqt5-tools -i https://pypi.mirrors.ustc.edu.cn/simple/

启动 pycharm, 打开 Settings -> Tools -> External Tools

  • 点击+,添加工具

  • 添加 pyqtdesigner

    1
    2
    3
    4
    5
    - Name:  pyqtdesigner

    - Program: C:\......\designer.exe

    - Working dir: $ProjectFileDir$
  • 添加 pyuic5

    1
    2
    3
    4
    5
    6
    7
    - Name:  pyuic5

    - Program: C:\......\pyuic5.exe

    - Arguments: $FileName$ -o $FileNameWithoutExtension$.py

    - Working dir: $FileDir$

ffmpeg 使用说明

查看使用说明:ffmpeg -h

1
2
3
4
5
6
7
8
9
# usage: 
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

# options:
-ss: set the start time offset
-f: force format
-t: record or transcode "duration" seconds of audio/video
-r set frame rate (Hz value, fraction or abbreviation)
-y: overwrite output files
阅读全文 »