1.
在配置Mongoose+nodejs服务器时,遇到这个问题
DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
新版本的mongoose需要自定义Promise方式,在
var Mongoose = require("mongoose");
后面添加
Mongoose.Promise = require("bluebird");
2.
在配置Mongoose+nodejs服务器时,遇到这个问题
Unhandled rejection MongoError: Unknown modifier: $pushAll
版本冲突,在新建schema的时候加上{usePushEach: true}配置就可以了:
var Mongoose = require("mongoose");
var schemaObject = new Mongoose.Schema("TableName", {userPushEach: true});
3.
今天使用curl的时候提示错误,网上搜索出来的全是windows下怎样操作的,
要在php.ini中去掉extension=php_curl.dll前面的分号,但是在linux中的php.ini中没
有这一行,而且有也不会是dll。。。
后来谷歌出来了解决方案:
安装php5-curl:
sudo apt-get install php5-curl
然后直接重启apache服务即可:
service apache2 restart
4.在VMWare配置Debian时,有时需要局域网的其他电脑能连上服务器,并且其自身还能连上外网。一下是解决方案:
首先确保Debian虚拟机安装好后使用默认NAT方式能够上网(其实不能上网是你乱动了网络配置,但不能上网也没关系
我们使用的只是DHCP配置)。
1.确保主机上,网络配置中,本地连接(或者有的是无线网络连接)属性中有“VMWare Bridge Protocol”,这应该是VMWare
完整版本都应该会安装的插件;
2.打开VMWare->编辑->虚拟网络编辑器,正常会看到VMnet0、VMnet1、VMnet8三个,默认为VMnet0为桥接,VMnet8
为NAT。现在VMnet8配置是正确的,不用去动他。点击VMnet0,在“连接到”中,选择刚刚确认过的本地连接
(或无线网络连接)的网卡。
3.打开虚拟机->设置->网络适配器,选择“桥接模式”,“复制物理网络连接状态”可不选。
4.使用cmd的ipconfig,或者本地连接(或无线网络连接 )详细信息中,找到IP: 10.0.1.206和网关: 10.0.1.240,
使用nslookup xxxx或者在详细信息中找到DNS: 119.6.6.6或者114.114.114.114,记住备用。
5.主机端配置完成,进入Debian,按照网上的教程,一般就开始配置interfaces了,一般都是使用静态IP。
但是先不急,我们不知道哪个静态IP可以使用(我之前配置了很久,也确认过配置的IP没有占用,但就是不能上外网,
这里需要先注意一下),我们使用DHCP来自动帮我们选择。进入Debian后,打开/etc/netowkring
编辑interfaces(这里我的eth0被默认改成了ens33,所以如果不是ens33就需要改回eth0)
#这两行是原来有的,dhcp不需要改
allow-hotplug ens33
iface ens33 inet dbcp
#这里设置bridge属性
bridge_ports ens33
bridge_stp off # disable Spanning Tree Protocol
bridge_waitport 0 # no delay before a port becomes available
bridge_fd 0 # no forwarding delay
然后就可以直接service networking restart重启网络。
此时,用ifconfig可以看到IP地址(10.0.1.204),并且ping也可以连接外网了(本来可以连接外网,之后改成bridge以后,都是DHCP应该也能
连接外网的,如果不能,那只能说----是VMWare的BUG ^_^)
6.由于使用DHCP,作为服务器的话IP不宜变化太大,因此需要将IP改为静态的。同样打开interfaces:
#将原来的dhcp改为静态,之前改的bridge不用管它
allow-hotplug ens33
auto ens33
iface ens33 inet static
address 10.0.1.204
broadcast 10.0.1.255
netmask 255.255.255.0
gateway 10.0.1.240
dns-nameservers 119.6.6.6 114.114.114.114
之后更改/etc/resolv.conf将dns同样写在里面(如果用network-manager可能会自动更改,但是如果没有,需要手动更改,
如果不改,后面连不上外网那我也不知道会出现什么问题)
nameserver 119.6.6.6
nameserver 114.114.114.114
好了,使用service networking restart重启网络,使用ifconfig和ping检查一下,就能看到网络正常了。
10.0.1.xxx这个网段就是局域网的网段了,可以被其他网络机器发现,作为服务器;也可以连接外网啦。
(可能路由器上有某些设置导致局域网段成了10.0.1.xxx,但很多家庭场合的路由器
一般都是192.168.1.xxx的,完全替换没问题)
7. Debian 6换源安装php7.0
#vim /etc/apt/sources.list添加:
-
deb http://packages.dotdeb.org jessie all
-
deb-src http://packages.dotdeb.org jessie all
#添加GnuPG的Key
-
wget https://www.dotdeb.org/dotdeb.gpg
-
apt-key add dotdeb.gpg
#apt-cache search php
#apt-get install php7.0
8.windows实现cd-
md_autoruns.cmd:
@echo off
cd %1
pushd %1
title aliases active
cls
%SystemRoot%\\System32\\doskey.exe /macrofile=c:\\tools\\aliases
mycd.bat:
@echo off
if '%*'=='' cd & exit /b
if '%*'=='-' (
cd /d %OLDPWD%
set OLDPWD="%cd%"
) else (
cd /d %*
if not errorlevel 1 set OLDPWD="%cd%"
)
cd=C:\\tools\\mycd.bat $*
cd\\=c:\\tools\\mycd.bat ..
A:=c:\\tools\\mycd.bat A:
B:=c:\\tools\\mycd.bat B:
C:=c:\\tools\\mycd.bat C:
...
Z:=c:\\tools\\mycd.bat Z:
.=cd
..=c:\\tools\\mycd.bat ..
...=c:\\tools\\mycd.bat ..\\..
....=c:\\tools\\mycd.bat ..\\..\\..
.....=c:\\tools\\mycd.bat ..\\..\\..\\..
......=c:\\tools\\mycd.bat ..\\..\\..\\..\\..
.......=c:\\tools\\mycd.bat ..\\..\\..\\..\\..\\..
........=c:\\tools\\mycd.bat ..\\..\\..\\..\\..\\..\\..
.........=c:\\tools\\mycd.bat ..\\..\\..\\..\\..\\..\\..\\..
tools=c:\\tools\\mycd.bat C:\\tools
wk=c:\\tools\\mycd.bat %WORKSPACE%
9.tail
#!/bin/bash
PATTERN="$1"
# Try to make sure sub-shells exit when we do.
trap "kill -9 -- -$BASHPID" SIGINT SIGTERM EXIT
PID=0
OLD_FILES=""
while true; do
FILES="$(echo $PATTERN)"
if test "$FILES" != "$OLD_FILES"; then
if test "$PID" != "0"; then
kill $PID
PID=0
fi
if test "$FILES" != "$PATTERN" || test -f "$PATTERN"; then
tail --pid=$$ -n 0 -F $PATTERN &
PID=$!
fi
fi
OLD_FILES="$FILES"
sleep 1
done
10.获取private成员变量
#include <iostream>
class A {
public:
A() = default;
private:
int data_ = 0;
};
template < int A::*Member >
class Access {
public:
friend int GetPrivateData(A& obj) {
return obj.*Member;
}
};
template class Access<&A::data_>;
int GetPrivateData(A& );
int main() {
A obj;
GetPrivateData(obj);
return 0;
}
11.异步加载
const modules = import.meta.glob('../*/*.vue')
const route = "./" + comp_name;
const loader = modules[route]
return markRaw(defineAsyncComponent({
loader,
loadingComponent: false,
delay: 200,
}))
12.动态资源
// 获取assets静态资源
export const getAssetsFile = (url: string) => {
return new URL(`../assets/images/${url}`, import.meta.url).href;
};
// 图片引用
<img :src="getAssetsFile('图片名.png')">
// 动态绑定背景图
<div :style="{'background-image': 'url(' + getAssetsFile(`${bgSrc}.png`) + ')'}"></div>
13.静态服务
// require这些东西都是调用node环境中的包,只要有node环境,这些require的模块都是默认被安装进去了,就可以直接这样写
// node支持ES6的写法,下面的就是ES6的写法,不需要额外使用插件来把ES6转ES5,很方便
let http = require('http')
let url = require('url')
let util = require('util')
let fs = require('fs')
// http库是node提供的api,可以直接上node的中文网,直接看到各种api
let server = http.createServer((req, res) => {
// 通过你在浏览器输入的网站,利用url.parse进行解析成一个对象,再读取其中pathname的属性
// 例如你输入http://localhost:8080/index.html,然后url.parse(req.url).pathname返回的值为 "/index.html"
var pathname = url.parse(req.url).pathname
console.log('file:' + pathname.substring(1))
// fs,文件系统,读取文件
fs.readFile(pathname.substring(1), (err, data) => {
if (err) {
// 错误就返回404状态码
res.writeHead(404, {
'Content-Type': 'text/html'
})
} else {
// 成功读取文件
res.writeHead(200, {
'Content-Type': 'text/html'
})
// 展示文件数据
res.write(data.toString())
}
// 注意,这个end 一定要放在读取文件的内部使用
res.end(util.inspect(url.parse(req.url)))
})
})
server.listen(3000, '127.0.0.1', () => {
console.log('服务器已经运行,请打开浏览器,输入:http://127.0.0.1:3000/来访问')
})
....持续更新中