Giter VIP home page Giter VIP logo

guanpengchn.github.io's Introduction

guanpengchn.github.io's People

Contributors

guanpengchn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

guanpengchn.github.io's Issues

markdown示例

在文字写书写不同数量的#可以完成不同的标题,如下:

一级标题

二级标题

三级标题

四级标题

五级标题
六级标题

等号及减号也可以进行标题的书写,等号代表一级标题,减号代表二级标题,并且需要写在文字的下面,减号及等号的数量不会影响标题的基数,如下:

一级标题

二级标题

无序列表的使用,在符号“-”后加空格使用。如下:

  • 无序列表1
  • 无序列表2
  • 无序列表3

如果要控制列表的层级,则需要在符号“-”前使用空格。如下:

  • 无序列表1
  • 无序列表2
    • 无序列表2.1
      • 列表内容
      • 列表内容

有序列表的使用,在数字及符号“.”后加空格几个,如下:

  1. 有序列表1
  2. 有序列表2
  3. 有序列表3

引用的格式是使用符号“>”后面书写文字,及可以使用引用。如下:

这个是引用
是不是和电子邮件中的
引用格式很像

粗体的使用是在需要加粗的文字前后各加两个“”,而斜体的使用则是在需要斜体的文字前后各加一个“”,如果要使用粗体和斜体,那么就是在需要操作的文字前后各加三个“*”。如下:
这个是粗体
这个是斜体
这个是粗体加斜体

在文中直接加链接,中括号中是需要添加链接的文字,圆括号中是需要添加的链接,如下:
link text

在引用中加链接,第一个中括号添加需要添加的文字,第二个中括号中是引用链接的id,之后在引用中,使用id加链接:如下:
[link text][id]
[id]: http://example.com/ "optional title here"

在文中直接引用链接,直接使用尖括号,把链接加入到尖括号中就可以实现,如下:
http://example.com/ or [email protected]
插入互联网上图片,格式如下:
这里写图片描述
![这里写图片描述][jane-eyre-douban]

用TAB键起始的段落,会被认为是代码块,如下:

echo “hello world";

如果在一个行内需要引用代码,只要用反引号引起来就好,如下: Use the printf()` function.

可以在一行中用三个以上的星号、减号、底线来建立一个分隔线,同时需要在分隔线的上面空一行。如下:




删除线的使用,在需要删除的文字前后各使用两个符合“~”,如下
Mistaken text.

在需要高亮的代码块的前一行及后一行使用三个反引号“`”,同时第一行反引号后面表面代码块所使用的语言,如下:

require 'redcarpet' 
markdown = Redcarpet.new("Hello World!") 
puts markdown.to_html 

可以使用冒号来定义表格的对齐方式,如下:

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

使用MathJax渲染LaTex 数学公式,详见[ math.stackexchange.com]
行内公式,数学公式为:
$\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N$
块级公式:
$$ x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$

可以渲染序列图:

张三->李四: 嘿,小四儿, 写博客了没? 
Note right of 李四: 李四愣了一下,说: 
李四-->张三: 忙得吐血,哪有时间写。 

或者流程图:

st=>start: 开始 
e=>end: 结束 
op=>operation: 我的操作 
cond=>condition: 确认?

st->op->cond 
cond(yes)->e 
cond(no)->op 
  • 关于 序列图 语法,参考 [这里]

前端Tips

Hyperleger-Fabric调用SDK的各种报错和解决方案

1.创建用户报错SSL

问题描述

大概上周一周的时间都在调这个bug,今天总算知道原因了,先把情况列出来,首先是使用了Fabric官网的Node SDK例子balance_transfer,在第一步发请求注册的时候出现的问题

  • 发送请求
$ curl -s -X POST http://localhost:4000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=Jim&orgName=Org1'
  • 报错
{"success":false,"message":"failed Error: Calling enrollment endpoint failed with error [Error: write EPROTO 140735804384128:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:\n]"}%
  • 使用单步调试,最终错误定位到了/balance-transfer/node_modules/fabric-ca-client/lib/FabricCAClientImpl.js的844行代码上,代码段如下:
var request = self._httpClient.request(requestOptions, function (response) {
    const responseBody = [];
    response.on('data', function (chunk) {
        responseBody.push(chunk);
    });

    response.on('end', function () {

        var payload = responseBody.join('');

        if (!payload) {
            reject(new Error(
                util.format('Enrollment failed with HTTP status code ', response.statusCode)));
        }
        //response should be JSON
        try {
            var res = JSON.parse(payload);
            if (res.success) {
                //we want the result field which is Base64-encoded PEM
                var enrollResponse = new Object();
                // Cert field is Base64-encoded PEM
                enrollResponse.enrollmentCert = Buffer.from(res.result.Cert, 'base64').toString();
                enrollResponse.caCertChain = Buffer.from(res.result.ServerInfo.CAChain, 'base64').toString();
                return resolve(enrollResponse);
            } else {
                return reject(new Error(
                    util.format('Enrollment failed with errors [%s]', JSON.stringify(res.errors))));
            }

        } catch (err) {
            reject(new Error(
                util.format('Could not parse enrollment response [%s] as JSON due to error [%s]', payload, err)));
        }
    });
});

request.on('error', function (err) {
reject(new Error(util.format('Calling enrollment endpoint failed with error [%s]', err)));
});

let body = JSON.stringify(enrollRequest);
request.write(body);
request.end();
  • 其中_httpClient值为https,也就是nodejs自带的模块,通过require('https')引入的,也就是相当于在发送https请求的时候报错

  • 该错误在网上搜了很久,也用了github上很多人提到的解决方案,但是并不奏效,最后发现是在fabric的基本docker-compose.yaml配置文件和base.yaml配置文件中有相关配置

  • 也就是TLS_ENABLED相关字段的配置,被配置成了false,尤其是CA部分的,会导致存在https无法请求的问题,换成http就成功了

解决方案

  • 修改network_config.yaml文件

  • certificateAuthories处的ca都由https配置成http的,并且打开httpOptions配置为true,配置修改如下

certificateAuthorities:
  ca0.chainplaza.com:
    url: http://localhost:7054
    # the properties specified under this object are passed to the 'http' client verbatim when
    # making the request to the Fabric-CA server
    httpOptions:
      verify: true
    tlsCACerts:
      path: ../network/crypto-config/peerOrganizations/org0.chainplaza.com/ca/ca.org0.chainplaza.com-cert.pem

    # Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is
    # needed to enroll and invoke new users.
    registrar:
      - enrollId: admin
        enrollSecret: adminpw
    # [Optional] The optional name of the CA.
    caName: ca0.chainplaza.com

  ca1.chainplaza.com:
    url: http://localhost:8054
    httpOptions:
      verify: true
    tlsCACerts:
      path: ../network/crypto-config/peerOrganizations/org1.chainplaza.com/ca/ca.org1.chainplaza.com-cert.pem
    registrar:
      - enrollId: admin
        enrollSecret: adminpw
    # [Optional] The optional name of the CA.
    caName: ca1.chainplaza.com

  ca2.chainplaza.com:
    url: http://localhost:9054
    httpOptions:
      verify: true
    tlsCACerts:
      path: ../network/crypto-config/peerOrganizations/org2.chainplaza.com/ca/ca.org2.chainplaza.com-cert.pem
    registrar:
      - enrollId: admin
        enrollSecret: adminpw
    # [Optional] The optional name of the CA.
    caName: ca2.chainplaza.com

2.创建channel报错SSL

问题描述

  • 首先基于第一步成功注册用户,获取token,执行
$ token=<put JSON Web Token here>
  • 发送请求
$ curl -s -X POST \
  http://localhost:4000/channels \
  -H "authorization: Bearer $token" \
  -H "content-type: application/json" \
  -d '{
    "channelName":"mychannel",
    "channelConfigPath":"../artifacts/channel/mychannel.tx"
}'
  • 报错
E0702 16:48:37.113124000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0702 16:48:37.117412000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
error: [Orderer.js]: sendBroadcast - on error: "Error: Connect Failed\n    at ClientDuplexStream._emitStatusIfDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:255:19)\n    at ClientDuplexStream._readsDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:221:8)\n    at readCallback (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:283:12)"
[2018-07-02 16:48:37.124] [ERROR] Create-Channel - Error: SERVICE_UNAVAILABLE
    at ClientDuplexStream.<anonymous> (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/fabric-client/lib/Orderer.js:136:21)
    at emitOne (events.js:116:13)
    at ClientDuplexStream.emit (events.js:211:7)
    at ClientDuplexStream._emitStatusIfDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:258:12)
    at ClientDuplexStream._readsDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:221:8)
    at readCallback (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:283:12)
(node:28483) UnhandledPromiseRejectionWarning: Error: Failed to initialize the channel: Error: SERVICE_UNAVAILABLE
    at Object.createChannel (/Users/guanpengchn/Code/chain_plaza/balance-transfer/app/create-channel.js:65:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:28483) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing insideof an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:28483) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
E0702 16:48:57.113731000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0702 16:48:57.120118000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
  • 将错误定位到了orderer节点的broadcast的函数上,根据错误提示,其实本质上也是由于协议错误导致的,根据github上的一个回答,使用http协议时不要用grpcs,而要用grpc

解决方案

3.创建用户报错Failed to get Affiliation

问题描述

  • 注册用户发送请求
$ curl -s -X POST http://localhost:4000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=Jim&orgName=Org0'
  • 报错
{"success":false,"message":"failed Error: fabric-ca request register failed with errors [[{\"code\":63,\"message\":\"Failed to get Affiliation: sql: no rows in result set\"}]]"}%
  • 获取到资料表示说,fabric-ca只有org1.department1 org1.department2 org2.department1,所以此处使用Org0报错

解决方案

  • 在命令行执行如下语句,其中fabric-ca-clientfabric-samples/bin中,其中7054是ca0的端口,相对应关系
$ fabric-ca-client enroll -u http://admin:adminpw@localhost:7054
2018/07/02 17:51:00 [INFO] Created a default configuration file at /Users/guanpengchn/.fabric-ca-client/fabric-ca-client-config.yaml
2018/07/02 17:51:00 [INFO] generating key: &{A:ecdsa S:256}
2018/07/02 17:51:00 [INFO] encoded CSR
2018/07/02 17:51:00 [INFO] Stored client certificate at /Users/guanpengchn/.fabric-ca-client/msp/signcerts/cert.pem
2018/07/02 17:51:00 [INFO] Stored root CA certificate at /Users/guanpengchn/.fabric-ca-client/msp/cacerts/localhost-7054.pem
2018/07/02 17:51:00 [INFO] Stored intermediate CA certificates at /Users/guanpengchn/.fabric-ca-client/msp/intermediatecerts/localhost-7054.pem

$ fabric-ca-client affiliation add org0
2018/07/02 17:51:09 [INFO] Configuration file location: /Users/guanpengchn/.fabric-ca-client/fabric-ca-client-config.yaml
Successfully added affiliation: org0

$ fabric-ca-client affiliation add org0.department1
2018/07/02 17:51:15 [INFO] Configuration file location: /Users/guanpengchn/.fabric-ca-client/fabric-ca-client-config.yaml
Successfully added affiliation: org0.department1

这时候再注册就成功了

4、create Affiliation的rest接口实现

问题描述

  • 之前通过命令行的方式能够成功添加affiliation,但是并不方便有缺陷,balance_transfer中的例子又没有做相关工作,倒是在fabcar中有使用,但虽然目的一样,实际上实现有很大差别,无法使用

解决方案

  • 于是通过debug后发现helper.jsgetRegisteredUser函数中,在enroll了admin之后的caClient变量有newAffiliationService函数

  • 仿照fabcar中的调用方式和helper.js的getRegisteredUser函数写法,做了如下实现

helper.js添加代码如下

var createAffiliation = async function(affiliationName) {
    try {
        var client = await getClientForOrg(affiliationName);
        logger.debug('Successfully initialized the credential stores');
        var admins = hfc.getConfigSetting('admins');
        let adminUserObj = await client.setUserContext({username: admins[0].username, password: admins[0].secret});
        let caClient = client.getCertificateAuthority();
        let tmp = await caClient.newAffiliationService().create({ name: affiliationName }, adminUserObj );
        logger.debug('Successfully create affiliation');
        var response = {
            success: true,
            message: affiliationName + ' create Successfully',
        };
        return response;
    } catch(error) {
        logger.error('Failed to create affiliation with error: %s', error.toString());
        logger.error(error.stack.toString());
        return 'failed '+error.toString();
    }

};

app.js中添加代码如下

// Create Affiliation
app.post('/affiliations', async function(req, res) {
    logger.info('<<<<<<<<<<<<<<<<< C R E A T E  A F F I L I A T I O N >>>>>>>>>>>>>>>>>');
    logger.debug('End point : /affiliation');
    var orgName = req.body.orgName;
    logger.debug('Affiliation name : ' + orgName);
    if (!orgName) {
        res.json(getErrorMessage('\'orgName\''));
        return;
    }

    let response = await helper.createAffiliation(orgName);

    if (response && typeof response !== 'string') {
        logger.debug('Successfully create affiliation %s ',orgName);
        res.json(response);
    } else {
        logger.debug('Failed to create affiliation %s with::%s',orgName,response);
        res.json({success: false, message: response});
    }
});

这样实现了rest接口,能够create affiliation,执行

$ fabric-ca-client affiliation list

即可看添加结果,最后一行

5、使用balance-transfer遇到无效网络配置

问题描述

Error: Invalid network configuration due to missing configuration data

解决方案

  • 原因就是在artifacts下的yaml文件缺失,所以找不到,涉及到的文件为artifacts/network-config.yaml,artifacts/org1.yaml,artifacts/org2.yaml等,文件所在目录

  • 其中在config.js文件中配有文件查询的代码

var util = require('util');
var path = require('path');
var hfc = require('fabric-client');

var file = 'network-config%s.yaml';

var env = process.env.TARGET_NETWORK;
if (env)
	file = util.format(file, '-' + env);
else
	file = util.format(file, '');
// indicate to the application where the setup file is located so it able
// to have the hfc load it to initalize the fabric client instance
hfc.setConfigSetting('network-connection-profile-path',path.join(__dirname, 'artifacts' ,file));
hfc.setConfigSetting('Org1-connection-profile-path',path.join(__dirname, 'artifacts', 'org1.yaml'));
hfc.setConfigSetting('Org2-connection-profile-path',path.join(__dirname, 'artifacts', 'org2.yaml'));
// some other settings the application might need to know
hfc.addConfigFile(path.join(__dirname, 'config.json'));
  • 其中要特别指出的是,在所有rest接口传入的orgName的变量都是根据'Org1-connection-profile-path'中的前面Org1来做文件查找的,在代码里体现就是

代码位置

// get a fabric client loaded with a connection profile for this org
let config = '-connection-profile-path';
    
// build a client context and load it with a connection profile
// lets only load the network settings and save the client for later
let client = hfc.loadFromConfig(hfc.getConfigSetting('network'+config));
    

6、create Affiliation后依然报错Failed to get Affiliation

问题描述

  • 在添加好上述rest接口之后,做了rest请求并且成功添加了org0,但是下一步注册依然报错

解决方案

  • 原因在于在注册时被代码字符串连接了一个department1,所以只添加了org0是无法注册的,要添加org0.department1才可以,但是rest方式无法做到,所以我就删掉了后面的字符串拼接,原代码
let secret = await caClient.register({
    enrollmentID: username,
    affiliation: userOrg.toLowerCase() + '.department1'
}, adminUserObj);

修改后的代码

let secret = await caClient.register({
enrollmentID: username,
affiliation: userOrg.toLowerCase()
}, adminUserObj);

7、instantiate chaincode时args参数为空报错

问题描述

  • 在发instantiate chaincode的http请求中包含如下参数
{
    "peers": ["peer4.org2.chainplaza.com"],
    "chaincodeName":"hospital2",
    "chaincodeVersion":"0",
    "chaincodeType": "golang",
    "args": []
}

其中args:[]这里参数为空,结果报错

"Incorrect arguments. Expecting no initial arguments"

解决方案

  • 该错误是我们写的chaincode中的报错,代码如下:
args := stub.GetStringArgs()
if len(args) != 0 {
    return shim.Error("Incorrect arguments. Expecting no initial arguments")
}
const args = [];
//args.push(Buffer.from(request.fcn ? request.fcn : 'init', 'utf8'));
  • 不注释掉就会导致chaincode一侧需要0个参数,而存在LSCC操作在真正的instantiate前面,但LSCC因为上面那行代码却有一个参数,故而报错,代操作代码如下
        /*
	 * Internal method to handle both chaincode calls
	 */
	_sendChaincodeProposal(request, command, timeout) {
		let errorMsg = null;

		//validate the incoming request
		if (!errorMsg) errorMsg = clientUtils.checkProposalRequest(request);
		if (!errorMsg) errorMsg = clientUtils.checkInstallRequest(request);
		if (errorMsg) {
			logger.error('sendChainCodeProposal error ' + errorMsg);
			return Promise.reject(new Error(errorMsg));
		}
		const peers = this._getTargets(request.targets, Constants.NetworkConfig.ENDORSING_PEER_ROLE);

		// args is optional because some chaincode may not need any input parameters during initialization
		if (!request.args) {
			request.args = [];
		}

		// step 1: construct a ChaincodeSpec
		const args = [];
		//args.push(Buffer.from(request.fcn ? request.fcn : 'init', 'utf8'));

		for (let arg of request.args)
			args.push(Buffer.from(arg, 'utf8'));

		const ccSpec = {
			type: clientUtils.translateCCType(request.chaincodeType),
			chaincode_id: {
				name: request.chaincodeId,
				version: request.chaincodeVersion
			},
			input: {
				args: args
			}
		};

		// step 2: construct the ChaincodeDeploymentSpec
		const chaincodeDeploymentSpec = new _ccProto.ChaincodeDeploymentSpec();
		chaincodeDeploymentSpec.setChaincodeSpec(ccSpec);

		const signer = this._clientContext._getSigningIdentity(request.txId.isAdmin());
		const lcccSpec_args = [
			Buffer.from(command),
			Buffer.from(this._name),
			chaincodeDeploymentSpec.toBuffer()
		];
		if (request['endorsement-policy']) {
			lcccSpec_args[3] = this._buildEndorsementPolicy(request['endorsement-policy']);
		}

		const lcccSpec = {
			// type: _ccProto.ChaincodeSpec.Type.GOLANG,
			type: clientUtils.translateCCType(request.chaincodeType),
			chaincode_id: { name: Constants.LSCC },
			input: { args: lcccSpec_args }
		};

		const channelHeader = clientUtils.buildChannelHeader(
			_commonProto.HeaderType.ENDORSER_TRANSACTION,
			this._name,
			request.txId.getTransactionID(),
			null,
			Constants.LSCC,
			clientUtils.buildCurrentTimestamp(),
			peers[0].getClientCertHash()
		);
		const header = clientUtils.buildHeader(signer, channelHeader, request.txId.getNonce());
		const proposal = clientUtils.buildProposal(lcccSpec, header, request.transientMap);
		const signed_proposal = clientUtils.signProposal(signer, proposal);

		return clientUtils.sendPeersProposal(peers, signed_proposal, timeout)
			.then(
				function (responses) {
					return [responses, proposal];
				}
			);
	}

Permission denied on accessing host directory in docker

按照阮一峰的做一个apache的php环境docker启动,结果发现出现权限问题,和volume参数有关,即便进入docker内部使用root权限也无法解决,查找到有一个解决方案,在docker启动命令中加入如下参数

--privileged=true
docker container run \
--rm \
--privileged=true \
--name wordpress \
--volume "$PWD/":/var/www/html \
php:5.6-apache

参考连接:https://stackoverflow.com/questions/24288616/permission-denied-on-accessing-host-directory-in-docker

golang调用python

golang调用python方案列表

  • go-python包
  • qiniu/py包
  • google的grumpy
  • http服务
  • 命令行调用

go-python

执行

go get github.com/sbinet/go-python
  • 第一个报错是找不到pkg-config,这个是由于mac环境导致的,解决方案
brew install pkg-config
  • 第二个报错如下
# pkg-config --cflags python-2.7
Package python-2.7 was not found in the pkg-config search path.
Perhaps you should add the directory containing `python-2.7.pc'
to the PKG_CONFIG_PATH environment variable
No package 'python-2.7' found
pkg-config: exit status 1

解决方案

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/pkgconfig
  • 在执行过程中,keras包报错invalid memory address or nil pointer dereference无法解决

qiniu/py

  • 需要将python代码放到golang中去执行
  • 同样存在机器学习包支持的问题

google的grumpy

  • Grumpy是将Python源码编译为Go源代码,然后将其编译为本地代码
  • 对于机器学习相关包的支持不足

http服务

  • 不可行,需要每次启动docker就默认启动服务,而且服务会更容易中断

命令行调用

  • 传入参数使用docopt来做,参考资料
  • golang操作json代码
package main
 
import (
    "encoding/json"
    "fmt"
    "os"
)
 
type ConfigStruct struct {
    Host              string   `json:"host"`
    Port              int      `json:"port"`
    AnalyticsFile     string   `json:"analytics_file"`
    StaticFileVersion int      `json:"static_file_version"`
    StaticDir         string   `json:"static_dir"`
    TemplatesDir      string   `json:"templates_dir"`
    SerTcpSocketHost  string   `json:"serTcpSocketHost"`
    SerTcpSocketPort  int      `json:"serTcpSocketPort"`
    Fruits            []string `json:"fruits"`
}
 
type Other struct {
    SerTcpSocketHost string   `json:"serTcpSocketHost"`
    SerTcpSocketPort int      `json:"serTcpSocketPort"`
    Fruits           []string `json:"fruits"`
}
 
func main() { 
    jsonStr := `{"host": "http://localhost:9090","port": 9090,"analytics_file": "","static_file_version": 1,"static_dir": "E:/Project/goTest/src/","templates_dir": "E:/Project/goTest/src/templates/","serTcpSocketHost": ":12340","serTcpSocketPort": 12340,"fruits": ["apple", "peach"]}`
 
    //json str 转map
    var dat map[string]interface{}
    if err := json.Unmarshal([]byte(jsonStr), &dat); err == nil {
        fmt.Println("==============json str 转map=======================")
        fmt.Println(dat)
        fmt.Println(dat["host"])
    }
 
    //json str 转struct
    var config ConfigStruct
    if err := json.Unmarshal([]byte(jsonStr), &config); err == nil {
        fmt.Println("================json str 转struct==")
        fmt.Println(config)
        fmt.Println(config.Host)
    }
 
    //json str 转struct(部份字段)
    var part Other
    if err := json.Unmarshal([]byte(jsonStr), &part); err == nil {
        fmt.Println("================json str 转struct==")
        fmt.Println(part)
        fmt.Println(part.SerTcpSocketPort)
    }
 
    //struct 到json str
    if b, err := json.Marshal(config); err == nil {
        fmt.Println("================struct 到json str==")
        fmt.Println(string(b))
    }
 
    //map 到json str
    fmt.Println("================map 到json str=====================")
    enc := json.NewEncoder(os.Stdout)
    enc.Encode(dat)
 
    //array 到 json str
    arr := []string{"hello", "apple", "python", "golang", "base", "peach", "pear"}
    lang, err := json.Marshal(arr)
    if err == nil {
        fmt.Println("================array 到 json str==")
        fmt.Println(string(lang))
    }
 
    //json 到 []string
    var wo []string
    if err := json.Unmarshal(lang, &wo); err == nil {
        fmt.Println("================json 到 []string==")
        fmt.Println(wo)
    }
}
  • 命令行
python modelchain_lr.py --p_batch_size=128 --p_epochs=20 --p_max_rounds=200 --p_verbosity=1 --p_inc_cutoff=-0.01 --p_p_cutoff=0.25 --p_rb_tolerance=16
# setup channel
peer channel create -o orderer.chainplaza.com:7050 -c chainplaza -f /etc/chainplaza/conf/material/chainplaza.tx 

# join channel
CORE_PEER_MSPCONFIGPATH=/etc/chainplaza/conf/crypto/peerOrganizations/org1.chainplaza.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer2.org1.chainplaza.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
peer channel join -b chainplaza.block

# install and instantiate modelchain
peer chaincode install -p github.com/chainplaza/chaincode/test -n modelchain -v 0
peer chaincode instantiate -n modelchain -v 0 -c '{"Args":[]}' -C chainplaza

# invoke modelchain
peer chaincode invoke -n modelchain -c '{"Args":["modelchain"]}' -C chainplaza

Install anaconda

cd /tmp
curl -O https://repo.anaconda.com/archive/Anaconda2-5.2.0-Linux-x86_64.sh
chmod +x Anaconda2-5.2.0-Linux-x86_64.sh
./Anaconda2-5.2.0-Linux-x86_64.sh
source /root/.bashrc
cd -
pip install requirements.txt

排序

int partition(vector<int> &vi, int low, int up)
{
	int pivot = vi[up];
	int i = low-1;
	for (int j = low; j < up; j++)
	{
		if(vi[j] <= pivot)
		{
			i++;
			swap(vi[i], vi[j]);
		}
	}
	swap(vi[i+1], vi[up]);
	return i+1;
}
//C++'s array range should be [low, up], the same as [low, up+1)
void quickSort(vector<int> &vi, int low, int up)
{
	if(low < up)
	{
		int mid = partition(vi, low, up);
		//Watch out! The mid position is on the place, so we don't need to consider it again.
		//That's why below is mid-1, not mid! Otherwise it will occur overflow error!!!
		quickSort(vi, low, mid-1);
		quickSort(vi, mid+1, up);
	}
}

归并排序

void Merge(int a[],int left,int mid,int right)
{
	//两段区间的长度
	int length1 = mid-left+1;
	int length2 = right-mid;

	//分配两段新的内存空间存储原内容
	int *l1 = new int[length1];
	int *l2 = new int[length2];

	for (int i = 0; i < length1; ++i)
	{
		l1[i] = a[left+i];
	}
	for (int j = 0; j < length2; ++j)
	{
		l2[j] = a[j+mid+1];
	}

	//存入原内容之后,比较两个序列
	int i = 0,j = 0;
	int k = length1;
	//比较两个序列的重合部分,进行排序
	while (i<length1 && j<length2)
	{
		if (l1[i] < l2[j])
		{
			a[left++] = l1[i++];
		}
		else
		{
			a[left++] = l2[j++];
			//因为l2[j]大于l1[i],所以l2[j]肯定大于[0,length-1]之中[0,i]之间的所有数,产生逆序对
			if (l2[j] > l1[i])
			{
				_count +=  length1-i+1;
			}		
		}
	}
	//两序列的剩余部分分别放于结尾
	while (i<length1)
	{
		a[left++] = l1[i++];
	}

	while (j<length2)
	{
		a[left++] = l2[j++];
	}

	//分配的内存需要释放掉
	delete []l1;
	delete []l2;
}
void Merge_sort(int a[],int left,int right)
{
	if (left < right)
	{
		int mid = (left+right)/2;//首先进行分区,然后递归操作
		Merge_sort(a,left,mid);
		Merge_sort(a,mid+1,right);//第一次将其分为两个区间,进行合并操作
		Merge(a,left,mid,right);
	}
}

二叉树的深度

##题目描述

输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。

/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
    int TreeDepth(TreeNode* pRoot){
        if(!pRoot){
            return 0;
        }
        return max(1+TreeDepth(pRoot->left) , 1+TreeDepth(pRoot->right));
    }
};

python将unicode和str互相转化

问题一:
将u'\u810f\u4e71'转换为'\u810f\u4e71'
 
方法:
s_unicode = u'\u810f\u4e71'
s_str = s_unicode.encode('unicode-escape').decode('string_escape')
 
问题二:
将'\u810f\u4e71'转换为u'\u810f\u4e71'
方法:s_str = '\u810f\u4e71's_unicode = s_str.decode('unicode-escape')

问题三:
将'\xe5\x8c\x97'转换为'\\u5317'
方法:s_x = '\xe5\x8c\x97' s_uescape = s_x.decode('utf-8').encode('unicode-escape')

设计相关网站和资料

对称的二叉树

题目描述

请实现一个函数,用来判断一颗二叉树是不是对称的。注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。

/*
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};
*/
class Solution {
public:
    bool Calc(TreeNode* left, TreeNode* right){
        if(left==nullptr){
            return right == nullptr;
        }
        if(right==nullptr){
            return false;
        }
        if(right->val != left->val){
            return false;
        }
        return Calc(left->right, right->left) && Calc(left->left, right->right);
    }
    bool isSymmetrical(TreeNode* pRoot)
    {
        if(!pRoot){
            return true;
        }
        return Calc(pRoot->left, pRoot->right);
    }

};

Tech Company Organizational Chart

Tech Company Organizational Chart

14pic

That's the point, it's just meant to be funny and not an actual look at any corporate structures. Google's is a neural network, Facebook's is a social graph, Apple has the dictator, Microsoft has everyone pointing guns at each other, Oracle is their legal team, and even Amazon's matches their hierarchical product website. In reality they all had similar corporate structures with layers of management, but there's some truth behind the caricatures. Microsoft did have a lot of infighting, Apple did have Steve Jobs acting as dictator, and Oracle sued Google over the Java API. The Google and Facebook ones seem to be complete jokes.

How Tech Companies Apologize

14-2

用两个栈实现队列

题目描述

用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。

class Solution
{
public:
    void push(int node) {
        stack1.push(node);
    }

    int pop() {
        if(stack2.empty()){
            while(!stack1.empty()){
                stack2.push(stack1.top());
                stack1.pop();
            }
        }
        int res = stack2.top();
        stack2.pop();
        return res;
    }

private:
    stack<int> stack1;
    stack<int> stack2;
};

链表中倒数第k个结点

题目描述

输入一个链表,输出该链表中倒数第k个结点。

/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
public:
    ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
        if(pListHead == NULL){
            return NULL;
        }
        if(k<=0){
            return NULL;
        }
        ListNode* pre = pListHead;
        ListNode* real = pListHead;
        for(int i=1;i<k;i++){
            if(pre->next == NULL)
                return NULL;
            pre = pre->next;
        }
        while(pre->next!=NULL){
            pre = pre->next;
            real = real->next;
        }
        return real;
    }
};

后台开发Tips

C++

数据库

网络安全

计算机网络

OpenGL

编程语言

二叉树中和为某一值的路径

题目描述

输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前)

/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
    vector<vector<int> > result;
    vector<int> tmp;
public:
    void Calc(TreeNode* root,int num){
        tmp.push_back(root->val);
        if(num - root->val == 0 && root->left == NULL && root->right == NULL){
            result.push_back(tmp);
        }else if(num - root->val > 0){
            if(root->left){
                Calc(root->left, num - root->val);
            }
            if(root->right){
                Calc(root->right, num - root->val);
            }
        }
        tmp.pop_back();
    }
    vector<vector<int> > FindPath(TreeNode* root,int expectNumber) {
        if(root){
            Calc(root,expectNumber);
        }
        return result;
    }
};

机器学习Tips

二叉树的下一个结点

题目描述

给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。

/*
struct TreeLinkNode {
    int val;
    struct TreeLinkNode *left;
    struct TreeLinkNode *right;
    struct TreeLinkNode *next;
    TreeLinkNode(int x) :val(x), left(NULL), right(NULL), next(NULL) {
        
    }
};
*/
class Solution {
public:
    TreeLinkNode* GetNext(TreeLinkNode* pNode)
    {
        if(!pNode){
            return nullptr;
        }
        TreeLinkNode* res = pNode;
        if(res->right){
            res = res->right;
            while(res->left){
                res = res->left;
            }
            return res;
        }else{
            res = res->next;
            while(res){
                if(res->val > pNode->val){
                    return res;
                }
                res = res->next;
            }
        }
        return nullptr;
    }
};

chaincode中使用go-python报错

在chaincode中加入以下几行就会在启动时报错

import (
	"fmt"

	"github.com/hyperledger/fabric/core/chaincode/shim"
	"github.com/hyperledger/fabric/protos/peer"
	"github.com/sbinet/go-python"
)

var PyStr = python.PyString_FromString
var GoStr = python.PyString_AS_STRING

model0 | # command-line-arguments
model0 | /opt/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
model0 | /tmp/go-link-679205363/000002.o: In function pluginOpen': model0 | /opt/go/src/plugin/plugin_dlopen.go:19: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(posixmodule.o): In function posix_tmpnam':
model0 | (.text.unlikely+0xfd8): warning: the use of tmpnam_r' is dangerous, better use mkstemp'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(posixmodule.o): In function posix_tempnam': model0 | (.text.unlikely+0xee1): warning: the use of tempnam' is dangerous, better use mkstemp' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(posixmodule.o): In function posix_initgroups':
model0 | (.text.unlikely+0x1c82): warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(grpmodule.o): In function grp_getgrall': model0 | (.text+0x45): warning: Using 'getgrent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(grpmodule.o): In function grp_getgrgid':
model0 | (.text+0x1e5): warning: Using 'getgrgid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(grpmodule.o): In function grp_getgrnam': model0 | (.text+0x162): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(grpmodule.o): In function grp_getgrall':
model0 | (.text+0x19): warning: Using 'setgrent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(grpmodule.o): In function grp_getgrall.cold.0': model0 | (.text.unlikely+0x85): warning: Using 'endgrent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(pwdmodule.o): In function pwd_getpwall':
model0 | (.text+0x205): warning: Using 'getpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(pwdmodule.o): In function pwd_getpwnam': model0 | (.text+0x31): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(pwdmodule.o): In function pwd_getpwuid':
model0 | (.text+0x155): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(pwdmodule.o): In function pwd_getpwall': model0 | (.text+0x1d9): warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(pwdmodule.o): In function pwd_getpwall.cold.4':
model0 | (.text.unlikely+0x171): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /tmp/go-link-679205363/000003.o: In function _cgo_b0c710f30cfd_C2func_getaddrinfo': model0 | /tmp/go-build/net/_obj/cgo-gcc-prolog:46: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(spwdmodule.o): In function spwd_getspall':
model0 | (.text.unlikely+0x15e): warning: Using 'getspent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(spwdmodule.o): In function spwd_getspnam': model0 | (.text.unlikely+0x20b): warning: Using 'getspnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(spwdmodule.o): In function spwd_getspall':
model0 | (.text.unlikely+0x159): warning: Using 'setspent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(spwdmodule.o): In function spwd_getspall': model0 | (.text.unlikely+0x1af): warning: Using 'endspent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(socketmodule.o): In functionsocket_gethostbyaddr':
model0 | (.text.hot+0x1fc): warning: Using 'gethostbyaddr_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(socketmodule.o): In functionsocket_gethostbyname_ex': model0 | (.text.unlikely+0x3b13): warning: Using 'gethostbyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(socketmodule.o): In functionsocket_getprotobyname':
model0 | (.text.unlikely+0x3e0b): warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(socketmodule.o): In functionsocket_getservbyname': model0 | (.text.unlikely+0x2b92): warning: Using 'getservbyname' in statically linked applications requires atruntime the shared libraries from the glibc version used for linking model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(socketmodule.o): In functionsocket_getservbyport':
model0 | (.text.unlikely+0x2c60): warning: Using 'getservbyport' in statically linked applications requires atruntime the shared libraries from the glibc version used for linking
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function _Py_c_abs': model0 | (.text+0x82b): undefined reference to hypot'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function complex_remainder': model0 | (.text+0x15be): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function complex_divmod': model0 | (.text+0x1890): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function _Py_c_pow': model0 | (.text+0x1ae7): undefined reference to hypot'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function _Py_c_pow': model0 | (.text+0x1af8): undefined reference to pow'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function _Py_c_pow': model0 | (.text+0x1b18): undefined reference to atan2'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function _Py_c_pow': model0 | (.text+0x1b4d): undefined reference to exp'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function _Py_c_pow': model0 | (.text+0x1b6a): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function _Py_c_pow': model0 | (.text+0x1b90): undefined reference to sincos'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function _Py_double_round': model0 | (.text+0x358): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function _Py_double_round': model0 | (.text+0x4de): undefined reference to round'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function _Py_double_round': model0 | (.text+0x570): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_divmod': model0 | (.text+0x724): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_divmod': model0 | (.text+0x7d7): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_is_integer': model0 | (.text.unlikely+0x1129): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_pow': model0 | (.text.hot+0x1bde): undefined reference to pow'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_pow': model0 | (.text.hot+0x1ca6): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_pow': model0 | (.text.hot+0x1ced): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_pow': model0 | (.text.hot+0x1d5b): undefined reference to pow'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_pow': model0 | (.text.hot+0x1fbf): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_pow': model0 | (.text.hot+0x2132): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_rem': model0 | (.text.hot+0x25f0): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_as_integer_ratio': model0 | (.text.hot+0x292c): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_as_integer_ratio': model0 | (.text.hot+0x295b): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_as_integer_ratio': model0 | (.text.hot+0x298a): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_as_integer_ratio': model0 | (.text.hot+0x29b9): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o): In function float_as_integer_ratio': model0 | (.text.hot+0x29e8): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(floatobject.o):(.text.hot+0x2a17): more undefined references to floor' follow model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(longobject.o): In function PyLong_FromString':
model0 | (.text.hot+0x2cb1): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atanh':
model0 | (.text+0x263): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atanh':
model0 | (.text+0x331): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atanh':
model0 | (.text+0x3f4): undefined reference to sqrt' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atanh':
model0 | (.text+0x412): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atanh':
model0 | (.text+0x417): undefined reference to sqrt' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atanh':
model0 | (.text+0x42d): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atanh':
model0 | (.text+0x469): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh':
model0 | (.text+0x517): undefined reference to sincos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh':
model0 | (.text+0x53a): undefined reference to cosh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh':
model0 | (.text+0x555): undefined reference to sinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh':
model0 | (.text+0x613): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh':
model0 | (.text+0x652): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh':
model0 | (.text+0x746): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh':
model0 | (.text+0x785): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh':
model0 | (.text+0x837): undefined reference to sincos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh':
model0 | (.text+0x85a): undefined reference to sinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh':
model0 | (.text+0x875): undefined reference to cosh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh':
model0 | (.text+0x933): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh':
model0 | (.text+0x972): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh':
model0 | (.text+0xa64): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh':
model0 | (.text+0xaa8): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh':
model0 | (.text+0xb9c): undefined reference to tanh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh':
model0 | (.text+0xbb1): undefined reference to tan' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh':
model0 | (.text+0xbc8): undefined reference to cosh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh':
model0 | (.text+0xc8f): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh':
model0 | (.text+0xca6): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh':
model0 | (.text+0xda8): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh':
model0 | (.text+0xdbf): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_asinh':
model0 | (.text+0xf2c): undefined reference to asinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_asinh':
model0 | (.text+0xf69): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_asinh':
model0 | (.text+0x103b): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_asinh':
model0 | (.text+0x1040): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_asinh':
model0 | (.text+0x1083): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_asinh':
model0 | (.text+0x108d): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_asinh':
model0 | (.text+0x1092): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sqrt':
model0 | (.text+0x11aa): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sqrt':
model0 | (.text+0x11ba): undefined reference to sqrt' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sqrt':
model0 | (.text+0x1313): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sqrt':
model0 | (.text+0x131d): undefined reference to sqrt' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log':
model0 | (.text+0x1537): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log':
model0 | (.text+0x1562): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log':
model0 | (.text+0x1578): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log':
model0 | (.text+0x163f): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log':
model0 | (.text+0x1644): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log':
model0 | (.text+0x16a8): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log':
model0 | (.text+0x16ad): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp':
model0 | (.text+0x177b): undefined reference to sincos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp':
model0 | (.text+0x17a1): undefined reference to exp' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp':
model0 | (.text+0x1874): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp':
model0 | (.text+0x18a6): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp':
model0 | (.text+0x19d6): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp':
model0 | (.text+0x19fd): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acos':
model0 | (.text+0x1b20): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acos':
model0 | (.text+0x1b5b): undefined reference to asinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acos':
model0 | (.text+0x1c0c): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acos':
model0 | (.text+0x1c5b): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acos':
model0 | (.text+0x1c60): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acosh':
model0 | (.text+0x1df9): undefined reference to asinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acosh':
model0 | (.text+0x1e15): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acosh':
model0 | (.text+0x1ecb): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acosh':
model0 | (.text+0x1ed0): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acosh':
model0 | (.text+0x1efa): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function cmath_rect':
model0 | (.text+0x22d3): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function cmath_rect':
model0 | (.text+0x2312): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function cmath_rect':
model0 | (.text+0x244a): undefined reference to sincos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_atan2':
model0 | (.text+0x20f4): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh.cold.2':
model0 | (.text.unlikely+0x2db5): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh.cold.2':
model0 | (.text.unlikely+0x2dc6): undefined reference to cosh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh.cold.2':
model0 | (.text.unlikely+0x2df2): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_cosh.cold.2':
model0 | (.text.unlikely+0x2e03): undefined reference to sinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh.cold.3':
model0 | (.text.unlikely+0x2e84): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh.cold.3':
model0 | (.text.unlikely+0x2e95): undefined reference to sinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh.cold.3':
model0 | (.text.unlikely+0x2ec1): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_sinh.cold.3':
model0 | (.text.unlikely+0x2ed2): undefined reference to cosh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh.cold.4':
model0 | (.text.unlikely+0x2f36): undefined reference to sincos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_tanh.cold.4':
model0 | (.text.unlikely+0x2f85): undefined reference to exp' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_log.cold.7':
model0 | (.text.unlikely+0x300c): undefined reference to atan2' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp.cold.8':
model0 | (.text.unlikely+0x3078): undefined reference to exp' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp.cold.8':
model0 | (.text.unlikely+0x3095): undefined reference to cos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_exp.cold.8':
model0 | (.text.unlikely+0x30c0): undefined reference to sin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acos.cold.9':
model0 | (.text.unlikely+0x3154): undefined reference to hypot' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function c_acos.cold.9':
model0 | (.text.unlikely+0x3159): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(cmathmodule.o): In function cmath_rect.cold.12':
model0 | (.text.unlikely+0x3364): undefined reference to sincos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(datetimemodule.o): In function round_to_long':
model0 | (.text+0x39e8): undefined reference to floor' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(datetimemodule.o): In function round_to_long.cold.58':
model0 | (.text.unlikely+0x16ec): undefined reference to ceil' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_exp':
model0 | (.text+0x9): undefined reference to exp' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_ceil':
model0 | (.text+0x26): undefined reference to ceil' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_atan':
model0 | (.text+0x56): undefined reference to atan' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_cosh':
model0 | (.text+0x289): undefined reference to cosh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_sinh':
model0 | (.text+0x2a9): undefined reference to sinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_tan':
model0 | (.text+0x2c6): undefined reference to tan' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_asin':
model0 | (.text+0x2d6): undefined reference to asin' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_tanh':
model0 | (.text+0x2e6): undefined reference to tanh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_acos':
model0 | (.text+0x2f6): undefined reference to acos' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_acosh':
model0 | (.text+0x4b6): undefined reference to acosh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_asinh':
model0 | (.text+0x4c6): undefined reference to asinh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_atanh':
model0 | (.text+0x4d6): undefined reference to atanh' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_factorial':
model0 | (.text+0x5f4): undefined reference to floor' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_fmod':
model0 | (.text+0x756): undefined reference to fmod' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_pow':
model0 | (.text+0x8e8): undefined reference to pow' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_pow':
model0 | (.text+0xa30): undefined reference to fmod' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_erf_series':
model0 | (.text+0xc93): undefined reference to exp' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_erfc_contfrac':
model0 | (.text+0xdab): undefined reference to exp' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_lgamma':
model0 | (.text+0xeaf): undefined reference to floor' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_lgamma':
model0 | (.text+0xefb): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_lgamma':
model0 | (.text+0xf0c): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_lgamma':
model0 | (.text+0xf34): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_lgamma':
model0 | (.text+0xf55): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_lgamma':
model0 | (.text+0xfce): undefined reference to log' model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o):(.text+0xff5):more undefined references to log' follow
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function sinpi': model0 | (.text+0x1102): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function sinpi': model0 | (.text+0x1115): undefined reference to round'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function sinpi': model0 | (.text+0x114a): undefined reference to cos'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function sinpi': model0 | (.text+0x1189): undefined reference to cos'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function sinpi': model0 | (.text+0x11a8): undefined reference to sin'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_tgamma': model0 | (.text+0x1216): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_tgamma': model0 | (.text+0x12d1): undefined reference to exp'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_tgamma': model0 | (.text+0x134c): undefined reference to pow'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_tgamma': model0 | (.text+0x1404): undefined reference to exp'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_tgamma': model0 | (.text+0x1454): undefined reference to pow'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_expm1': model0 | (.text+0x1479): undefined reference to expm1'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_log10': model0 | (.text+0x345): undefined reference to log10'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_atan2': model0 | (.text+0x3bf): undefined reference to atan2'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_fabs': model0 | (.text.unlikely+0x52b): undefined reference to fabs'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_hypot': model0 | (.text.unlikely+0x9aa): undefined reference to hypot'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function sinpi.cold.20': model0 | (.text.unlikely+0xedf): undefined reference to sin'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function sinpi.cold.20': model0 | (.text.unlikely+0xf05): undefined reference to sin'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_tgamma.cold.21': model0 | (.text.unlikely+0xf6d): undefined reference to pow'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_tgamma.cold.21': model0 | (.text.unlikely+0x106f): undefined reference to pow'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function m_log': model0 | (.text.unlikely+0x27d): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_1': model0 | (.text.hot+0xc0): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_1': model0 | (.text.hot+0x2c6): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_sqrt': model0 | (.text.hot+0x2e6): undefined reference to sqrt'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_log': model0 | (.text.hot+0x3e8): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_floor': model0 | (.text.hot+0xa86): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_cos': model0 | (.text.hot+0xae6): undefined reference to cos'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(mathmodule.o): In function math_sin': model0 | (.text.hot+0xaf6): undefined reference to sin'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(posixmodule.o): In function posix_openpty': model0 | (.text.unlikely+0xdcb): undefined reference to openpty'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(posixmodule.o): In function posix_forkpty': model0 | (.text.unlikely+0x2116): undefined reference to forkpty'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(signalmodule.o): In functionsignal_setitimer': model0 | (.text+0xc63): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(signalmodule.o): In functionsignal_setitimer': model0 | (.text+0xc80): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(signalmodule.o): In functionsignal_setitimer': model0 | (.text+0xca7): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(signalmodule.o): In functionsignal_setitimer': model0 | (.text+0xcc8): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(timemodule.o): In function time_sleep': model0 | (.text.hot+0xc8): undefined reference to fmod'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(timemodule.o): In function time_sleep': model0 | (.text.hot+0xd8): undefined reference to floor'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_crc32': model0 | (.text+0x4e): undefined reference to crc32'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompress': model0 | (.text+0x13e): undefined reference to inflateInit2_'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompress': model0 | (.text+0x168): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompress': model0 | (.text+0x189): undefined reference to inflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompress': model0 | (.text+0x1d5): undefined reference to inflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_compress': model0 | (.text+0x31d): undefined reference to deflateInit_'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_compress': model0 | (.text+0x348): undefined reference to deflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_compress': model0 | (.text+0x361): undefined reference to deflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_compressobj': model0 | (.text+0x487): undefined reference to deflateInit2_'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objcompress': model0 | (.text+0x5f5): undefined reference to deflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objcompress': model0 | (.text+0x691): undefined reference to deflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_flush': model0 | (.text+0x76c): undefined reference to deflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_flush': model0 | (.text+0x79c): undefined reference to deflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompressobj': model0 | (.text+0x88f): undefined reference to inflateInit2_'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_unflush': model0 | (.text+0x9a2): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_unflush': model0 | (.text+0xa08): undefined reference to inflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function Decomp_dealloc': model0 | (.text+0xae2): undefined reference to inflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_adler32': model0 | (.text+0xb7e): undefined reference to adler32'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompress.cold.3': model0 | (.text.unlikely+0x1aa): undefined reference to inflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompress.cold.3': model0 | (.text.unlikely+0x1b9): undefined reference to inflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_decompress.cold.3': model0 | (.text.unlikely+0x1de): undefined reference to inflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_compress.cold.4': model0 | (.text.unlikely+0x276): undefined reference to deflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_compress.cold.4': model0 | (.text.unlikely+0x28a): undefined reference to deflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_flush.cold.8': model0 | (.text.unlikely+0x41c): undefined reference to deflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objdecompress.cold.10': model0 | (.text.unlikely+0x657): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_unflush.cold.11': model0 | (.text.unlikely+0x80d): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function Comp_dealloc.cold.12': model0 | (.text.unlikely+0x84e): undefined reference to deflateEnd'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_copy': model0 | (.text.unlikely+0x941): undefined reference to deflateCopy'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_uncopy': model0 | (.text.unlikely+0xa77): undefined reference to inflateCopy'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objdecompress': model0 | (.text.hot+0x1b0): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objdecompress': model0 | (.text.hot+0x2d7): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objdecompress': model0 | (.text.hot+0x42a): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objdecompress': model0 | (.text.hot+0x4ac): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(zlibmodule.o): In function PyZlib_objdecompress': model0 | (.text.hot+0x52b): undefined reference to inflate'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_log1p': model0 | (.text+0xd): undefined reference to log1p'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_acosh': model0 | (.text.unlikely+0x64): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_acosh': model0 | (.text.unlikely+0xa3): undefined reference to sqrt'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_acosh': model0 | (.text.unlikely+0xf5): undefined reference to sqrt'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_asinh': model0 | (.text.unlikely+0x17c): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_asinh': model0 | (.text.unlikely+0x1b4): undefined reference to sqrt'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_asinh': model0 | (.text.unlikely+0x1e2): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_asinh': model0 | (.text.unlikely+0x201): undefined reference to sqrt'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_asinh': model0 | (.text.unlikely+0x231): undefined reference to log1p'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_atanh': model0 | (.text.unlikely+0x306): undefined reference to log1p'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_expm1': model0 | (.text.unlikely+0x358): undefined reference to exp'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_expm1': model0 | (.text.unlikely+0x385): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_expm1': model0 | (.text.unlikely+0x3ab): undefined reference to exp'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_acosh': model0 | (.text.unlikely+0xd3): undefined reference to log'
model0 | /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpython2.7.a(_math.o): In function _Py_acosh': model0 | (.text.unlikely+0x112): undefined reference to log1p'
model0 | collect2: error: ld returned 1 exit status
model0 |
model0 | ./cc0.sh: line 4: ./cc_model0: No such file or directory
model0 exited with code 127

平衡二叉树

题目描述

输入一棵二叉树,判断该二叉树是否是平衡二叉树。

class Solution {
public:
    int Calc(TreeNode* pRoot){
        if(pRoot == nullptr){
            return 0;
        }
        int left = Calc(pRoot->left);
        if(left == -1){
            return -1;
        }
        int right = Calc(pRoot->right);
        if(right == -1){
            return -1;
        }
        return abs(right - left)>1?-1:max(right,left)+1;
    }
    bool IsBalanced_Solution(TreeNode* pRoot) {
        if(Calc(pRoot) == -1){
            return false;
        }
        return true;
    }
};

从尾到头打印链表

题目描述

输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。

/**
*  struct ListNode {
*        int val;
*        struct ListNode *next;
*        ListNode(int x) :
*              val(x), next(NULL) {
*        }
*  };
*/
class Solution {
public:
    vector<int> printListFromTailToHead(ListNode* head) {
        stack<ListNode *> tmp;
        while(head){
            tmp.push(head);
            head = head->next;
        }
        vector<int> res;
        while(!tmp.empty()){
            res.push_back(tmp.top()->val);
            tmp.pop();
        }
        return res;
    }
};

java高并发编程

synchronized

  • 锁定的不是代码块,方法,而是对象,一定要明确,也就是对象锁

16-1

  • 静态的属性和方法要锁定当前类的Class对象,也就是所谓的类锁
public static void mm(){
    synchronized(T.class) {
        count--;
    }
}
  • 同步方法和非同步方法同时存在时,非同步方法可以被多个占有该对象的线程同时调用

  • synchronized获得的锁是可重入的,包括子类调用父类的同步方法

  • 异常会导致锁释放

  • 尽量使用细粒度的锁

volatile

  • java线程模型?JMM

16-2

  • volatile只保证了可见性,synchronized保证可见性和原子性,synchronized比volatile效率低

Atom*

  • 方法都是原子性的,简单的同步效率高

  • 但是多个方法不构成原子性

其他

  • 不要用字符串做锁定对象
  • 锁定对象o如果变成另一个对象,则锁定的对象发生改变,所以应该避免

wait和notify

  • sleep不释放锁
  • notify只是唤醒一个线程,但是不释放锁
  • wait释放锁

CountDownLatch门闩/syclicbarrier/semaphore

  • 不需要锁定对象,也就不需要synchronized
  • 线程中await等待门闩打开
  • 使用countDown减到0就启动并继续执行线程

ReentrantLock重入锁

  • 需要手动释放锁lock,unlock
  • 可以使用trylock来获取是否拿到锁,然后做判断处理,可以指定时间
  • 和synchronized不存在性能区别
  • lockInterruptibly可以对interrupt方法做出反馈
  • ReentrantLock可以指定为公平锁,谁等的时间长把锁给谁,synchronized就是竞争锁没有公平锁,公平锁效率比竞争锁低

生产者消费者

  • wait 99%的情况下和while一起使用,在被notify之后再判断一次,而if就不会做
  • 永远使用notifyAll不适用notify
  • Lock Condition,可以精确控制哪些线程被叫醒

ThreadLocal

  • 自己线程自己用,别的线程用不了,需要自己做,互相之间没影响
  • ThreadLocal是空间换时间,synchronized是时间换空间,ThreadLocal时间效率更高

线程安全的单例模式Singleton

  • 不加锁同时实现懒加载

并发容器Map/Set

  • ConcurrentHashMap要比Hashtable效率高,Hashtable是加锁,ConcurrentHashMap是把数据分了16份只锁其中一段,而1.8使用CAS,所以效率高,同样也比Collection.synchronized要高
  • ConcurrentSkipListMap用于高并发排序,跳表

并发容器队列

  • CopyOnWriteArrayList,写的时候非常费时间,读的时候不用加锁,适合写少读多,只能保证最终数据一致性
  • Collection.synchronized可以把list专成加锁的list
  • Queue高并发分类
  • ConcurrentLinkedQueue
  • BlockingQueue
  • LinkedBlockingQueue
  • ArrayBlockingQueue,BQ在put时如果满了就会等待,take如果空了就会等待
  • TransferQueue
  • SynchronousQueue
  • DelayQueue
  • ConcurrentQueue,offer方法类似于add,但是offer在有界的情况下不会报异常只会返回boolean,poll方法把第一个(index=0)拿出来并且删掉,peek方法则是把第一个拿出来但不删除
  • Deque为双端队列
  • DelayQueue中每个元素都有等待时间,可以用来定时执行任务
  • LinkedTransferQueue是生产者发现消费者在的话就不往队列里扔了直接发给生产者,transfer方法先执行会导致阻塞,实时消息处理使用的比较多
  • SynchronousQueue没有容量的队列,容量为0,消费者必须马上消费掉,所以不能用add函数,只能用put实际上调用的是transfer

相关工具类

  • Executor
  • ExecutorService的excute函数自动调用没有返回值的runnable,submit可以执行有返回值和没有返回值的callable和runnable,所有的java线程池都实现了该接口
  • callable有返回值和runnable没有,其他差不多
  • Executors是工具类,有一些工厂方法
  • FutureTask,通过get方法阻塞获取结束的值,是把Callable做了个包装好放进线程中启动

线程池

  • FixedThreadPool固定个数线程池
  • CachedThreadPool缓存线程池,里面的线程有生存周期,默认60s
  • SingleThreadExecutor只有一个线程
  • ScheduledThreadPool以固定频率来执行任务
  • WorkStealingPool每个线程都维护自己的一个任务,执行完自己的之后会从别人的那里偷任务执行,是daemon线程,精灵线程,主线程结束还会存在但看不到输出,封装了ForkJoinPool
  • ForkJoinPool分叉合并线程池,RecursiveAction没有返回值所以不能join使用runnable,RecursiveTask有返回值可以join,join本身是阻塞的,用于大规模数据计算
  • ThreadPoolExecutor所有的线程池底层都是他实现的,可以用它做自定义线程池
  • ParallelStreamAPI

参考资料

docker-compose使用volume部署mysql时permission deny问题解决

问题

整体情况为使用docker做mysql的容器,然后结合其他服务一起通过docker-compose启动,并且为了一次性建表和设置用户权限我又在mysql中封装了setup.sh、schema.sql、privileges.sql这些自定义的脚本,在Dockerfile构造时执行,到目前为止都是正常的。

但是由于每次down掉容器后,mysql的数据会丢失无法持久化,所以在docker-compose.yml中配置了volume参数,然后就产生了如下的报错,包括调试过程中的报错。

首先列几个可能的报错,这些都和这个有关系。

问题一:mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)

问题二:'su' command in Docker returns 'must be run from terminal'

问题三:/usr/bin/mysqld_safe: 637: /usr/bin/mysqld_safe: cannot create /var/lib/mysql/c0ce8fdc06d0.err: Permission denied

以上几个问题都是我在调试过程中出现的报错,采用过以下办法解决:

1、在docker-compos.yml中添加

user:"1000:50"

2、保证volume配置对应的是/var/lib/mysql目录,不能是/var/lib/mysql/data更深一层目录

3、在Dockerfile中添加权限指令chmod一类的,来修改文件权限

上述的方法均无效,在列出真正的解决方案之前,我把我重要的几个配置文件列出来

  • docker-compose.yml
plate-nginx:
build: ./nginx
container_name: plate-nginx
links:
- plate-client:plate-client
- plate-server:plate-server
ports:
- "80:80"
- "443:443"
- "7000:7000"
plate-client:
build: ./client
container_name: plate-client
volumes:
- "/home/picture:/app/client/app/upload"
ports:
- "3000:3000"
- "3001:3001"
plate-server:
build: ./server
container_name: plate-server
ports:
- "7001:7001"
plate-mysql:
build: ./mysql
container_name: plate-mysql
volumes:
- "/home/data:/var/lib/mysql"
ports:
- "3306:3306"
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: 123456
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- plate-mysql:plate-mysql
ports:
- "8888:80"
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: 123456
PMA_HOST: plate-mysql
PMA_PORT: 3306

  • mysql下的Dockerfile
FROM mysql:5.6

#设置免密登录
ENV MYSQL_ALLOW_EMPTY_PASSWORD yes

#将所需文件放到容器中
COPY setup.sh /mysql/setup.sh
COPY schema.sql /mysql/schema.sql
COPY privileges.sql /mysql/privileges.sql

#设置容器启动时执行的命令
CMD ["sh", "/mysql/setup.sh"]

  • setup.sh
#!/bin/bash
set -e

#查看mysql服务的状态,方便调试,这条语句可以删除
echo `service mysql status`

echo '1.启动mysql....'
#启动mysql
service mysql start
sleep 3
echo `service mysql status`

echo '2.开始导入数据....'
#导入数据
mysql < /mysql/schema.sql
echo '3.导入数据完毕....'

sleep 3
echo `service mysql status`

#重新设置mysql密码
echo '4.开始修改密码....'
mysql < /mysql/privileges.sql
echo '5.修改密码完毕....'

#sleep 3
echo `service mysql status`
echo `mysql容器启动完毕,且数据导入成功`

tail -f /dev/null

解决方案

真正的问题所在其实就是在服务器上的volume目录/home/data和容器里目录/var/lib/mysql拥有者不一样导致的,那么如何查看拥有者,需要使用如下几条指令

  • 查看容器中/var/lib/mysql的所有者
docker run -ti --rm --entrypoint="/bin/bash" plate_plate-mysql -c "ls -la /var/lib/mysql"

9-1

可以从图中看出来这个目录的所有者是mysql用户组

  • 查看服务器中/home/data的所有者
ls -la /home/data

9-2

在systemd-bus-proxy这个位置原来是root,这里由于被我修改了所以是这样,也就是说,这两个目录的所有者不同导致的权限问题,现在把他们的id统一就可以了,统一前要先查出来容器里的mysql用户组id,然后修改服务器的/home/data下的用户组id

  • 查出来容器里的mysql用户组id
docker run -ti --rm --entrypoint="/bin/bash" plate_plate-mysql -c "cat /etc/group"

9-3

可以看到mysql用户组的id为999

  • 修改服务器文件用户组id
chown -R 999 /home/data

9-2

修改后再去查看就如上图一样,权限变成了systemd-bus-proxy,至于为什么没变成mysql呢,因为999是docker容器里面的权限id,不是服务器的,所以服务器不识别也是自然的,之后再重启,执行

docker-compose build && docker-compose up -d

就不会再有报错了

前端与学习路径

test

在文字写书写不同数量的#可以完成不同的标题,如下:

一级标题

二级标题

三级标题

四级标题

五级标题
六级标题

等号及减号也可以进行标题的书写,等号代表一级标题,减号代表二级标题,并且需要写在文字的下面,减号及等号的数量不会影响标题的基数,如下:

一级标题

二级标题

无序列表的使用,在符号“-”后加空格使用。如下:

  • 无序列表1
  • 无序列表2
  • 无序列表3

如果要控制列表的层级,则需要在符号“-”前使用空格。如下:

  • 无序列表1
  • 无序列表2
    • 无序列表2.1
      • 列表内容
      • 列表内容

有序列表的使用,在数字及符号“.”后加空格几个,如下:

  1. 有序列表1
  2. 有序列表2
  3. 有序列表3

引用的格式是使用符号“>”后面书写文字,及可以使用引用。如下:

这个是引用

是不是和电子邮件中的

引用格式很像

粗体的使用是在需要加粗的文字前后各加两个“”,而斜体的使用则是在需要斜体的文字前后各加一个“”,如果要使用粗体和斜体,那么就是在需要操作的文字前后各加三个“*”。如下:
这个是粗体
这个是斜体
这个是粗体加斜体

在文中直接加链接,中括号中是需要添加链接的文字,圆括号中是需要添加的链接,如下:
link text

在引用中加链接,第一个中括号添加需要添加的文字,第二个中括号中是引用链接的id,之后在引用中,使用id加链接:如下:
[link text][id]
[id]: http://example.com/ "optional title here"

在文中直接引用链接,直接使用尖括号,把链接加入到尖括号中就可以实现,如下:
http://example.com/ or [email protected]
插入互联网上图片,格式如下:
这里写图片描述
![这里写图片描述][jane-eyre-douban]

用TAB键起始的段落,会被认为是代码块,如下:

echo “hello world";

如果在一个行内需要引用代码,只要用反引号`引起来就好,如下:

Use the printf() function.

可以在一行中用三个以上的星号、减号、底线来建立一个分隔线,同时需要在分隔线的上面空一行。如下:




删除线的使用,在需要删除的文字前后各使用两个符合“~”,如下
Mistaken text.

在需要高亮的代码块的前一行及后一行使用三个反引号“`”,同时第一行反引号后面表面代码块所使用的语言,如下:

#FileName: HelloWorld.java  
public class HelloWorld   #如果有 public 类的话,类名必须和文件同名,注意大小写  
{  
  #Java 入口程序,程序从此入口  
  public static void main(String[] args)  
  {  
  #向控制台打印条语句  
    System.out.println("Hello,World!");  
  }  
} 
var sys = require("sys");    #导入需要的 sys 模块  
sys.puts("Hello,World!");    #调用里面的 puts 函数来打印字符串   
#include <stdio.h>  
int main()                #main 入口函数  
{  
  printf("Hello,World!"); #printf 函数打印  
  return 1;               #函数返回值  
}  

可以使用冒号来定义表格的对齐方式,如下:

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

复杂链表的复制

题目描述

输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)

/*
struct RandomListNode {
    int label;
    struct RandomListNode *next, *random;
    RandomListNode(int x) :
            label(x), next(NULL), random(NULL) {
    }
};
*/
class Solution {
public:
    RandomListNode* Clone(RandomListNode* pHead)
    {
        if(!pHead){
            return NULL;
        }
        RandomListNode* pNew = pHead;
        while(pNew){
            RandomListNode* tmp = new RandomListNode(pNew->label);
            tmp->next = pNew->next;
            pNew->next = tmp;
            pNew = pNew->next->next;
        }
        pNew = pHead;
        while(pNew){
            if(pNew->random){
                pNew->next->random = pNew->random->next;
            }
            pNew = pNew->next->next;
        }
        RandomListNode* pResult = pHead->next;
        pNew = pHead->next;
        while(pNew){
            pHead->next = pNew->next;
            if(pNew->next){
                pNew->next = pNew->next->next;
            }
            pHead = pHead->next;
            pNew = pNew->next;
        }
        return pResult;
    }
};

二叉树的镜像

题目描述

题目描述
操作给定的二叉树,将其变换为源二叉树的镜像。
输入描述:

二叉树的镜像定义:源二叉树 
    	    8
    	   /  \
    	  6   10
    	 / \  / \
    	5  7 9 11
    	镜像二叉树
    	    8
    	   /  \
    	  10   6
    	 / \  / \
    	11 9 7  5
/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
    void Mirror(TreeNode *pRoot) {
        if(pRoot){
            TreeNode *tmp = pRoot->left;
            pRoot->left = pRoot->right;
            pRoot->right = tmp;
            Mirror(pRoot->left);
            Mirror(pRoot->right);
        }
    }
};

秋招Java研发岗复习策略

秋招投的基本都是Java研发岗,分享一下自己的复习策略

timg

初级策略:看面经和刷题

如果是面试java开发的话,推荐JavaGuide这个仓库,里面覆盖的还比较全面

高级策略:看书和读源码

其实最开始我是拒绝看书的,因为觉得太慢,而且可能记不住,所以我使用了初级策略,但是在面试过程中有几件事情让我发现了秋招仅仅依靠面经是无法拿到大厂offer的

问题如下:

  1. 面试中让我实现HashMap的put函数伪代码,实现ThreadPoolExecutor的offer和take函数伪代码
  2. 大小端是什么样的,如何写代码判断,网络字节序c++和java会存在大小端转换问题么?
  3. 你对jvm看起来很了解,那双亲委派模型知道么?
  4. Spring的启动过程是怎么样的,用到了哪些类?
  5. 遇到大量wait_time状态怎么处理?

分析下上面几个问题,可以得到下面几个结论

  1. 我面的都是java和后台研发的岗位,但是不可避免的会碰到c++的面试官问c++相关的面试问题,尤其是网络编程上
  2. java面试如果仅仅看面经的话,遇到源码和更深入一层的问题基本顾及不到,而恰恰现在大厂的面试官都会去深入一步询问

所以只看面经很容易被识别出来,然后被面试官吊打,我只举了面试过程中遇到的5个较深入的问题,还有更多的问题我没列出来,而且可以认为有几个问题没答出来,就少了几个offer,今年的面试已经很难有问题不会可以给offer的空间了

基于上述结论我推荐几本我看过的书,都是豆瓣评分很高很经典的书籍,分别用于补充不同的部分,所有的书籍均可下载,下载链接,该推荐基于已经学过Java有一定编程能力的同志

Java研发书籍:

推荐阅读顺序:

Java高并发程序设计 -> JDK -> 深入理解Java虚拟机 -> MySQL必知必会 -> Redis开发与运维 -> TCP/IP编程 -> 图解HTTP -> Head First 设计模式 -> Java 8实战 -> 大型网站技术架构 -> 高性能MySQL -> 其他

书籍详情:

  • JDK的collection,map,concurrent包必看
  • Java高并发程序设计:必看,面试中高并发几乎是必问的点,如果没有系统的看过高并发程序如何写,类库如何用很容易被问晕
  • 深入理解Java虚拟机:必看,经典中的经典,所有jvm和jmm相关的问题和知识都在这里有答案
  • MySQL必知必会:必看,内容为sql语句的基本使用,建议配合牛客网的数据库实战编程来复习
  • Redis开发与运维:必看,主要内容为Redis的使用和特点,讲解了Redis都有哪些可用的内容
  • TCP/IP编程:必看,书中虽然都是C++,但基本覆盖了网络编程能遇到的问题,包括IO使用,网络字节序等
  • 图解HTTP:必看,书很短一天就能看完,能很快的掌握http协议中的字段和含义,面试中也经常被问到
  • Head First 设计模式:选看,讲java设计模式的,其中单例模式的四种实现被问得最多
  • Java 8实战:选看,非常有价值的书籍,Java 8的新特性使得Java函数式编程成为了可能
  • 大型网站技术架构:必看,面试中常常会遇到秒杀系统设计一类的问题,这时候需要有对分布式系统演化的理解
  • 高性能MySQL:选看,内容为mysql的实现原理和性能优化,在面试中经常会被问到,读这本书会有更深刻的理解
  • 其他:还有很多进阶的书籍,比如Spring揭秘、Netty权威指南、Redis设计与实现等,这些都可以后续再看

建议:学一个工具的时候,需要准备两本书,第一本书是讲如何使用的,第二本书是讲内部原理的,建议先将第一本书看个大概,再去开始做项目,一边做一边巩固,同时开始学习实现原理。

斐波那契数列

题目描述

大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。
n<=39

class Solution {
public:
    int Fibonacci(int n) {
        vector<int> res;
        res.push_back(0);
        res.push_back(1);
        for(int i=2;i<=n;i++){
            res.push_back(res[i-2]+res[i-1]);
        }
        return res[n];
    }
};

Java虚拟机调优

Java内存结构

  • 一个线程对应一个栈,一个方法对应一个栈帧
  • 持久代perm也叫做方法区,永久区
  • 永久区存放class文件,静态变量,字符串常量,方法和执行引擎都去永久区找

15-3

堆内存

  • new出来的对象如果很大直接放到老年代中,否则放到新生代
  • 发生gc新生代没有被回收的会被放到survivor区
  • 再次发生gc,新生代没有被回收的和survivor没有被回收的,放到了另一个survivor区
  • 往复循环
  • 两个survivor会被叫为from,to或者s0,s1

15-5

  • 比例设置

15-9

GC如何确定垃圾

  • 强引用,软引用,虚引用,弱引用
  • main方法里的对象可以作为roots,class加载器也是

15-6

垃圾收集算法

  • Mark-Sweep标记清除,实际上不是擦除,而是做了标记,有内存碎片问题,导致需要fullGC来整理,耗费时间
  • Copying复制,效率高,但是浪费内存空间,survivor区就是这个算法,因为新生代一般剩下的不多
  • Mark-Compact标记压缩,老年代用这个算法,因为每次更改的都不多

15-7

15-8

15-10

jvm采用分代算法

  • new
  • 存活对象少
  • 使用copying,占用内存空间也不大,效率也高
  • old
  • 垃圾少
  • 一般使用mark-compact

JVM参数

  • -标准参数,所有jvm都应该支持
  • -X非标,每个jvm实现都不同
  • -XX不稳定参数,下一个版本可能会取消

垃圾收集器

  • Serial Collector
  • Parallel Collector 并发量大,每次垃圾收集停顿时间长
  • CMS Collector 停顿时间短
  • G1 Collector 中合并发量大和停顿时间短

java对象的分配

  • 占用1%是为了减少加锁,要不然多线程要加锁影响速度
  • 逃逸指的是对象在线程外部也有引用,线程结束后无法回收

15-11

常用参数设置

  • 堆设置

  • -Xms:初始堆大小

  • -Xmx:最大堆大小

  • -Xss:线程栈大小

  • -XX:NewSize=n:年轻代大小

  • -XX:NewRatio=n:设置年轻代和年老代的比值。如3:代表年轻:年老为1:3,年轻代占整个年轻代年老代的1/4

  • -XX:SurvivorRatio=n:年轻代中Eden区与两个Survivor区的比值,注意Survivor区有两个。如:3,表示Eden:Survivor=3:2,一个Survivor区占整个年轻代的1/5,比2因为有两个

  • -XX:MaxPermSize=n:设置持久代大小

  • 收集器设置

  • -XX:+UseSerialGC:设置串行收集器

  • -XX:+UseParallelGC:设置并行收集器

  • -XX:+UseConcMarkSweepGC:设置并发收集器

  • 垃圾回收统计信息

  • -XX:+PrintGC

  • -XX:+PrintGCDetails

  • -Xloggc:filename

  • -Xss的理解

  • 该参数指的是栈中每个线程的空间大小,即线程栈的大小

  • 如果分配的小,那么可启动的线程多,并发性好

  • 如果分配的大,那么递归调用就可以很深,但是可启动的线程变少,并发性差

典型tomcat优化配置

  • set JAVA_OPTS=

  • -Xms4g

  • -Xmx4g

  • -Xss512k

  • -XX:+AggressiveOpts //凡是能优化的都开启

  • -XX:+UseBiasedLocking

  • -XX:PermSize=64M //jdk1.8取消了

  • -XX:MaxPermSize=300M //class越来越多,最大给300M

  • -XX:+DisableExplicitGC //System.gc()不起作用,因为有人调用会打乱调优

  • 如果服务器上只有一个java虚拟机程序,可以让他尽量占内存

  • 如果业务中new出来的东西特别多,Eden区要调大一点

  • 业务中有很多对象在不停的运行,老年代的多,就把老年代的调多,调调比例

15-1

JMeter和Load Runner等性能测试工具

  • 修改catalina.bat做调优

15-2

参考资料

JVM 数据存储介绍及性能优化

马士兵Java虚拟机调优

大小端判断和转换

BOOL IsBigEndian()  
{  
    int a = 0x1234;  
    char b =  *(char *)&a;  //通过将int强制类型转换成char单字节,通过判断起始存储位置。即等于 取b等于a的低地址部分  
    if( b == 0x12)  
    {  
        return TRUE;  
    }  
    return FALSE;  
}

#define BigtoLittle32(A)   ((( (uint32)(A) & 0xff000000) >> 24) | \  
                                       (( (uint32)(A) & 0x00ff0000) >> 8)   | \  
                                       (( (uint32)(A) & 0x0000ff00) << 8)   | \  
                                       (( (uint32)(A) & 0x000000ff) << 24))  

从上往下打印二叉树

题目描述

从上往下打印出二叉树的每个节点,同层节点从左至右打印。

/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
    vector<int> PrintFromTopToBottom(TreeNode* root) {
        queue<TreeNode*> q;
        q.push(root);
        vector<int> result;
        if(!root){
            return result;
        }
        while(!q.empty()){
            root = q.front();
            q.pop();
            result.push_back(root->val);
            if(root->left){
                q.push(root->left);
            }
            if(root->right){
                q.push(root->right);
            }
        }
        return result;
    }
};

xampp install pthreads for php

1. Check the runtime enviroment

  • php version
D:\xampp\php>php -v
PHP 5.6.34 (cli) (built: Jul 18 2013 10:56:37)

The php of xampp is 32-bit by default.

  • windows version

1-version

It determines the location of "pthreadVC2.dll".

2. Download the file

File url : http://windows.php.net/downloads/pecl/releases/pthreads/

Download php_pthreads-2.0.9-5.6-ts-vc11-x86.zip according to the above version.

3. Install

  • Copy "pthreadVC2.dll" to "D:\xampp\php"
  • Copy "php_pthreads.dll" to "D:\xampp\php\ext"
  • Add "extension=php_pthread.dll" to "php.ini"
  • Add "LoadFile D:/xampp/php/pthreadVC2.dll" to "httpd.conf"
  • Restart Apache

4. Test

Official test code:

<?php
class AsyncOperation extends Thread {
public function __construct($arg){
$this->arg = $arg;
}

public function run(){
if($this->arg){
printf("Hello %s\n", $this->arg);
}
}
}
$thread = new AsyncOperation("World");
if($thread->start())
$thread->join();
?>

If it has error, you can use the following command to check it out.

D:\xampp\php>php -m

You can make sure if the pthreads module have been loaded.

work on fedora

sudo fdisk -l
sudo umount /dev/sdb*
sudo mkfs.vfat /dev/sdb -I

sudo dd if=~/images/ubuntu.iso of=/dev/sdb

yum install pv
sudo dd if=./centos7.iso bs=4M | pv | dd of=/dev/sdb bs=4M

这里要注意之后要安装google官网的rpm包,否则会有登陆不上去的bug

配置oh-my-zsh,使用af-magic主题

chsh -s /bin/zsh
  • 引导项修复
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
  • rime横向
ibus-setup

修改成横向即可,这时候可能会遇到报错,通过以下指令来解决

dnf install zypper
zypper in python2-gobject-Gdk
  • 远程连接

要使用aaron用户,不能使用root用户

rdesktop 10.10.162.42:3389
  • 截图

可以自定义快捷键

4screen

https://blog.csdn.net/gatieme/article/details/52800015

strcpy/strlen/strcat/strcmp/memset/memcpy的实现

#include <assert.h>
#include <stdio.h>

// 字符串拷贝strcpy
char* strcpy(char* des, const char* src){
    assert((NULL!=des)&&(NULL!=src));
    char * res = des;
    while((*des++=*src++)!='\0');
    return res;
}

// 字符串长度strlen
int strlen(const char* src){
    assert((NULL!=src));
    int res=0;
    while((*src++)!='\0'){
        ++res;
    }
    return res;
}

// 字符串链接strcat
char* strcat(char* des, const char* src){
    assert((NULL!=des) && (NULL!=src));
    char* res = des;
    while(*des!='\0')
        ++des;
    while(*des++=*src++);
    return res;
}

// 字符串比较strcmp
int strcmp(const char* s1, const char* s2){
    assert((NULL!=des) && (NULL!=src));
    while(*s1 == *s2){
        if(*s1 == '\0')
            return 0;
        ++s1;
        ++s2;
    }
    return *s1-*s2;
}

//将指针一个范围变为一个数
void* memset(void* src, int c, unsigned int n){
    assert(NULL!=src);
    void* res = src;
    while(n--){
        *(char*)src = c;
        (char*)src ++;
    }
    return res;
}

//将指针一个范围拷贝另一个指针的数
void* memcpy(void* dest,void* src, unsigned int n){
    assert(NULL != dest && NULL != src);
    void* res=dest;
    while(n--){
        *(char*)dest = *(char*)src;
        (char*)dest++;
        (char*)src++;
    }
    return res;
}

有关于while((*des++=*src++)!='\0');的理解,等同于

while(
des' = des,
src' = src,
*des' = *src',
*des' != '\0'
){
  des = des' + 1;
  src = src' + 1;
}

二叉搜索树的后序遍历序列

题目描述

输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。

//左子树一定比右子树小,因此去掉根后,数字分为left,right两部分,right部分的
//最后一个数字是右子树的根他也比左子树所有值大,因此我们可以每次只看有子树是否符合条件
//即可,即使到达了左子树左子树也可以看出由左右子树组成的树还想右子树那样处理
 
//对于左子树回到了原问题,对于右子树,左子树的所有值都比右子树的根小可以暂时把他看出右子树的左子树
//只需看看右子树的右子树是否符合要求即可
class Solution {
public:
    bool VerifySquenceOfBST(vector<int> sequence) {
        int size = sequence.size();
        if(size==0){
            return false;
        }
        int i = 0;
        while(--size){
            while(sequence[i] < sequence[size]){
                i++;
            }
            while(sequence[i] > sequence[size]){
                i++;
            }
            if(i<size){
                return false;
            }
            i = 0;
        }
        return true;
    }
};

环境与部署

重建二叉树

题目描述

输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。

/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    TreeNode* reConstructBinaryTree(vector<int> pre,vector<int> vin) {
        if(pre.size()==0)
            return NULL;
        else if(pre.size()==1)
            return new TreeNode(pre[0]);
        TreeNode * root = new TreeNode(pre[0]);
        int pos = std::find(vin.begin(), vin.end(), pre[0]) - vin.begin();
        vector<int> l_pre = vector<int>(pre.begin()+1, pre.begin()+pos+1);
        vector<int> r_pre = vector<int>(pre.begin()+pos+1,pre.end());
        vector<int> l_vin = vector<int>(vin.begin(), vin.begin()+pos);
        vector<int> r_vin = vector<int>(vin.begin()+pos+1,vin.end());
        root->left = reConstructBinaryTree(l_pre, l_vin);
        root->right = reConstructBinaryTree(r_pre, r_vin);
        return root;
    }
};

golang和java中的shuffle

golang和java中的shuffle

有篇文章中讲了golang中shuffle的使用
代码如下:

a := []int{1, 2, 3, 4, 5, 6, 7, 8}
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(a), func(i, j int) { a[i], a[j] = a[j], a[i] })

结果

[5 8 6 4 3 7 2 1]

golang-1.10中shuffle的实现

// Shuffle pseudo-randomizes the order of elements.
// n is the number of elements. Shuffle panics if n < 0.
// swap swaps the elements with indexes i and j.
func (r *Rand) Shuffle(n int, swap func(i, j int)) {
	if n < 0 {
		panic("invalid argument to Shuffle")
	}

	// Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
	// Shuffle really ought not be called with n that doesn't fit in 32 bits.
	// Not only will it take a very long time, but with 2³¹! possible permutations,
	// there's no way that any PRNG can have a big enough internal state to
	// generate even a minuscule percentage of the possible permutations.
	// Nevertheless, the right API signature accepts an int n, so handle it as best we can.
	i := n - 1
	for ; i > 1<<31-1-1; i-- {
		j := int(r.Int63n(int64(i + 1)))
		swap(i, j)
	}
	for ; i > 0; i-- {
		j := int(r.int31n(int32(i + 1)))
		swap(i, j)
	}
}

golang的实现和java有很大区别,下面看下java的实现

public static void shuffle(List<?> list) {
    Random rnd = r;
    if (rnd == null) {
        r = rnd = new Random();
    }

    shuffle(list, rnd);
}

public static void shuffle(List<?> list, Random rnd) {
    int size = list.size();
    if (size >= 5 && !(list instanceof RandomAccess)) {
        Object[] arr = list.toArray();

        for(int i = size; i > 1; --i) {
            swap(arr, i - 1, rnd.nextInt(i));
        }

        ListIterator it = list.listIterator();

        for(int i = 0; i < arr.length; ++i) {
            it.next();
            it.set(arr[i]);
        }
    } else {
        for(int i = size; i > 1; --i) {
            swap(list, i - 1, rnd.nextInt(i));
        }
    }

}

首先获取集合的元素个数,如果小于5个或者实现了RandomAccess接口,就循环一遍,随机交换集合中两个相邻的元素的位置,RandomAccess是一个标记接口,如果实现了这个接口就表示支持快速的随机访问操作,类似于数组。

如果大于等于5个元素也没有实现RandomAccess接口,那么就转为数组,之后也是循环,随机交换集合中两个相邻的元素的位置,最后再将数组放回原来的list中。

之所以做这样的区别是和速度有关系,其中涉及到了RandomAccess这个类,有篇文章讲了这个类的用处

ArrayList实现了RandomAccess,而LinkedList没实现这个接口,所以ArrayList是做直接的下标遍历,而LinkedList是先转成Array结构,再用下标遍历

vue-element-admin使用琐记

做项目主要用了前端框架vue.js,其中使用了开源后台系统vue-element-admin,用别人的开源工具果然有很大成长,知道很多东西,做一篇笔记,记录下零零碎碎学到的东西

vue-i18n

该项目实现国际化的原理是在cookie中存储一个键值对,来判断语言,进而做相关转换

1

常见的$t

  • 想使用complexTable,经常能看到$t的出现,查了下github才懂,原来这个是vue-i18n要用的,它对应的位置是@/view/lang下的各种语言包文件,比如标题那行对应了此处,也就是相当于这行决定了显示的值

公共组件化complexTable

该组件用来做复杂表格显示使用,带着分页整体比较合心意

vue中的slot和slot-scope

有一篇文章《深入理解vue中的slot和slot-scope》讲的已经很全面了,但在最后一个demo那里描述的不够清楚,主要是传输数据那里,自己探索之后补充一下。

简单改了下代码如下:

  • 父组件
<template>
  <div class="father">
    <h3>这里是父组件</h3>
    <!--第一次使用:用flex展示数据-->
    <child>
      <template slot-scope="user">
        <div class="tmpl">
          <span v-for="item in user.data2">{{item}}</span>
        </div>
      </template>

    </child>

    <!--第二次使用:用列表展示数据-->
    <child>
      <template slot-scope="user">
        <ul>
          <li v-for="item in user.data2">{{item}}</li>
        </ul>
      </template>

    </child>

    <!--第三次使用:直接显示数据-->
    <child>
      <template slot-scope="user">
       {{user.data2}}
      </template>

    </child>

    <!--第四次使用:不使用其提供的数据, 作用域插槽退变成匿名插槽-->
    <child>
      我就是模板
    </child>
  </div>
</template>
  • 子组件
<template>
  <div class="child">

    <h3>这里是子组件</h3>
    // 作用域插槽
    <slot  :data2="data"></slot>
  </div>
</template>

 export default {
    data: function(){
      return {
        data: ['zhangsan','lisi','wanwu','zhaoliu','tianqi','xiaoba']
      }
    }
}

其实只是改了一个变量名,可以看到user就是一个父组件的区域,在父组件范围使用,和子组件没有关系。而data2是和子组件的slot标签动态绑定相关联的,绑定的数据data就只和子组件自己有关联,原来都叫做data混在了一块看不清楚,区分一下就清晰了

父组件给子组件传值

组件相关可以看官网文档,这里我主要理解的是props这个属性是子组件的,不是父组件的

跨域问题

  • CORS

CORS基本没什么问题,在服务端配置好之后,然后配置config文件夹下dev.env.js,配置如下

module.exports = {
  NODE_ENV: '"development"',
  ENV_CONFIG: '"dev"',
  BASE_API: '"http://10.10.154.2:8088/CNDRGs"'
}
  • 代理

由于项目中要考虑兼容ie8和ie9的问题,所以可以考虑使用代理来做,配置如下

config/index.js

module.exports = {
  dev: {

    ...

    proxyTable: {
      "/CNDRGs": {
        target:"http://10.10.154.2:8088",
        changeOrigin:true,
        pathRewrite: {
          '^/CNDRGs': '/CNDRGs/'
        }
      }
    }

    ...
  }
}

其中第一个/CNDRGs^/CNDRGs是对应关系,要保持一致,/CNDRGs/是服务器端在基础host上附加的路径,这里在做重定向

另外一个就是api文件修改,以src/api/deathTopTen.js为例

import request from '@/utils/request'

export function fetchList(query) {
  return request({
    url: '/CNDRGs/drgdead',
    method: 'get',
    params: query,
    baseURL: ''
  })
}

注意要添加baseURL: ''这一行,否则会直接从10.10.154.2请求,就达不到代理的目的了,代理的目的是从自身处请求,再有自身的服务去发请求

url中的/CNDRGs也是和proxyTable中的/CNDRGs^/CNDRGs是对应关系

HTTP状态码

概括

状态码 类别 原因短语
1XX Informational(信息性状态码) 接收的请求正在处理
2XX Success(成功状态码) 请求正常处理完毕
3XX Redirection(重定向状态码) 需要进行附加操作以完成请求
4XX Client Error(客户端错误状态码) 服务器无法处理请求
5XX Server Error(服务器错误状态码) 服务器处理请求出错

2XX

  • 200 OK
  • 204 No Content
  • 206 Partial Content 返回一部分数据,Content-Range字段

3XX

  • 301 Moved Permanently 永久性重定向
  • 302 Found 临时性重定向
  • 303 See Other 和302一致,但是希望采用GET方式
  • 304 Not Modified 该状态码表示客户端发送附带条件的请求 2 时,服务器端允许请求访问资源,但未满足条件的情况
  • 307 Temporary Redirect 和302一致

4XX

  • 400 Bad Request 请求报文存在语法错误
  • 401 Unauthorized 需要认证或者认证失败
  • 403 Forbidden 拒绝资源访问
  • 404 Not Found 找不到请求的资源

5XX

  • 500 Internal Server Error 服务器执行错误
  • 503 Service Unavailable 服务器超负载或者停机维护,无法处理请求

源代码阅读笔记

以JDBC为例,本质就是将mysql或者postgresql注册到java.sql.DriverManagerjava.util.ServiceLoader中,注册过程中在java.sql.DriverManagerloadInitialDrivers函数里调用了Class.forName(),之后每次判断是哪个驱动的时候就去遍历,源代码如下

    private static void loadInitialDrivers() {
        String drivers;
        try {
            drivers = AccessController.doPrivileged(new PrivilegedAction<String>() {
                public String run() {
                    return System.getProperty("jdbc.drivers");
                }
            });
        } catch (Exception ex) {
            drivers = null;
        }

        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            public Void run() {

                ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class);
                Iterator<Driver> driversIterator = loadedDrivers.iterator();
                try{
                    while(driversIterator.hasNext()) {
                        driversIterator.next();
                    }
                } catch(Throwable t) {
                // Do nothing
                }
                return null;
            }
        });

        println("DriverManager.initialize: jdbc.drivers = " + drivers);

        if (drivers == null || drivers.equals("")) {
            return;
        }
        String[] driversList = drivers.split(":");
        println("number of Drivers:" + driversList.length);
        for (String aDriver : driversList) {
            try {
                println("DriverManager.Initialize: loading " + aDriver);
                Class.forName(aDriver, true,
                        ClassLoader.getSystemClassLoader());
            } catch (Exception ex) {
                println("DriverManager.Initialize: load failed: " + ex);
            }
        }
    }

找不到SimpleFormController类似的Controller类了,原因是都被注解替换掉了

数值的整数次方

题目描述

给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。

class Solution {
public:
    double Power(double base, int exponent) {
        long long p = abs((long long)exponent);
        double res = 1.0;
        while(p){
            if(p & 0x1){
                res *= base;
            }
            base *= base;
            p >>= 1;
        }
        return exponent < 0 ? 1/ res : res;
    }
};

树的子结构

题目描述

输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)

/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
    bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2)
    {
        bool result = false;
        if(pRoot1 != NULL && pRoot2!=NULL){
            if(pRoot1->val == pRoot2->val){
                result = isChild(pRoot1, pRoot2);
            }
            if(!result){
                result = isChild(pRoot1->left, pRoot2);
            }
            if(!result){
                result = isChild(pRoot1->right, pRoot2);
            }
        }
        return result;
    }
    
    bool isChild(TreeNode* pRoot1, TreeNode* pRoot2){
        if(pRoot2 == NULL){
            return true;
        }
        if(pRoot1 == NULL){
            return false;
        }
        if(pRoot1->val != pRoot2->val){
            return false;
        }
        return isChild(pRoot1->left, pRoot2->left) && isChild(pRoot1->right, pRoot2->right);

    }
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.