unclay
unclay / blog Goto Github PK
View Code? Open in Web Editor NEW博客
Home Page: https://www.unclay.com/
博客
Home Page: https://www.unclay.com/
最近公司服务器因为某些原因,导致服务器环境需要全部重新部署,安装nodejs又忘了,记录下,方便下次使用。
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list
sudo npm install n -g
sudo n stable
sudo node -v
// error code
W: There is no public key available for the following key IDs:
8B48AD6246925553
W: Failed to fetch http://mirrors.aliyuncs.com/ubuntu/dists/precise/Release.gpg Could not connect to mirrors.aliyuncs.com:80 (10.143.34.200), connection timed out
// A:resolve: add key
gpg --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553
gpg -a --export 8B48AD6246925553 | sudo apt-key add -
// error code
W: Failed to fetch http://mirrors.163.com/ubuntu/dists/precise/Release.gpg Could not connect to mirrors.163.com:80 (123.58.173.106). - connect (111: Connection refused)
W: Failed to fetch http://mirrors.163.com/ubuntu/dists/precise-security/Release.gpg Unable to connect to mirrors.163.com:http:
W: Failed to fetch http://mirrors.163.com/ubuntu/dists/precise-updates/Release.gpg Unable to connect to mirrors.163.com:http:
W: Failed to fetch http://mirrors.163.com/ubuntu/dists/precise-proposed/Release.gpg Unable to connect to mirrors.163.com:http:
W: Failed to fetch http://mirrors.163.com/ubuntu/dists/precise-backports/Release.gpg Unable to connect to mirrors.163.com:http:
W: Some index files failed to download. They have been ignored, or old ones used instead.
// A: 部分网络问题,下载失败,尝试换成官方源,虽然比较慢,但是能下载
// resolve:修改apt文件 /etc/apt/sources.list(注意备份)
# Ubuntu官方
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
make[1]: *** [/home/software/node-v7.8.0/out/Release/obj.target/v8_libplatform/deps/v8/src/libplatform/default-platform.o] Error 1
make[1]: Leaving directory `/home/software/node-v7.8.0/out'
make: *** [node] Error 2
// A: gcc版本太低,需要把gcc升级到4.8以上
修改/etc/apt/sources.list为以下软件源(改前请备份)
163和里面在部分网络下会一直下载失败,可以改回官方源下载
http://wiki.ubuntu.org.cn/模板:14.04source
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ precise-backports main restricted universe multiverse
一不小心就看到位图法,引起了我的兴趣。
简单说下位图法(bitmap),用每一个bit来存放某个状态,常用于正整数类型中。(具体内容请自行百度)
先来个抛砖引玉吧,曾经有一个题目,据说是腾讯的前端面试题,内容大概如下:
有一组数字,从1到n,假设n=10,乱序且不重复。例如[1,5,8,3,4,9,2,6,7,10],随机删除3个数字,请找出3个被删除的数字。
// 随机删除后的数组
var arr = [1, 3, 4, 9, 2, 7, 10];
// 位图数组,多了索引0,所以设置11个
var bitmap = Array(11);
// 输出数组
var outputArr = [];
// 设置位图状态
for (var i = 0; i < arr.length; i++) {
bitmap[arr[i]] = 1;
}
// 提取已移除的数字
for (var i = 1; i < bitmap.length; i++) {
if (!bitmap[i]) {
outputArr.push(i);
}
}
// 输出[5, 6, 8]
console.log(outputArr);
初始化的位图数组如下:
[undefind * 11]
设置状态位后的位图数组(undefind当0)如下:
[0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1 ]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
不难看出,缺失的5,6,8,位图法就是通过这种原理来设置的
另外,位图法还支持排序
,从上得知数字也被重新排好序了
已知两个数组[8,4,6,2,1,9]、[3,4,5,8,9,7,0],请合并去除重复数字,并找出重复过的数字。
var arr1 = [8, 4, 6, 2, 1, 9];
var arr2 = [3, 4, 5, 8, 9, 7, 0];
var bitmap = Array(10);
// 重复的数字
var repeatArr = [];
// 合并后的数组
var concatArr = [];
// 设置位图状态
for (var i = 0; i < arr1.length; i++) {
bitmap[arr1[i]] = 1;
}
// 找到重复数字
for (var i = 1; i < arr2.length; i++) {
if (bitmap[arr2[i]]) {
repeatArr.push(arr2[i]);
}
// 同时设置位图状态
bitmap[arr2[i]] = 1;
}
// 合并后的数组
for (var i = 0; i < bitmap.length; i++) {
if (bitmap[i]) {
concatArr.push(i);
}
}
// 输出[4, 8, 9]
console.log(repeatArr);
// 输出[0, 1, 2, 4, 5, 6, 7, 8, 9]
console.log(concatArr);
位图法能不能计算数以亿计的量级,答案是“能”
一个bit状态位表示一条数据,
我们来简单计算一下:
1B = 8bit
1KB = 1024B
1MB = 1024KB
≈ 1024 * 1024 * 8 bit
≈ 840万 bit
也就是说,800多万的数据才占用了1MB内存而已,剩下的就是cpu的计算了
/*
* @Description: test
* @Author: Clay
* @Date: 2019-04-01
* @LastEditors: Clay
* @LastEditTime: 2019-04-01 17:56
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node, CommonJS之类的
module.exports = factory(require('jquery'));
} else {
// 浏览器全局变量(root 即 window)
root.returnExports = factory(root.jQuery);
}
}(this, function ($) {
// 方法
function myFunc(){};
// 暴露公共方法
return myFunc;
}));
最近公司服务器因为某些原因,导致服务器环境需要全部重新部署,安装nodejs又忘了,记录下,方便下次使用。
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm
sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list
sudo npm install n -g
sudo n stable
sudo node -v
// error code
W: The repository 'http://ppa.launchpad.net/chris-lea/node.js/ubuntu xenial Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch http://ppa.launchpad.net/chris-lea/node.js/ubuntu/dists/xenial/main/binary-amd64/Packages 404 Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
// A: 修改node相关文件:/etc/apt/sources.list.d/chris-lea-ubuntu-node_js-xenial.list
deb http://ppa.launchpad.net/chris-lea/node.js/ubuntu trusty main
deb-src http://ppa.launchpad.net/chris-lea/node.js/ubuntu trusty main
node -v
-bash: /usr/local/bin/node: Permission denied
sudo node -v
Segmentation fault (core dumped)
// A: 重新安装nodejs
手动移除 /usr/local/lib/node_modules整个目录
手动移除 /usr/local/bin/node
手动移除 /usr/local/bin/n
手动移除 /usr/local/bin/npm
修改/etc/apt/sources.list为以下软件源(改前请备份)
163和里面在部分网络下会一直下载失败,可以改回官方源下载
http://wiki.ubuntu.org.cn/模板:16.04source
deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse
解决方法: 使用mongoose.Types.ObjectId,而不是用mongoose.Schema.Types.ObjectId
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.