卡布奇诺

生活心情


  • 首页

  • 分类

  • 归档

  • 标签

  • 关于

Python 生成二维码

发表于 2018-08-29 | 分类于 Python

安装 MYQR

Github:https://github.com/sylnsfar/qrcode

1
pip install MyQR

写代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from MyQR import myqr

# myqr.run('http://www.wujinyu.com') #黑白图片

# myqr.run(
# words='http://www.wujinyu.com',
# picture='./images/a.png',
# colorized=True, #添加此参数可以生成彩色
# save_name='blog_cai.png',
# )

myqr.run(
words='http://www.wujinyu.com',
picture='./images/g.gif',
colorized=True,
save_name='blog.gif',
)

详细参数:请查阅https://github.com/sylnsfar/qrcode/blob/master/README-cn.md

命令行模式

1
2
3
4
5
6
7
8
9
10
# 概括
myqr Words
[-v {1,2,3,...,40}]
[-l {L,M,Q,H}]
[-n output-filename]
[-d output-directory]
[-p picture_file]
[-c]
[-con contrast]
[-bri brightness]

phpstorm 配置

发表于 2018-08-28 | 分类于 php

界面美化

enter action or option name

1
command+shift+a

左侧折叠线

1
2
3
Editor -> General -> Code Folding

show code folding outline 取消勾选 Apply

顶部分割线

1
2
3
Editor -> General -> Appearance

show method separators 取消勾选 Apply

右侧分割线

1
2
3
Editor -> General -> Appearance

show right margin(....) 取消勾选 Apply

跳转文件

1
2
3
Navigate -> File 快捷键可以修改  Crtl+p

设置中 keymaps

查看类方法

1
2
3
Navigate -> File Structure 快捷键可以修改  Crtl+m

设置中 keymaps

快速切换

1
2
3
4
5
Reacent File 

快捷键 Crtl+e

设置中 keymaps

Symbol 全局搜索方法

1
2
3
4
5
Symbol 

快捷键 Crtl+e

设置中 keymaps

django-ckeditor后台富文本编辑器

发表于 2018-08-18 | 分类于 Python

安装 django-ckeditor

1 使用 pip 安装

1
pip install django-ckeditor

2 注册到 django 项目中的 setting.py 在 INSTALLED_APPS 中加入 ‘ckeditor’

1
2
3
4
INSTALLED_APPS = [
# ...
'ckeditor',
]

3 打开对应需要修改为富文本编辑的模型文件 models.py。例如我有个Blog模型:

1
2
3
4
5
6
from django.db import models


class Blog(models.Model):
title = models.CharField(max_length=50)
content = models.TextField()

其中,title是博客标题,content是博客内容。博客内容需要富文本编辑,则改成如下:

1
2
3
4
5
6
7
from django.db import models
from ckeditor.fields import RichTextField


class Blog(models.Model):
title = models.CharField(max_length=50)
content = RichTextField()

若你需要编辑器的语言是简体中文,设置settings.py的LANGUAGE_CODE = 'zh-hans'。注意这里zh-hans都是小写。我发现写zh-Hans显示为繁体。另外,此时无法从本地上传图片,只能使用网络图片。可添加上传图片功能。

阅读全文 »

Shell脚本并发及并发数的控制

发表于 2018-05-23
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
#!/bin/bash
# Step1 创建有名管道
[ -e ./fd1 ] || mkfifo ./fd1

# 创建文件描述符,以可读(<)可写(>)的方式关联管道文件,这时候文件描述符3就有了有名管道文件的所有特性
exec 3<> ./fd1

# 关联后的文件描述符拥有管道文件的所有特性,所以这时候管道文件可以删除,我们留下文件描述符来用就可以了
rm -rf ./fd1

# Step2 创建令牌
for i in `seq 1 2`;
do
# echo 每次输出一个换行符,也就是一个令牌
echo >&3
done

# Step3 拿出令牌,进行并发操作
for line in `seq 1 10`;
do
read -u3 # read 命令每次读取一行,也就是拿到一个令牌
{
echo $line
echo >&3 # 执行完一条命令会将令牌放回管道
}&
done

wait

exec 3<&- # 关闭文件描述符的读
exec 3>&- # 关闭文件描述符的写

作者:不智鱼
链接:https://www.jianshu.com/p/701952ffb755
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

laravel 利用中间件进行操作日志记录

发表于 2018-05-08

利用中间件进行操作日志记录过程:

1、创建中间件

1
php artisan make:middleware AdminOperationLog

2、生成了文件./app/Http/Middleware/AdminOperationLog.php

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
代码如下:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Models\OperationLog;

class AdminOperationLog
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$user_id = 0;
if(Auth::check()) {
$user_id = (int) Auth::id();
}
$_SERVER['admin_uid'] = $user_id;
if('GET' != $request->method()){
$input = $request->all();
$log = new OperationLog(); # 提前创建表、model
$log->uid = $user_id;
$log->path = $request->path();
$log->method = $request->method();
$log->ip = $request->ip();
$log->sql = '';
$log->input = json_encode($input, JSON_UNESCAPED_UNICODE);
$log->save(); # 记录日志
}
return $next($request);
}
}

3、中间件引入 ./app/Http/Kernel.php

1
2
3
4
5
6
7
8
9
10
11
12
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\AdminOperationLog::class,
...
],

'api' => [
'throttle:60,1',
'bindings',
],
];

此时进行操作时就会记录操作日志

laravel 5.5 登录验证码 captcha 引入

发表于 2018-05-08

前提: 开启Laravel的用户认证功能

1、安装 Captcha

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
安装 Captcha+

$ composer require mews/captcha

配置

/config/app.php
'providers' => [
// ...
Mews\Captcha\CaptchaServiceProvider::class,
]
'aliases' => [
// ...
'Captcha' => Mews\Captcha\Facades\Captcha::class,
]

自定义配置
$ php artisan vendor:publish

运行之后,就可以在 config/captcha.php 中进行配置了。这里使用默认配置。

2、使用 Captcha 为 auth 组件添加验证码功能

在登录视图中增加验证码的选项,可以加到密码和 remember me 之间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/resources/views/auth/login.blade.php
<div class="form-group">
<label for="captcha" class="col-md-4 control-label">验证码</label>
<div class="form-group">
<div class="col-md-3">
<input id="captcha" class="form-control" type="captcha" name="captcha" value="{{ old('captcha') }}" required>
@if($errors->has('captcha'))
<div class="col-md-12">
<p class="text-danger text-left"><strong>{{$errors->first('captcha')}}</strong></p>
</div>
@endif
</div>
<div class="col-md-4">
<img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src='{{captcha_src()}}'+Math.random()">
</div>
</div>
</div>

重写 AuthController 登录验证方法,并自定义提示信息:
修改 AppHttpControllersAuthLoginController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
首先要引入如下代码:
use Illuminate\Http\Request;

重写validateLogin方法:

在验证里面加入验证码的规则验证即可
/**
* DESC: 重写 AuthenticatesUsers 登录验证方法,并自定义提示信息;
* 原验证方法 Illuminate\Foundation\Auth\AuthenticatesUsers
* @param Request $request
*/
protected function validateLogin(Request $request){
$this->validate($request, [
$this->username() => 'required|string',
'password' => 'required|string',
'captcha' => 'required|captcha',
],[
'captcha.required' => '请填写验证码',
'captcha.captcha' => '验证码错误',
]);
}

centos7 yum安装mongodb 3.6

发表于 2018-05-02 | 分类于 MongoDB

配置MongoDB的yum源

1
2
3
4
5
6
7
8
9
10
# 编辑文件
vim /etc/yum.repos.d/mongodb-org-3.6.repo

# 添加以下内容
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

安装mongodb

1
yum install -y mongodb-org

相关操作

1
2
3
4
5
6
7
8
# 启动
systemctl start mongod.service

# 停止
systemctl stop mongod.service

# 重启
systemctl restart mongod.service

编辑配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 编辑默认配置文件
vim /etc/mongod.conf

# 数据存放位置
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:

# 网络相关配置
net:
port: 27017 # 默认端口
bindIp: 0.0.0.0 # 监听IP配置,开启远程连接可以注释本行或者修改IP为0.0.0.0

# 是否开启权限验证
security:
authorization: enabled

CentOS 7 安装 Python3、pip3

发表于 2018-05-02 | 分类于 Linux

CentOS 7 默认安装了 Python 2,当需要使用 Python 3 的时候,可以手动下载 Python 源码后编译安装。

一、安装 Python 3

1.1 安装准备

1
2
3
4
5
6
7
8
9
$ sudo mkdir /usr/local/python3 # 创建安装目录

# 下载 Python 源文件
$ wget --no-check-certificate https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
# 注意:wget获取https的时候要加上:--no-check-certificate

$ tar -xzvf Python-3.6.0.tgz # 解压缩包

$ cd Python-3.6.0 # 进入解压目录

1.2 编译安装

1
2
3
4
5
$ sudo ./configure --prefix=/usr/local/python3 # 指定创建的目录

$ sudo make

$ sudo make install

可能出现的错误

1
"zipimport.ZipImportError: can't decompress data; zlib not available"

解决方案

1
yum install zlib zlib-devel -y

1.3 配置

1.3.1 两个版本共存

  • 创建 python3 的软链接:
1
$ sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3

这样就可以通过 python 命令使用 Python 2,python3 来使用 Python 3。

  • 1.3.2 修改默认为 Python 3

将 /usr/bin 中的 python 备份

1
$ sudo mv python python.bak

然后创建 python3 的软链接

1
$ sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python

这样默认的 Python 版本就替换为 Python 3 了。

因为 yum 使用 Python 2,因此替换为 Python 3 后可能无法正常工作,因此修改 yum配置文件

1
$ sudo vim /usr/bin/yum

将第一行指定的 python 版本改为 python2.7(#!/usr/bin/python 改为 #!/usr/bin/python2.7)

1
$ sudo vim /usr/libexec/urlgrabber-ext-down

将第一行指定的 python 版本改为 python2.7(#!/usr/bin/python 改为 #!/usr/bin/python2.7)

二、安装 pip

2.1 yum 安装

1
2
3
4
5
6
7
8
# 首先安装 epel 扩展源
$ sudo yum -y install epel-release

# 安装 python-pip
$ sudo yum -y install python-pip

# 清除 cache
$ sudo yum clean all

通过这种方式貌似只能安装 pip2,想要安装 Python 3 的 pip,可以通过以下的源代码安装方式。

2.2 源码安装

1
2
3
4
5
6
7
8
9
# 下载源代码
$ wget --no-check-certificate https://github.com/pypa/pip/archive/9.0.1.tar.gz

$ tar -zvxf 9.0.1 -C pip-9.0.1 # 解压文件

$ cd pip-9.0.1

# 使用 Python 3 安装
$ python3 setup.py install
  • 创建链接:
1
$ sudo ln -s /usr/local/python3/bin/pip /usr/bin/pip3

2.3 升级 pip

1
$ pip install --upgrade pip

FormRequest

发表于 2018-05-02 | 分类于 Python

【scrapy】FormRequest <TypeError: to_bytes must receive a unicode, str or bytes object, got int>

原因:formData里面有的参数是数字,转成字符串就行

1
2
3
4
5
6
7
8
9
10
11
for i in range(5):
num = i+1
data = {
'ajax' : 'ajax',
'searchKey':'searchKey',
'projectStatus':'projectStatus',
'projectModel':'-1',
'financingModel':'0',
'pageNo':str(num),
'pageCount':'12'
}

Ubuntu16.04安装mongodb

发表于 2018-05-01 | 分类于 Linux

1.导入软件源的公钥

1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

2.为mongodb创建软件源list文件

  • ubuntu12.04
1
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
  • ubuntu14.04
1
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
  • ubuntu16.04
1
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

3.更新软件源并安装mongodb

1
2
sudo apt-get update
sudo apt-get install -y mongodb-org

如果想要安装特定的版本,使用下面命令:

1
sudo apt-get install -y mongodb-org=3.2.9 mongodb-org-server=3.2.9 mongodb-org-shell=3.2.9 mongodb-org-mongos=3.2.9 mongodb-org-tools=3.2.9

4.配置启动文件

如果是ubuntu16.04的版本,需要手动新建/lib/systemd/system/mongod.service文件,并写入下面内容:

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

5.启动、重启和关闭命令

1
2
3
sudo service mongod start
sudo service mongod restart
sudo service mongod stop

6.mongodb的完全卸载

  • 先停止运行mongodb
1
sudo service mongod stop
  • 再卸载软件
1
sudo apt-get purge mongodb-org*
  • 删除数据库和日志文件
1
2
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

7.添加php的mongodb扩展

1
2
# pecl install mongodb
# echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
123…17
卡布奇诺

卡布奇诺

记录编程中遇到的坑

167 日志
18 分类
102 标签
GitHub E-Mail
© 2015 — 2018 卡布奇诺@心情
由 Hexo 强力驱动
|
主题 — NexT.Pisces v5.1.4