1. vscode下python print 输出乱码

在task文件中加入环境变量,然后问题解决。

1
2
3
4
5
"options": {
"env":{
"PYTHONIOENCODING": "UTF-8"
}
}

2. python 运行配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"version": "0.1.0",
"command": "python",
"windows": {
"command": "D:\\develop\\running\\Python35\\python.exe" //python的安装路径
},
"isShellCommand": true,
"args": [
"${file}"
],
"showOutput": "always",
"options": {
"env": {
"PYTHONIOENCODING": "UTF-8"
}
}
}

Ubuntu运行级别

1
2
3
4
5
6
7
8
9
10
11
12
13
0 停机

1 单用户,Does not configure network interfaces, start daemons, or allow non-root logins

2 多用户,无网络连接 Does not configure network interfaces or start daemons

3 多用户,启动网络连接 Starts the system normally.

4 用户自定义

5 多用户带图形界面

6 重启

以nexus为例,配置nexus开启自动启动

1
2
cp /opt/nexus/nexus-2.0.3/bin/nexus /etc/init.d/
update-rc.d nexus defaults 99 ##数字越大启动越靠后面,因为需要网络支持,所以启动靠后

sysv-rc-conf管理启动项

1
2
sudo apt-get install sysv-rc-conf
sudo sysv-rc-conf

每个项目都会有多套运行环境(开发,测试,正式等等),不同的环境配置也不尽相同(如jdbc.url),借助Jenkins和自动部署提供的便利,我们可以把不同环境的配置文件单独抽离出来,打完包后用对应环境的配置文件替换打包后的文件,其实maven已经给我们提供了替换方案:profile + filtering

  1. 配置 resource 插件,启用filtering功能并添加属性到pom:
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
<project>
...
<build>
<filters>
<filter>src/main/filters-${active.profile}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<active.profile>dev</active.profile>
</properties>
<!-- 把当前profile设置为默认profile,可以同时这是多个为默认-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<active.profile>test</active.profile>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<active.profile>product</active.profile>
</properties>
</profile>
...
</project>

  1. 然后在src/main下新建三个文件:filters-dev.properties,filters-test.properties,filters-product.properties,文件内容如下(以filters-dev.properties为例):
1
2
3
pom.jdbc.url=jdbc:mysql://127.0.0.1:3306/dev
pom.jdbc.username=root
pom.jdbc.password=123456
  1. 用 dev profile 打开发包mvn clean package -Pdev, 打包后jdbc.properties文件内容如下:
1
2
3
jdbc.url=jdbc:mysql://127.0.0.1:3306/dev
jdbc.username=root
jdbc.password=123456

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## You will need somewhere for your project to reside, create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

## You may test the newly compiled and packaged JAR with the following command:
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App

## ignore test
mvn install -Dmaven.test.skip=true

## 按指定文件指定环境打包
mvn -B package --file pom_github.xml -P profile -Dmaven.test.skip=true

mvn dependency:tree
mvn install -X

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>xxx.xxx.Main</mainClass>
                            </transformer>
                        </transformers>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>

1
2
3
4
5
6
7
8
9
10
11
12
git config --global https.proxy http://127.0.0.1:1080

git config --global https.proxy https://127.0.0.1:1080

git config --global --unset http.proxy

git config --global --unset https.proxy

npm config delete proxy

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

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
56
57
58
59
60
61
62
63
64
65
66
67
########## maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

########## eclipse
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

################## Intellij
.idea/
*.iml
*.iws

  1. 安装nexus,可下载sh版,直接运行可根据提示完成配置,适合初学者

  2. 配置maven中settings.xml文件的servers节点,可以发布jar包到nexus

    nexus-releases admin admin123 nexus-snapshots admin admin123

3. 配置pom.xml文件

<repositories>
    <!-- 私服 -->
    <repository>
        <id>nexus-repos</id>
        <name>maven-public</name>
        <url>http://192.168.0.114:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
    
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>nexus-repos</id>
        <name>maven-public</name>
        <url>http://192.168.0.114:8081/repository/maven-public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>maven-releases</name>
        <url>http://192.168.0.114:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>maven-snapshots</name>
        <url>http://192.168.0.114:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

在pom文件build节点下加入

<outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/classes/</outputDirectory>

web配置

  1. tomcat6
1
2
3
4
5
6
7
8
9
10
11
<!-- tomcat6插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>${tomcat.version}</version>
<configuration>
<port>${webserver.port}</port>
<path>/${project.artifactId}</path>
<uriEncoding>${project.build.sourceEncoding}</uriEncoding>
</configuration>
</plugin>
  1. tomcat7
1
2
3
4
5
6
7
8
9
10
11
<!-- tomcat7插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat.version}</version>
<configuration>
<port>${webserver.port}</port>
<path>/${project.artifactId}</path>
<uriEncoding>${project.build.sourceEncoding}</uriEncoding>
</configuration>
</plugin>
  1. jetty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!-- jetty插件 -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>${webserver.port}</port>
</connector>
</connectors>
<webAppConfig>
<contextPath>/${project.artifactId}</contextPath>
</webAppConfig>
<systemProperties>
<systemProperty>
<name>org.mortbay.util.URI.charset</name>
<value>${project.build.sourceEncoding}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>

参考资料

下载单个文件,默认将输出打印到标准输出中(STDOUT)中

curl http://www.centos.org

通过-o/-O选项保存下载的文件到指定的文件中:

  1. -o:将文件保存为命令行中指定的文件名的文件中
  2. -O:使用URL中默认的文件名保存文件到本地
# 将文件下载到本地并命名为mygettext.html
  curl -o mygettext.html http://www.gnu.org/software/gettext/manual/gettext.html
 
# 将文件保存到本地并命名为gettext.html
  curl -O http://www.gnu.org/software/gettext/manual/gettext.html

同样可以使用转向字符”>”对输出进行转向输出

同时获取多个文件

curl -O URL1 -O URL2

若同时从同一站点下载多个文件时,curl会尝试重用链接(connection)。

通过-L选项进行重定向
默认情况下CURL不会发送HTTP Location headers(重定向).当一个被请求页面移动到另一个站点时,会发送一个HTTP Loaction header作为请求,然后将请求重定向到新的地址上。
例如:访问google.com时,会自动将地址重定向到google.com.hk上。

curl http://www.google.com
<HTML>
<HEAD>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>302 Moved</TITLE>
</HEAD>
<BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="http://www.google.com.hk/url?sa=p&amp;hl=zh-CN&amp;pref=hkredirect&amp;pval=yes&amp;q=http://www.google.com.hk/&amp;ust=1379402837567135amp;usg=AFQjCNF3o7umf3jyJpNDPuF7KTibavE4aA">here</A>.
</BODY>
</HTML>

上述输出说明所请求的档案被转移到了http://www.google.com.hk。

这是可以通过使用-L选项进行强制重定向

让curl使用地址重定向,此时会查询google.com.hk站点
curl -L http://www.google.com

断点续传

通过使用-C选项可对大文件使用断点续传功能,如:

# 当文件在下载完成之前结束该进程
$ curl -O http://www.gnu.org/software/gettext/manual/gettext.html
##############             20.1%

# 通过添加-C选项继续对该文件进行下载,已经下载过的文件不会被重新下载
curl -C - -O http://www.gnu.org/software/gettext/manual/gettext.html
###############            21.1%

对CURL使用网络限速

通过–limit-rate选项对CURL的最大网络使用进行限制

下载速度最大不会超过1000B/second
 
curl --limit-rate 1000B -O http://www.gnu.org/software/gettext/manual/gettext.html

下载指定时间内修改过的文件

当下载一个文件时,可对该文件的最后修改日期进行判断,如果该文件在指定日期内修改过,就进行下载,否则不下载。
该功能可通过使用-z选项来实现:

若yy.html文件在2011/12/21之后有过更新才会进行下载
curl -z 21-Dec-11 http://www.example.com/yy.html

CURL授权

在访问需要授权的页面时,可通过-u选项提供用户名和密码进行授权

 curl -u username:password URL
 
 # 通常的做法是在命令行只输入用户名,之后会提示输入密码,这样可以保证在查看历史记录时不会将密码泄露
 curl -u username URL

从FTP服务器下载文件

CURL同样支持FTP下载,若在url中指定的是某个文件路径而非具体的某个要下载的文件名,CURL则会列出该目录下的所有文件名而并非下载该目录下的所有文件

 # 列出public_html下的所有文件夹和文件
 curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/
 
 # 下载xss.php文件
 curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/xss.php

上传文件到FTP服务器

通过 -T 选项可将指定的本地文件上传到FTP服务器上

# 将myfile.txt文件上传到服务器
curl -u ftpuser:ftppass -T myfile.txt ftp://ftp.testserver.com

# 同时上传多个文件
curl -u ftpuser:ftppass -T "{file1,file2}" ftp://ftp.testserver.com

# 从标准输入获取内容保存到服务器指定的文件中
curl -u ftpuser:ftppass -T - ftp://ftp.testserver.com/myfile_1.txt

获取更多信息

通过使用 -v 和 -trace获取更多的链接信息

通过字典查询单词

# 查询bash单词的含义
curl dict://dict.org/d:bash

# 列出所有可用词典
curl dict://dict.org/show:db

# 在foldoc词典中查询bash单词的含义
curl dict://dict.org/d:bash:foldoc

为CURL设置代理

x 选项可以为CURL添加代理功能

 # 指定代理主机和端口
 curl -x proxysever.test.com:3128 http://google.co.in

保存与使用网站cookie信息

 # 将网站的cookies信息保存到sugarcookies文件中
 curl -D sugarcookies http://localhost/sugarcrm/index.php
 
 # 使用上次保存的cookie信息
 curl -b sugarcookies http://localhost/sugarcrm/index.php

传递请求数据

默认curl使用GET方式请求数据,这种方式下直接通过URL传递数据
可以通过 –data/-d 方式指定使用POST方式传递数据

# GET
curl -u username https://api.github.com/user?access_token=XXXXXXXXXX

# POST
curl -u username --data "param1=value1&param2=value" https://api.github.com

# 也可以指定一个文件,将该文件中的内容当作数据传递给服务器端
curl --data @filename https://github.api.com/authorizations

注:默认情况下,通过POST方式传递过去的数据中若有特殊字符,首先需要将特殊字符转义在传递给服务器端,如value值中包含有空格,则需要先将空格转换成%20,如:

curl -d "value%201" http://hostname.com

在新版本的CURL中,提供了新的选项 –data-urlencode,通过该选项提供的参数会自动转义特殊字符。

curl --data-urlencode "value 1" http://hostname.com

除了使用GET和POST协议外,还可以通过 -X 选项指定其它协议,如:

curl -I -X DELETE https://api.github.cim

上传文件

curl --form "fileupload=@filename.txt" http://hostname/resource