MongoDB

  • 查看版本 mongod --version
  • 从 4.4 版本开始 db 和 tool 分离了

历史

4.4
4.2 2019
4.0 2018
3.6 2017

YUM方式安装

安装

1
2
3
4
5
6
7
8
9
10
vi /etc/yum.repos.d/mongodb-org-4.4.repo

[mongodb-org]
name=MongoDB Repository
baseurl=https://mirrors.aliyun.com/mongodb/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

yum install -y mongodb-org

启动

1
2
3
service mongod start
service mongod stop
service mongod restart

To prevent unintended upgrades

1
2
vi /etc/yum.conf
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

auto boot
chkconfig mongod on

Tarball方式安装

1
2
3
4
5
6
7
8
9
10
sudo yum install libcurl openssl

cd ~/download
wget mongodb-linux-x86_64-rhel70-4.4.0.tgz
tar xzvf mongodb-linux-x86_64-rhel70-4.4.0.tgz
cp mongodb-linux-x86_64-rhel70-4.4.0/bin/* /usr/local/bin/

wget mongodb-database-tools-rhel70-x86_64-100.1.1.tgz
tar xzvf mongodb-database-tools-rhel70-x86_64-100.1.1.tgz
cp mongodb-database-tools-rhel70-x86_64-100.1.1/bin/* /usr/local/bin/

启动

1
2
3
4
5
6
7
mkdir -p /var/lib/mongo
mkdir -p /var/log/mongodb
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork

mongod -f /etc/mongod.conf &

mongod --shutdown -f /etc/mongod.conf

使用

登录

1
mongo --host ip

监控

1
2
mongostat
mongotop

数据库

1
2
3
4
5
show dbs
use dbname
db.dropDatabase()

db.serverStatus().connections

文档

1
2
3
4
show collections
db.createCollection(name, options)
db.collection.drop()
db.collection.renameCollection("record")

查询文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
db.collection.find( {} ).limit(5)
db.collection.find( { status: "D" } )
db.collection.find( { status: { $in: [ "A", "D" ] } } )
db.collection.find( { status: "A", qty: { $lt: 30 } } )
db.collection.find( { $or: [ { status: "A" }, { qty: { $lt: 30 } } ] } )
db.collection.find( {
status: "A",
$or: [ { qty: { $lt: 30 } }, { item: /^p/ } ]
} )

status: "D"
status: { $in: [ "A", "D" ] } }
qty: { $lt: 30 }
$or: [ { qty: { $lt: 30 } }, { item: /^p/ } ]
exec_time: {$lt: ISODate('2020-07-23T01:00:00.000Z')}

插入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
db.test.insert({
date1: new Date(),
date2: new Date("2020-01-01"),
date2: new Date("2020-01-01T12:00:01.123"),
date2: new Date("2020-01-01T12:00:01.123Z")
})

db.collection.insertOne(
{ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } }
)
db.collection.insertMany([
{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "A" },
{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
{ item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
{ item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }
]);

更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
db.collection.updateOne()
db.collection.updateMany(
{ age: { $lt: 18 } },
{ $set: { status: 'reject' } }
)

db.scoreSearchLog_20200723.updateMany(
{
'resultCode': '500',
'exec_time': {$lt: ISODate('2020-07-23T01:00:00.000Z')}
},
{ $set: { 'resultCode': '300' } }
)

db.collection.replaceOne(
{ "name": "Central Perk Cafe" },
{ "name": "Central Pork Cafe", "Borough" : "Manhattan" }
)

删除

1
2
3
4
db.collection.deleteOne()
db.collection.deleteMany(
{ status: 'reject' }
)

排序

1
db.collection.sort({'exec_time': -1}).count()

索引

1
2
db.collection.createIndex({'exec_time': -1})
db.collection.getIndexes()

参考

Install MongoDB Community on Red Hat or CentOS using .tgz Tarball
Install MongoDB Community Edition on Red Hat Enterprise or CentOS Linux

Node.js

Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

History

版本 发布时间 维护截至

  • 18.x 2022/04/19 2025/04/30
  • 16.x 2021/4/20 2024/4/30
  • 14.x 2020/4/21 2023/4/30
  • 12.x 2019/4/23 2022/4/30
  • 10.x 2018/4/24 2021/4/30

参考

使用NPM

  • 查看版本 npm -v
  • 查看配置 npm config list
  • 修改镜像 npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
  • Cache files are stored in ~/.npm on Posix, or %AppData%/npm-cache on Windows.

演示:创建Web服务

1
2
3
4
5
6
7
8
9
10
// 创建服务
var http = require('http');

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8888);

// 启动服务
node server.js

使用PM2管理

  • 安装 npm install pm2 -g
  • 启动 pm2 start | stop | restart | delete
  • 监控 pm2 monit
  • 进程列表 pm2 list
  • 使用PM2启动Express.js: pm2 start bin/www

Dart Language

Dart is a client-optimized language for fast apps on any platform.

DartPad is an open source tool that lets you play with the Dart language in any modern browser.

History

Version Date
1.0 2013-11
2.0 2018-08

Documentation

Features

  • Type inference
  • Null safety
  • Type safety
  • async and await
  • isolate-based concurrency
  • single inheritance
  • no interface, all classes implicitly define an interface
  • new keyword is optional
  • null coalescing operator ??
  • Cascade notation .. ?.., Assignment operators ??=
  • String interpolation
  • spread operator
  • collection if

  • Everything you can place in a variable is an object, and every object is an instance of a class. Even numbers, functions, and null are objects.
  • Although Dart is strongly typed, type annotations are optional because Dart can infer types.
  • If you enable null safety, variables can’t contain null unless you say they can.You can make a variable nullable by putting a question mark (?) at the end of its type.
  • If you know that an expression never evaluates to null but Dart disagrees, you can add ! to assert that it isn’t null.
  • Dart supports generic types, like List<int> or List<Object>.
  • You can also create functions within functions (nested or local functions).
  • doesn’t have the keywords public, protected, and private. If an identifier starts with an underscore (_), it’s private to its library.
  • Dart has both expressions (which have runtime values) and statements (which don’t).
  • Dart tools can report two kinds of problems: warnings and errors.

The libraries

  • Built-in types, collections, and other core functionality for every Dart program (dart:core)
  • Richer collection types such as queues, linked lists, hashmaps, and binary trees (dart:collection)
  • Encoders and decoders for converting between different data representations, including JSON and UTF-8 (dart:convert)
  • Mathematical constants and functions, and random number generation (dart:math)
  • File, socket, HTTP, and other I/O support for non-web applications (dart:io)
  • Support for asynchronous programming, with classes such as Future and Stream (dart:async)
  • Lists that efficiently handle fixed-sized data (for example, unsigned 8-byte integers) and SIMD numeric types (dart:typed_data)
  • Foreign function interfaces for interoperability with other code that presents a C-style interface (dart:ffi)
  • Concurrent programming using isolates — independent workers that are similar to threads but don’t share memory, communicating only through messages (dart:isolate)
  • HTML elements and other resources for web-based applications that need to interact with the browser and the Document Object Model (DOM) (dart:html)

Syntax

Built-in types

Variables

1
2
3
var name = 'Bob';
Object name = 'Bob';
String name = 'Bob';
  • Variables store references.
  • the style guide recommendation of using var, rather than type annotations, for local variables.

Define a function

1
2
3
4
5
6
7
8
void printElement(int element) {
print(element);
}

var list = [1, 2, 3];

// Pass printElement as a parameter.
list.forEach(printElement);
  • Named parameters are optional unless they’re specifically marked as required.
  • Wrapping a set of function parameters in [] marks them as optional positional parameters.
  • Your function can use = to define default values for both named and positional parameters. The default values must be compile-time constants.
  • Every app must have a top-level main() function, which serves as the entrypoint to the app.
  • All functions return a value. If no return value is specified, the statement return null.
  • You can pass a function as a parameter to another function.

Anonymous functions

1
2
3
4
5
6
const list = ['apples', 'bananas', 'oranges'];
list.forEach((item) {
print('${list.indexOf(item)}: $item');
});

list.forEach((item) => print('${list.indexOf(item)}: $item'));
  • You can also create a nameless function called an anonymous function, or sometimes a lambda or closure.

Control flow statements

If the object that you are iterating over is an Iterable (such as List or Set) and if you don’t need to know the current iteration counter, you can use the for-in form of iteration:

1
2
3
for (var candidate in candidates) {
candidate.interview();
}

Exceptions

In contrast to Java, all of Dart’s exceptions are unchecked exceptions. Methods don’t declare which exceptions they might throw, and you aren’t required to catch any exceptions.

1
2
3
throw FormatException('Expected at least 1 section');

throw 'Out of llamas!';

Classes

Command-line and server apps

Write command-line apps

Create a small app

Use the dart create command and the console-full template to create a command-line app:

1
dart create -t console-full cli

Run the app

1
2
cd cli
dart run

Compile for production

Use the dart compile tool to AOT compile the program to machine code:

1
dart compile exe bin/cli.dart

Functions

The => expr syntax is a shorthand for { return expr; }. The => notation is sometimes referred to as arrow syntax.

OOP

Factory constructors

Asynchronous programming: futures, async, await

  • To define an async function, add async before the function body.
  • The await keyword works only in async functions.

Future class

1
2
3
Future<int> future = getFuture();
future.then((value) => handleValue(value))
.catchError((error) => handleError(error));

FutureBuilder class

中国杀人案

轿车撞人案

2022年03月20日,河北邯郸轿车撞人案

2021年5月22日,大连轿车撞人案

2019年7月17日,常州奔驰撞人案

2019年7月3日,玛莎拉蒂追尾宝马案

谭明明醉酒驾驶(血液酒精含量167.66mg/100ml)的玛莎拉蒂莱万特越野车,与王某驾驶的正在等待绿灯的宝马740发生追尾,宝马车被撞出数十米远并起火燃烧,造成车内2人当场烧死、1人受伤;肇事车内3人受伤。

据当地媒体报道,谭明明父母做皮革生意,家境富裕。

2018年7月30日,杭州SUV奔驰撞人案

2018年7月30日19时许,陈某某(女)穿拖鞋驾驶浙A牌照的小型越野客车撞倒多名行人,造成5人死亡,4人轻伤,3人轻微伤。

2015年6月20日,南京宝马撞人案

2009年5月7日,杭州富家子改装跑车撞人案

欺实马:语源自七十码,中国网民恶搞出一个生物“欺实马”,以此讽刺杭州警方对此案中肇事车辆的车速认定。

交车司机自杀

2018年10月28日,重庆公交车坠江

2020年7月7日,贵州公交坠湖

2021年10月11日,河北大巴坠河

婚姻悲剧

2022年04月9日,安徽夫妻相隔5小时先后坠楼身亡

2021年03月15日,安徽女子离婚冷静期携儿女跳楼

枪击案

弑师案

杀村官案

冤案

故意杀人案

2020年

2019年

2018年

2017年

2016年

2015年

2014年

2013年

2012年

2010年

2009年

2008年

2006年

2005年

2004年

2001年

1996年

1992年

1988年

1983年

参考

中国有哪些恐怖或鲜为人知的杀人案件?
中国最凶残的杀人案是哪一件?