Decorative image frame

人生如逆旅,我亦是行人

行有不足 | 反求诸己

人生如逆旅,我亦是行人

flutter适配方案

直接上代码

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
37
38
class ScreenUtil {
static ScreenUtil instance = new ScreenUtil();
double width;
bool allowFontScaling;
static double _screenWidth;
static double _textScaleFactor;
ScreenUtil({
this.width = 750, // 默认设计稿750px
this.allowFontScaling = false, // 默认不跟随系统缩放字体
});
static ScreenUtil getInstance() {
return instance;
}
void init(BuildContext context) {
_screenWidth = MediaQuery.of(context).size.width;
_textScaleFactor = MediaQuery.of(context).textScaleFactor;
}
get scaleWidth => _screenWidth / instance.width;
setSize(double size) => size * scaleWidth;

///@param fontSize 传入设计稿上字体的px ,
setSp(double fontSize) => allowFontScaling
? setSize(fontSize)
: setSize(fontSize) / _textScaleFactor;
}

// 使用, 在入口文件中(一般为app.dart),
ScreenUtil.instance = ScreenUtil.getInstance()..init(context);
// 在切图是使用
Text('关于',
...
style: TextStyle(color: kLingyiText500, fontSize: ScreenUtil.getInstance().setSp(32))
)
Container(
width: ScreenUtil.getInstance().setSize(64),
height: ScreenUtil.getInstance().setSize(64),
...
)
阅读全文 >>

python富文本转word

富文本转word

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#coding=utf-8
from docx import Document
from docx.shared import Pt, RGBColor
from docx.oxml.ns import qn
from lxml import etree
# from docx.enum.text import WD_ALIGN_PARAGRAPH

data = [{
'document_title': u'<h1>写一个题目阿斯蒂芬按时</h1>',
'document_content': u"""<p>你好</p>

<p>你好中国</p>

<p><strong>hello </strong>world</p>
"""
},{
'document_title': u'写一个题目阿斯蒂芬按时',
'document_content': u"""<p>你好</p>

<p>你好中国</p>

<p><strong>hello </strong>world</p>
"""
}]
<!-- more -->

# 格式化富文本
def clean_richtext(richtext):
response = etree.HTML(text=richtext)
return response.xpath('string(.)')

def render_data(data):
document = Document()
font_name = u'宋体'

for item in data:
title_text = clean_richtext(item['document_title'])
content_text = clean_richtext(item['document_content'])
title = document.add_heading()
paragraph = document.add_paragraph()
# 居中
# title.alignment = WD_ALIGN_PARAGRAPH.CENTER
title_run = title.add_run(title_text)
title_run.font.size = Pt(22)
title_run.font.color.rgb = RGBColor(0, 0, 0)
title_run.font.name = font_name
title_run._element.rPr.rFonts.set(qn('w:eastAsia'), font_name)
para_run = paragraph.add_run(content_text)
para_run.font.size = Pt(10.5)
para_run.font.name = font_name
para_run._element.rPr.rFonts.set(qn('w:eastAsia'), font_name)

document.save('test.docx')

render_data(data)

Django命令

setting相关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 设置mysql数据库:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 数据库引擎
'NAME': 'for_django', # 你要存储数据的库名,事先要创建之
'USER': 'root', # 数据库用户名
'PASSWORD': 'root', # 密码
'HOST': 'localhost', # 主机
'PORT': '3306', # 数据库使用的端口
}
}
# 设置中文
LANGUAGE_CODE = 'zh-hans'

# 设置时区
TIME_ZONE = 'Asia/Shanghai'

# 允许所有hosts
ALLOWED_HOSTS = ["*"]
阅读全文 >>

vue+mint构建项目

安装vue-cli

npm install -g vue-cli

生成vue项目目录

vue init webpack projectname

安装mint-ui

npm install -g mint-ui

在项目中引入mint-ui

1
2
3
4
5
6
7
8
9
10
11
12
13
// main.js

import Vue from 'vue'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import App from './App.vue'

Vue.use(MintUI)

new Vue({
el: '#app',
components: { App }
})

mysql 远程连接

注:数据库环境为linux

防火墙

  • 查看防火墙状态:sudo ufw status
  • 关闭防火墙:sudo ufw enable
  • 打开防火墙: sudo ufw disable

查看数据库端口

  • 登录数据库 mysql -uroot -p
  • 查询端口命令 show global variables like 'port';

允许数据库端口进行数据传输

  • 假设数据库端口为3306 iptables -I INPUT -s 0/0 -p tcp --dport 3306 -j ACCEPT
  • 检查命令: iptables -L -n|grep 3306, 如果结果为: ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306,表示以允许

管理员赋权给远程用户

  • 登录数据库 mysql -uroot -p
  • 赋权: grant all privileges on *.* to 'newname'@'%' identified by 'password' with grant option; (newname表示远程用户名,password为密码 .赋予表示所有权利,’%’表示所有远程机器ip都可以访问)
  • 刷新权限: flush privileges;
  • 检查用户
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql> select host, user from user;
    +-----------+------------------+
    | host | user |
    +-----------+------------------+
    | % | ksir |
    | % | root |
    | localhost | debian-sys-maint |
    | localhost | mysql.session |
    | localhost | mysql.sys |
    +-----------+------------------+
    5 rows in set (0.00 sec)

修改~/etc/mysql下的mysql配置文件my.cnf, 有些版本配置文件为mysql.conf.d/mysql.cnf,将bind-address = 127.0.0.1改成bind-address = 0.0.0.0

重启mysql服务service mysql restart

远程连接:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\Users\ksir>mysql -h 192.168.***.*** -uksir -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.25-0ubuntu0.16.04.2 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

enjoy!

Flask-sqlachemy中lazy参数

lazy 的几个参数决定了 SQLAlchemy 什么时候从数据库中加载数据,官网解释如下

  • select: (which is the default) means that SQLAlchemy will load the data as necessary in one go using a standard select statement.
  • joined: tells SQLAlchemy to load the relationship in the same query as the parent using a JOIN statement.
  • subquery: works like ‘joined’ but instead SQLAlchemy will use a subquery.
  • dynamic : is special and useful if you have many items. Instead of loading the items SQLAlchemy will return another query object which you can further refine before loading the items. This is usually what you want if you expect more than a handful of items for this relationship
阅读全文 >>

python数据库驱动比较

mysql-connector-python

  • Officially supported by Oracle
  • Pure python
  • A little slow
  • Not compatible with MySQLdb

pymysql

  • Pure python
  • Faster than mysql-connector
  • Almost completely compatible with MySQLdb, after calling pymysql.install_as_MySQLdb()

mysqlclient

Django’s recommended library.
Friendly fork of the original MySQLdb, hopes to merge back some day.
The fastest implementation, as it is C based.
The most compatible with MySQLdb, as it is a forkDebian and Ubuntu use it to provide both python-mysqldb andpython3-mysqldb packages.