why nosql

NoSql可以处理结构化,非结构化的数据,可以水平伸缩,在实时和批量数据分析中具有优势

difference

why docker

  1. 解决“在我的机子上可以正常工作”的问题
  2. 运维更好地管理服务
  3. 更好地迁移和拓展(任意平台运行)

what is docker

docker属于Linux容器的一种封装,和VM类似,但他不像VM一样虚拟在操作系统之上,而是和操作系统平级,程序运行在容器里,就和在真实的物理机上面运行一样

img

简单一点理解就是:程序运行在docker上和真机上几乎误差,将程序包装起来管理

名词解释

  • daemon:守护进程
  • Client:命令行
  • image:镜像,用来创建容器
  • container:运行组件,启动的image就是容器
  • registry:管理image的地方

install

#ubuntu

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

HelloWorld

1
2
3
sudo docker container run hello-world
//他会先找本地,然后再去仓库下载
//该过程将image变成容器,即image文件产生container文件

常用命令

docker pull image_name//拉取镜像

docker images//本地镜像

docker rmi xxx//remove image

docker ps//view what docker is running

docker ps -a

//以下使用cn代替 container_name/container_id

docker start|stop|restart cn

docker attach cn//启动后进入容器

dokcer rm cn

docker info

docker search nginx

16.0正式发布

我们从去年八月开始,努力将我们LineageOs的新特性移植到新版本的安卓上,非常感谢之前版本中的工作者们,我们才能够在这次的版本新特性中投入更多的精力,尤其是,隐私守护(Privacy Guard)和插件(su addon)上收到了了大量的提升建议。
通过对Styles API的一些细微更改,他现在可以兼容安卓暗黑模式的默认实现,在未来,越来越多的三方应用将遵循系统风格,这意味着Styles API将允许在跨应用程序时获得更一致的体验。
正如我们发布夏季第二次调研结果那样,我们将介绍Trust的新特性,首先是设备锁定时阻止新USB设备连接。请注意,由于基于底层,所以这个特性必须在每个设备底层中启用。Trebuchet现在还可以隐藏app以及在打开app前进行身份验证。该限制也仅在Trebuchet中,并非系统范围。
我们认为16.0的分支已经达到了15.1版本的特性测试并做好了发布准备。随着16.0分支成为最新最活跃的分支,在2019.3.1,它将开始日更新构建,并且15.1将会移动到周更新。
16.0版本将会从小部分机器开始运行,一些其他的机子如果准备好了,我们也会做一些小改动,开始构建,并通过改动构建脚本来更好地处理我们最新手机的,独特feature,以及由此产生的复杂问题

支持更新名单

  • Asus
  • BQ
  • Fairphone
  • Google
  • HTC
  • Huawei
  • LeEco
  • Lenovo
  • LG
  • Moto
  • Nextbit
  • Nubia
  • Nvdia
  • OnePlus(my oneplus 5T receive 16.0)
  • Oppo
  • Samsung
  • Sony
  • Wileyfox
  • Wingtech
  • Xiaomi
  • YU
  • ZTE
  • Zuk
  • more

其他热门的ROM

原文

Hello LineageOS 16.0

We’ve been working hard since August to port our unique features to this new version of Android. Thanks to the major cleanup and refactoring done in the previous version, we were able to focus more on features and reliability this time; in particular, both Privacy Guard and the su addon received a sizeable amount of improvements.

With some minor changes made to the Styles API, it is now compatible with what will eventually become the default implementation of dark mode in Android. In the future, more and more third party apps will follow the system style, meaning our Styles API will allow you to have a more coherent experience across apps.

As we announced when the Summer Survey 2 results were posted, we will be introducing new features to Trust, beginning with the ability to block new USB device connections when device is locked. Please note that this feature has to be enabled on a per-device basis due to the layer at which this was implemented. Trebuchet is also now able to hide apps and require authentication before opening them. Please note that this restriction is limited to Trebuchet and is not system-wide.

We feel that the 16.0 branch has reached feature parity with 15.1 and is ready for initial release. With 16.0 being the most recent and most actively-developed branch, on March 1st, 2019 it will begin receiving builds nightly and 15.1 will be moved to weekly builds.

LineageOS 16.0 will be launching with a small selection of devices. Additional devices will begin receiving builds as they are ready and after we make minor change to our build scripts to better handle the unique features, and resulting complications, of the most modern devices.

Upgrading to LineageOS 16.0

  1. (Optional) Make a backup of your important data

  2. Download the build either from

    download portal

    or built in Updater app

    • You can export the downloaded package from the Updater app to the sdcard by long-pressing it and then selecting “Export” in the popup menu
  3. Download proper addons packages (GApps, su…) for Android 9.0/Lineage OS 16.0

  4. Make sure your recovery and firmware are up to date

  5. Format your system partition

  6. Follow the “Installing LineageOS from recovery” section on your device’s installation page

Please note that if you’re currently on an official build, you DO NOT need to wipe your device.

If you are installing from an unofficial build, you MUST wipe data from recovery before installing.

写在最前面:该文章为笔记,来自纯洁的微笑

what is the loading of class

类加载即:

将编译class文件中的二进制数据读到内存中方法区,然后在堆区通过java.lang.Class实例化对象,对方法区的数据进行操作

img

该加载过程包含首次使用加载,以及预加载

加载class文件的方式

  • 本地
  • 网络
  • zip,jar文件中
  • 数据库
  • 动态编译

类的生命周期

img

problem

In LeetCode Store, there are some kinds of items to sell. Each item has a price.

However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.

You are given the each item’s price, a set of special offers, and the number we need to buy for each item. The job is to output the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers.

Each special offer is represented in the form of an array, the last number represents the price you need to pay for this special offer, other numbers represents how many specific items you could get if you buy this offer.

You could use any of special offers as many times as you want.

examples

Example 1:

1
2
3
4
5
6
7
Input: [2,5], [[3,0,5],[1,2,10]], [3,2]
Output: 14
Explanation:
There are two kinds of items, A and B. Their prices are $2 and $5 respectively.
In special offer 1, you can pay $5 for 3A and 0B
In special offer 2, you can pay $10 for 1A and 2B.
You need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.

Example 2:

1
2
3
4
5
6
7
Input: [2,3,4], [[1,1,0,4],[2,2,1,9]], [1,2,1]
Output: 11
Explanation:
The price of A is $2, and $3 for B, $4 for C.
You may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C.
You need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C.
You cannot add more items, though only $9 for 2A ,2B and 1C.

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ShoppingOffers {
public static void main(String[] args) {
/*以下贴出测试方式,因为对ArrayList不熟悉,如有更好的方式,欢迎指出*/
List<Integer> price = new ArrayList<Integer>();
List<List<Integer>> special = new ArrayList<List<Integer>>();
List<Integer> needs = new ArrayList<Integer>();
price.add(0, 2);price.add(1, 5);
Integer[][] arr = new Integer[][] {{3,0,5},{1,2,10}};
special.add((List<Integer>)Arrays.asList(arr[0]));
special.add((List<Integer>)Arrays.asList(arr[1]));
needs.add(0,3);needs.add(1,2);
ShoppingOffers so = new ShoppingOffers();
int res = so.shoppingOffers(price, special, needs);
System.out.println(res);
}
public int shoppingOffers(List < Integer > price, List < List < Integer >> special, List < Integer > needs) {
return shopping(price, special, needs);
}
public int shopping(List < Integer > price, List < List < Integer >> special, List < Integer > needs) {
int j = 0, res = dot(needs, price);
for (List < Integer > s: special) {
ArrayList < Integer > clone = new ArrayList < > (needs);
for (j = 0; j < needs.size(); j++) {
int diff = clone.get(j) - s.get(j);
if (diff < 0)
break;
clone.set(j, diff);
}
if (j == needs.size())
res = Math.min(res, s.get(j) + shopping(price, special, clone));
}
return res;
}
public int dot(List < Integer > needs, List < Integer > price) {
int sum = 0;
for (int i = 0; i < needs.size(); i++) {
sum += needs.get(i) * price.get(i);
}
return sum;
}
}

key

本题目采用动态规划的思路,我们带入测试样例1的

1
2
3
4
>Input: [2,5], [[3,0,5],[1,2,10]], [3,2]
>即A=$2,B=$5
>3A=5$,1A+2B=10$
>需购买3A+2B
尝试 price
1:单买 16
2单买302套餐,还差2个B,则先算出2B的res为10,先试305套餐,A买超了,则退出305套餐,此时还有1210套餐,A买多了,退出套餐,两个套餐试完了,得到了单买两个B,$10的套餐,总价就为15元, 15(覆盖16)
3单买1210套餐,还差2A,0B,费用目前10元,先单买2A,费用4元,总价14元,然后先尝试305套餐,发现超,然后再试1210套餐,发现B超了,得到目前最低费用为14元 14(覆盖15)

问题的关键就在于clone的精髓之处,用来记录还需要多少零件的个数,使用递归,进行操作。如果不符合,(如买超了)直接break后,重新计算clone,直到special方法都试完了,然后才返回,如果一直都是break的状态则会返回单买的价格。

perfect

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution {

private Integer res;

public int shoppingOffers(List<Integer> price, List<List<Integer>> special, List<Integer> needs) {
res=Integer.MAX_VALUE;
int[] parr=new int[price.size()];
int[] aarr=new int[needs.size()];
for(int i=0;i<parr.length; i++){
parr[i]=price.get(i);
aarr[i]=needs.get(i);
}
findMinimum(special, 0, aarr, parr, 0);
return res;
}

private void findMinimum(List<List<Integer>> special, int curOffer, int[] remain, int[] single, int total){
if(total>=res||curOffer==special.size()) return;
int buyNow=buySingle(remain, single, total);
if(buyNow<res) res=buyNow;
int[] newRemain=remainAfterUse(special.get(curOffer), remain);
if(newRemain!=null) findMinimum(special, curOffer, newRemain, single, total+special.get(curOffer).get(remain.length));
findMinimum(special, curOffer+1, remain, single, total);
}

private int[] remainAfterUse(List<Integer> special, int[] remain){
int[] res=new int[remain.length];
for(int i=0;i<remain.length;i++){
res[i]=remain[i]-special.get(i);
if(res[i]<0) return null;
}
return res;
}

private int buySingle(int[] remain, int[] single, int total){
for(int i=0; i<remain.length; i++){
total+=remain[i]*single[i];
}
return total;
}

}

http2

优势

  • 更有效的网络利用率
  • 引入 HTTP Header 压缩减小报文体积
  • 在同一个连接中支持多路并发
  • 支持 Server Push

多路复用(Multiplexing)

由于HTTP连接,起初有要求限制同一域名下的请求有数量限制,超过则被阻塞,而HTTP2可以发起多重请求,如同时请求样式文件和脚本文件

二进制分帧

img

HTTP/2 通过让所有数据流共用同一个连接,可以更有效地使用 TCP 连接,让高带宽也能真正的服务于 HTTP 的性能提升。

img

http2.0的格式定义更接近tcp层的方式,这张二机制的方式十分高效且精简。length定义了整个frame的开始到结束,type定义frame的类型(一共10种),flags用bit位定义一些重要的参数,stream id用作流控制,剩下的payload就是request的正文了。

server Push

http2.0能通过push的方式将客户端需要的内容预先推送过去

首部压缩(Header Compression)


BigInt


*fs.mkdir 和 fs.mkdirSync 支持递归参数


CLI Flag 自动补全


Windows 安装包优化


本文章思路来自https://zhuanlan.zhihu.com/p/56780733

定位

其实由于Egg本身的动态加载机制,所以JavaScript很难去做智能提醒(如变量定义检查),本次借鉴TS的动态生成d.ts,使用ts的Declaration Merging(声明合并)特性,读取JSDoc注释。

获取

  • 更新egg-bin模块
  • package.json 添加 “egg”: { “declarations”: true }

实操,升级个人GitHub项目chum,执行

npm i egg-bin

将其从4.9.0–>4.11.0并在package.json的尾部加上上述egg的kv,在根目录下生成tpyping文件夹,将app目录下的controller,model,以及根目录下的index,config目录都进行了ts文件生成

1550905277423

其实egg原生支持JavaScript,对于TS只是支持不推荐的态度,并没有使用TS去重构,本次智能提醒,应该是对JS一个劣势的补齐,解决方案也似乎借鉴了TS的方式,但又保留了人们书写JS的习惯

Problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

Note:

The solution set must not contain duplicate triplets.

Example:

Given array nums = [-1, 0, 1, 2, -1, -4],

A solution set is:
[
[-1, 0, 1],
[-1, -1, 2]
]

Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public class Solution {
public List<List<Integer>> threeSum(int[] nums) {
Arrays.sort(nums);
ArrayList<List<Integer>> res = new ArrayList<List<Integer>>();
for(int i = 0; i < nums.length - 2; i++){
// 跳过重复元素
if(i > 0 && nums[i] == nums[i-1]) continue;
// 计算2Sum
ArrayList<List<Integer>> curr = twoSum(nums, i, 0 - nums[i]);
res.addAll(curr);
}
return res;
}

private ArrayList<List<Integer>> twoSum(int[] nums, int i, int target){
int left = i + 1, right = nums.length - 1;
ArrayList<List<Integer>> res = new ArrayList<List<Integer>>();
while(left < right){
if(nums[left] + nums[right] == target){
ArrayList<Integer> curr = new ArrayList<Integer>();
curr.add(nums[i]);
curr.add(nums[left]);
curr.add(nums[right]);
res.add(curr);
do {
left++;
}while(left < nums.length && nums[left] == nums[left-1]);
do {
right--;
} while(right >= 0 && nums[right] == nums[right+1]);
} else if (nums[left] + nums[right] > target){
right--;
} else {
left++;
}
}
return res;
}
}

Key

tips:很久没有写Java了,花了点时间去整理了一些知识,所以上面的算法其实是ctrl+v的,现在整理一下list相关的知识:

1.List<List>为嵌套的list集合,声明方式

List<List****> list = new Array***()*

or

List<List> list = new ArrayList<>();//recomend

2.List是一个接口,而ArrayList是List接口的一个实现类

List list = new List();//是错误的用法

List list = new ArrayList();//list会丢失ArrayList的trimToSize()方法

ArrayList list=newArrayList()

3.然后明天再回来重新写这道题

缓存

why

  • 高性能

    例如:把查完的值缓存,下次直接访问

  • 高并发

    例如:把请求排队

difference(vs memcached)

特征 redis memchched
数据结构 更复杂的数据结构,更丰富的数据操作
集群 支持 不支持
性能 单核 多核

redis线程模型

redis 内部使用文件事件处理器 file event handler,这个文件事件处理器是单线程的,所以 redis 才叫做单线程的模型。它采用 IO 多路复用机制同时监听多个 socket,根据 socket 上的事件来选择对应的事件处理器进行处理。

假设一个 Redis 服务器正在运作, 那么这个服务器的监听套接字的 AE_READABLE 事件应该正处于监听状态之下, 而该事件所对应的处理器为连接应答处理器。

如果这时有一个 Redis 客户端向服务器发起连接, 那么监听套接字将产生 AE_READABLE 事件, 触发连接应答处理器执行: 处理器会对客户端的连接请求进行应答, 然后创建客户端套接字, 以及客户端状态, 并将客户端套接字的 AE_READABLE 事件与命令请求处理器进行关联, 使得客户端可以向主服务器发送命令请求。

之后, 假设客户端向主服务器发送一个命令请求, 那么客户端套接字将产生 AE_READABLE 事件, 引发命令请求处理器执行, 处理器读取客户端的命令内容, 然后传给相关程序去执行。

redis-single-thread-model

执行命令将产生相应的命令回复, 为了将这些命令回复传送回客户端, 服务器会将客户端套接字的 AE_WRITABLE 事件与命令回复处理器进行关联: 当客户端尝试读取命令回复的时候, 客户端套接字将产生 AE_WRITABLE 事件, 触发命令回复处理器执行, 当命令回复处理器将命令回复全部写入到套接字之后, 服务器就会解除客户端套接字的 AE_WRITABLE 事件与命令回复处理器之间的关联。

key

当具备多个索引的时候,如:KEY 联合索引 (a,b,c)为索引,除(b,c)条件索引不会触发该索引表外,(a,b),(a,c),(a,b,c)均会触发上述联合索引,具体可参见explain的key类型,理论应该显示联立索引

如:

EXPLAIN SELECT * FROM TABLENAME WHERE a=’2222’ AND b=‘222’

如果你设置多个单列索引,在explain下,key的值就为其单列的索引,如上述的a列

0%