VICTORCHENEY

INNERPEACE

修改hosts文件大法

改HOSTS大法

Windows下在C:/Windows/system32/drivers/etc/hosts
Ubuntu等linux系一般在/etc/hosts

在hosts中添加如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 # Github
151.101.44.249 github.global.ssl.fastly.net
192.30.253.113 github.com
103.245.222.133 assets-cdn.github.com
23.235.47.133 assets-cdn.github.com
203.208.39.104 assets-cdn.github.com
204.232.175.78 documentcloud.github.com
204.232.175.94 gist.github.com
107.21.116.220 help.github.com
207.97.227.252 nodeload.github.com
199.27.76.130 raw.github.com
107.22.3.110 status.github.com
204.232.175.78 training.github.com
207.97.227.243 www.github.com
185.31.16.184 github.global.ssl.fastly.net
185.31.18.133 avatars0.githubusercontent.com
185.31.19.133 avatars1.githubusercontent.com

改完之后立刻刷新

1
2
Windows:ipconfig /flushdns
Ubuntu:sudo systemctl restart nscd

工具推荐

修改hosts文件神器 SwitchHosts! https://github.com/oldj/SwitchHosts/releases

docker命令

进入容器

sudo docker exec -it <containername> // sudo 为Linux系统管理员权限命令

1.停止所有的container,这样才能够删除其中的images:

docker stop $(docker ps -a -q)

如果想要删除所有container的话再加一个指令:

docker rm $(docker ps -a -q)

2.查看当前有些什么images

docker images

Node--文件路径

nodejs中的几种文件路径比较

在调试一个node代码的时候,总是出问题,最后找到原因是由于路径的问题,node中的路径有全局变量__dirname、全局变量__filename./../以及process.cwd()
首先看个例子:

在桌面的nodedemo文件夹新建了simple.js文件,对以上几种路径进行输出

1、__dirname: 表示当前模块所在的文件夹的绝对路径。

2、__filename: 表示当前模块的绝对路径

3、process.cwd()表示的是node进程当前工作的绝对路径

4、./在打印的时候要借助path.resolve()进行转换,与process.cwd()效果相同

5、../表示当前工作目录的上级目录

AngularJS验证用户名的自定义指令

Angularjs表单验证中,验证用户名是否唯一

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
angular.module('demo.form')
.directive('ensureUnique', ['$http', ($http) => {
return {
require: 'ngModel',
link: (scope, ele, attrs, c) => {
scope.$watch(attrs.ngModel, () => {
$https({
method: 'POST',
url: '/api/check/' + attrs.ensureUnique,
data: {'field': attrs.ensureUnique}
}).success((data, status, headers, cfg) => {
c.$setValidity('unique', data.isUnique)
}).error((data, status, headers, cfg) => {
c.$setValidity('unique', false);
})
})
}
}
}]);


JavaScript--GeolocationAPI定位

HTML5 Geolocation API

在HTML5中新增了Geolocation API方便用户定位,获取地理位置信息。通过设备获取地理位置可以通过以下方式:

1、IP地址
2、三维坐标(GPS全球定位系统、从RFID、Wi-Fi到Wi-Fi的MAC地址、GSM或CDMA手机的ID)
3、用户自定义数据