Regexp

Regex

Tools

Regexper: Visulization tool for Regexp
Regex101: Write, test and debug Regexp

Syntax

Syntax Description
Special Characters
\n New line.
\f Form feed.
\r Return.
\s Space.
\t Tab.
\v Vertical tab.
[\b] Backspace. As \b refers to boundary(see below), [] is used to differentiate backspace and boundary.
Repeats
? Zero or one occurrence.
* Zero or more occurrences.
{x} X times.
{min, max} min to max times. If max not given, then it means at least min times.
Margins
\b Boundary. Matches a pseudo position between word character \w and non-word character \W. Often used to extract single word. Match /\bcat\b/ in The cat scattered his food will not match cat in scattered as cat in scattered is surrounded by word character s and t.
\B Non-boundary.
^ Start of string.
$ End of string.
Modifiers
/m Multiple line.
/i Ignore case.
/g Global.
Sub-expression
Sub-expression Expression within brackets ( and ) is a sub-expression.
Backreference Use \1, \2 in the back to reference the first, second expression in the front. Example: Use \b(\w+)\s\1 to match two continuous same words in Hello what what is the first thing, and I am am Tom..
Non-capturing group Use (?:) to avoid being captured. Example: Using (Chendongti)(?:an) to match Chendongtian will only return one group Chendongti, an is not captured.
Lookahead Use (?=)/(?!) to add a must-have/must-not-have suffix. Example: Using happ(?=ily) to match happ happily will only return happ in happily, and happ(?!ily) will only return happ in happy.
Lookbehind Use (?<=)/(?<!) to add must-have/must-not-have prefix. Example: Using (?<=ap)ple to match apple people will only return ple in apple, and (?<!ap)ple will only return ple in people.
Logical operators
NOT ^. [^abc].
OR |. (a|b).
锂电池

锂电池

参考

  1. 【电池】30分钟,让你成为半个锂电池专家
  2. 铁电池、三元锂、NCM都是啥?电动汽车电池,纯干货一文全知道!
  3. 常见圆柱电池型号

种类

LiFePO4: LFP, 磷酸铁锂, 用磷酸铁锂作为正极材料的锂离子电池。
Ternary Lithium: 正极材料使用镍钴锰酸锂(Li(NiCoMn)O2)三元正极材料的锂电池,三元复合正极材料前驱体产品,是以镍盐、钴盐、锰盐为原料。
Cylindrical: 圆柱电池。
Prismatic: 方型电池。
LTO: lithium-titanium-oxide/lithium-titanate, 钛酸锂电池,一种用作锂离子电池负极材料-钛酸锂,可与锰酸锂、三元材料或磷酸铁锂等正极材料组成2.4V或1.9V的锂离子二次电池。
Polymer lithium: 聚合物电池。
LFP_VS_TL

电芯正极材料

  锂电池正极材料,是锂离子电池构成材料的一部分,直接影响着锂离子电池的性能,占有较大比例(正负极材料的质量比为3: 1~4:1)。

  锂离子电池是以2种不同的能够可逆地插入及脱出锂离子的嵌锂化合物分别作为电池的正极和负极的二次电池体系。充电时,锂离子从正极材料的晶格中脱出,经过电解质后插入到负极材料的晶格中,使得负极富锂,正极贫锂;放电时锂离子从负极材料的晶格中脱出,经过电解质后插入到正极材料的晶格中,使得正极富锂,负极贫锂。这样正负极材料在插入及脱出锂离子时相对于金属锂的电位的差值,就是电池的工作电压。

种类:
LCO: LiCoO2, Lithium Cobalt Oxide. 钴酸锂。
LNO: 镍酸锂。
LMO: LiMn2O4, Lithium Manganese Oxide. 锰酸锂。
NCM: 镍锰钴。
NCA: 镍钴铝。
LFP: 磷酸铁锂。

圆柱电池型号

型号 描述
10440 10440电池是一种直径为10mm、高度为44mm的锂离子电池,与我们常称为7号电池的大小相同,这种电池容量一般很小,只有几百mAh,重要应用在迷你电子产品。例如手电筒、迷你音响、扩音器等。
14500 14500电池是一种直径为14mm、高度为50mm的锂离子电池,这也是我们一直称为5号电池的规格尺寸,这种电池一般是3.7V或者3.2V,标称容量比较小,比10440电池大一点,一般是1600mAh,放电性能优越,应用领域最重要是消费电子类,例如无线音响、电动玩具、数码相机等。
16340 16340电池是一种直径为16mm、高度为34mm的锂离子电池,这种电池由于尺高度矮一点,而且容量也不是很小,因此在强光手电筒、LED手电筒、头灯、激光灯、照明灯具等经常出现。
18650 18650电池是一种直径为18mm、高度为65mm的锂离子电池,它最大的特点是拥有非常高的能量密度,几乎达到170瓦时/千克,因此这种电池是性价比较好的电池,我们平时经常看见的多数是这种电池,因为它是比较成熟的锂离子电池,各方面系统质量稳定性较好,广泛适用于10千瓦时左右的电池容量场合,例如在、在手机、笔记本电脑等小型电器上。
21700 21700电池是一种直径为21mm、高度为70mm的锂离子电池,因为它的体积增大,空间利用率变大,电芯单体以及系统能量密度可得到提升,它的体积能量密度远高于18650型电池,广泛用于数码,电动汽车、平衡车、太阳能能锂离子电池路灯、LED灯、电动工具等。生产这种电池厂家重要有Tesla、三星、松下、比克、猛狮新能源等。
26650 26650电池是一种直径为26mm、高度为65mm的锂离子电池,标称电压3.2V、标称容量3200mAh,这种电池用拥有优秀的容量及高一致性等特点,已逐步成为代替18650电池趋势,在动力锂电池方面很多产品也将逐步青睐于此。

常见证书和证明

参考:

  1. 危包证是什么
  2. 各国认证

各国认证

国家 名称 内容
中国 CQC CQC自愿性认证(标准:GB 31241-2015),锂电池作为零部件配合终端产品申请CCC强制认证需要;目前电商及网络平台均需提供盖有CNAS及CMA章的GB 31241报告。
中国 UN38.3 UN38.3报告及空海运鉴定书,航空/航海运输走货需要。
中国 BSMI BSMI认证 (标准:CNS 15364),锂电池进入台湾强制性准入要求
欧盟 CB CB认证(标准:IEC 62133:2012 2nd Edition),适用所有CB成员国,覆盖四大洲绝大多数成员国。
欧盟 EN 62133 EN 62133:2013 Report,锂电池进入欧盟成员国市场必须提供的安全性评估报告。
欧盟 CE-EMC CE-EMC 认证 (标准:EN 61000-6-1/EN 61000-6-3),用途:锂电池进入欧盟成员国市场必须提供的电磁兼容评估报告。
欧盟 ROHS & Reach Directive ROHS(六项)及Reach Directive(108项),锂电池进入欧盟成员国市场必须提供的化学成分评估报告。
欧盟 GOST GOST认证,用途:锂电池进入俄罗斯强制性准入要求。
北美 UL UL认证(标准:UL 1642/UL 2054/UL 60950),非强制性的安全性认证,一般是买家要求,美国UL机构发证。
北美 TUV-US TUV-US 认证(标准:UL 1642/UL 2054/UL 60950),用途:非强制性的安全性认证,一般是买家要求,北美莱茵机构发证。
北美 FCC FCC 认证 (标准:FCC Part 15B),美国强制性的EMC电磁兼容认证。
北美 CTIA CTIA认证 (标准:IEEE 1725/1625),北美电信运营商的强制性准入要求;IEEE 1725针对手机的可充式电池标准;IEEE 1625针对PC的可充式电池标准;
韩国 KC 标准:KC 62133(2015-07) ,韩国强制性准入要求。
亚洲 PSE 电池属于非特定电器,属于自愿性认证,须申请圆形PSE认证。
印度 BIS (IS 16046:2015),印度强制性准入要求。
澳洲 RCM 澳洲强制性准入要求,须提供CISPR 22报告和IEC 62133报告 注册RCM。

危包证

“危包证”是一种俗称,准确的讲危包证分为两个,一个是性能证,全称是《出入境货物包装性能检验结果单》,另一个是使用证,全称是《出境危险货物运输包装使用鉴定结果单》。危包证是要有了包装性能单才能去商检局做了商检之后再换包装使用单,这个使用单就是危包证。但由于相关部门监管愈发严格,很多企业可能部分资质不齐,导致办不出危包证。

包装性能单

危包证样本

《中华人民共和国进出口商品检验法》及其实施条例规定,出口危险货物包装容器生产企业应当向产地海关申请危险货物包装容器性能检验,出口危险货物的生产企业应当向产地海关申请危险货物包装容器使用鉴定。港监申报时就需要用到危包证,出口商在出口危险品时如果没有危包证,在港监申报就放行不了,柜子上不了船。

办理危包证的话,需根据你产品实际性质包装情况要各包装生产厂家提供《中华人民共和国出入境检验检疫局出境货物运输包装性能检验结果单》,也就是性能单,再去做个分类鉴定报告,按照商检局的系列程序走完即可得到危包证。具体可以去当地商检局去咨询办理流程。如果觉得流程繁杂,我们也可以代为办理危包证。办理危包证一般5到7个工作日可以出证,最迟两周。若紧急情况可以加钱进行加急,那么危包证3到5个工作日就能到手。

常见问题

  • 3.2v和3.7v区别

3.2V表示的是磷酸铁锂电池,其主要正极化学原材料为LiFePO4,由于其本身原材料的化学特性,决定了其生产制造出来的单颗电芯电压就是3.2V;

3.7V表示的是聚合物锂电池(常见锂离子电池,如手机、无线无耳机、智能手表等的电池),主要正极化学原材料有LiCoO2、LiNiO2、LiMnO2和锰镍钴复合氧化物等,由于其本身的化学物质的特性,制造出来的电池电芯电压一般是3.7V。

  • 什么是高倍率电池?

High rate battery, 一般指的放电率高,放电电流大的电池,适用于无人机、航模、电动工具等大功率产品。

Redis

Redis

What is redis

An distributed in-memory key-value database.
distributed: redis can scale from a single instance to a distributed system.
in-memory: that’s why redis is fast and commonly serves as cache.
key-value: redis stores key-value pairs.

Why redis

As an in-memory cache, redis is much faster than traditional RDBMS.
Helps reduce database workload.

Install

Server: See offical install procedure here.
As no offical windows install file provided, tporadowski provides an unoffical install file.

Client: redis server ships with a cli tool redis-cli. For GUI client, check RedisInsight out.

Config

Difference between redis.windows-service.conf and redis.windows.conf

redis.windows-service.conf: Configuration file for windows service.
reids.windows.conf: Configuration file for command line.

Security

Default redis requires no auth, but cannot access from machine other than localhost.
To enable remote access (only tested on windows):
In file redis.windows-service.conf:

  1. Comment bind 127.0.0.1(line 64). This makes redis listen to all interfaces.
  2. Change procted-mode yes to protected-mode no(line 83). All clients are now able to connect in.
  3. Uncomment requirepass foobared(line 503) and replace foobared to your own password.

Use

Different types

Type Description
Hash Key-value dictionary object.
Sorted Set Sorted set.
Set Unsorted set.
String Simplest type. String or number.
List Linked list under the hood. Can add element to the head/left or the tail/right.
JSON JSON object. Requires RedisJSON module be installed.

Commands

redis-cli: connects to localhost on port 6379.
redis-cli -h [host] -p [port] -a [password]: connect to specified host and port. If password contains special character, wrap it in quotes.

node redis

Note that redis does not work in browser environment.

Single threaded and asynchronous Javascript

Reference:

  1. A conclusion of Javascript running mechanism
  2. Detailed explanation of Javascript asynchronism
  3. JavaScript Event Loop And Call Stack Explained

Sinle-threaded Javascript

A running chrome consists of multiple process. Each tab is an isolated process.
chrom task manager
A tab process consisits of multiple threads. Among them the important ones includes:

  1. Rendering thread. Renders DOM.
  2. Javascript engine thread. Runs Javascript. Note that when Javascript engine thread runs, rendering thread hangs. Because Javascript engine thread can manipulate DOM and rendering requires a consistent DOM.
  3. Event thread. Handles event loop.
  4. Timer thread. Handles timer methods like setTimeout, setInterval. Timer thread should be stand-alone as running of other function may affect timing accuracy.

Asynchronism

Javascript, well-known for its asynchronism.
Synchronous functions runs and gets result. When function is slow (e.g. has file I/O or web request operations), it waits.
Asynchronous functions runs and expects result. The function does not wait for result, instead it leaves a callback function there to handle future result, and it moves on.
Asynchronism makes Javascript run without idle time. That’s why javascript is fast.

Event loop and call stack

Event loop and call stack
Browsers gives us Web APIs to handle callbacks. Functions like AJAX, setTimeout call these APIs.
Web APIs push callbacks into callback queue. Callbacks wait to be executed in the future.
Event loop watches call stack and callback queue. If call stack is empty, event loop takes one callback from callback queue and javascript engines executes the callback.

Queues

Callback queue is not only one but two queue: macrotask queue and microtask queue.
Everytime event loop is triggered, it takes all microtasks and one macrotask. Microtasks are executed first.
Macrotasks: setTimeout, setInterval, setImmediate, I/O operations, UI rendering
Microtasks: Promise, process.nextTick, MutationObserver

Markdown

Markdown

What is markdown ?

A lightweight markup language which formats content by its simple syntax.

Why markdown ?

  1. Eveywhere, for everything.
    Websites like Reddit, Github, etc. support markdown. Documents, notes, books, emails and so on support markdown. WYSIWYG files are mostly only supported by its own editor.

  2. Human readable. Markdown files are in plain text which is human readable. WYSIWYG files are not.

  3. Portable. As markdown files are written in plain text, it can be created on any device, any operating system. And almost all platforms supports rendering of markdown.

Kicking the tires

Online editor: Dillinger
Client editor: Marktext, a realtime rendering editor

Syntax

Basic

Element Syntax
Heading # Heading 1
## Heading 2
### Heading 3
Bold **bold text**
Italic *Italic*
Blockquote > blockquote
List 1. First Item
2. Second Item
3. Third Item
- First Item
- Second Item
- Third Item
Code `code`
Horizontal rule ---
Link [title](https://www.example.com)
Image ![alt text](image.jpg)

Extended

Element Syntax
Table | Syntax | Description |
| ———– | ———– |
| Header | Title |
| Paragraph | Text |
Note that there must be a blank line after the table.
Fenced code block ```{ firstname: ‘dongtian’, lastname: ‘chen’ }```

Use ``` [language] to specify code block language, for example ``` js to specify javascript. See supported language here
Footnote Here’s a sentence with a footnote. [^1]
[^1]: This is the footnote.
Definition List term
: definition
Strikethrough ~~The world is flat.~~
Task List - [x] Write the press release
- [ ] Update the website
- [ ] Contact the media
Emoji That is so funny! &#x1f602;
Highlight I need to highlight these ==very important words==.
Subscript H~2~O
Superscript X^2^

FAQ

  • Escaping
    Use backslash to escape most special characters.

  • Leading spaces
    Markdown does not support leading spaces before each paragraph. Use &nbsp;(may have some problem with specific renderer like Hexo) or full-width space(a prettier solution) at the beginning.

  • Custom style
    Use html tags directly in markdown and style them with css.
    1
    2
    3
    4
    5
    6
    7
    > <div class="poetry">满堂花醉三千客,一剑霜寒十四州。</div>

    <style>
    .poetry {
    text-align: center;
    }
    </style>

  • Warning box
    The easiest way is to use emojis:
1
>  **If you are using mobile browser**: Be very careful here!

Use emoji to call user attention


  • Change line in blockquote
1
2
3
4
5
6
7
8
9
10
11
12
13
> Case 1
>
> 00:23
>
> 00:54
>
> &nbsp;
>
> Case 2
>
> 00:21
>
> 00:51

will produce:

Case 1

00:23

00:54

&nbsp;

Case 2

00:21

00:51

or an easier one(leave one space at the beginning of the second line and so on):

1
2
3
> line 1
line 2
line 3

will produce:

line 1
line 2
line 3


  • Highlight delete/add line in code

Use diff directive:

1
2
3
``` diff
- I like markup
+ I like markdown

gives:

1
2
- I like markup
+ I like markdown

  • Code block with filename
1
2
``` js, test.js
console.log('hello!')

gives:

test.js
1
console.log('hello!')

  • List in list/nested list

Use 2 or 4 spaces:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Unordered list

* Item 1
* Item 2
* Item 3
* Item 3a
* Item 3b
* Item 3c

# Ordered list

1. Step 1
2. Step 2
3. Step 3
1. Step 3.1
2. Step 3.2
3. Step 3.3
Git

Git

What is Git ?

A distributed version control system.

Why Git over SVN ?

  1. Github uses git. Most modern IT companies use git.
  2. Git is distributed, SVN is centralized. Git enables you to work and source control offline with your own repo.
  3. Most operations are done locally, so it’s fast.

How Git works

Git consists of 4 areas:

  1. Working Directory: Current working directory.
  2. Staging Area: Tracks and saves changes ready to commit.
  3. Local Repo: Repository on the disk.
  4. Remote Repo: Repository on the server.

Git areas

Concepts

  • HEAD: Current branch.

.gitignore file

Refs:

  1. Git ignore patterns
  2. gitignore

Patterns

Pattern Example matches Explanation
logs logs
logs/debug.log
logs/latest/foo.bar
build/logs
build/logs/debug.log
If you don’t append a slash, the pattern will match both files and the contents of directories with that name. In the example matches on the left, both directories and files named logs are ignored
logs/ logs/debug.log
logs/latest/foo.bar
build/logs/foo.bar
build/logs/latest/debug.log
Appending a slash indicates the pattern is a directory. The entire contents of any directory in the repository matching that name – including all of its files and subdirectories – will be ignored
logs/* logs/test.log(a file)
logs/test(a directory)
but not
logs/bar/hello.c(a file)
the asterisk in the pattern does not match “bar/hello.c” which has a slash in it.
logs/
!logs/important.log
logs/debug.log
logs/important.log
Wait a minute! Shouldn’t logs/important.log be negated in the example on the left? Nope! Due to a performance-related quirk in Git, you can not negate a file that is ignored due to a pattern matching a directory
logs/**/debug.log logs/debug.log
logs/monday/debug.log
logs/monday/pm/debug.log
A double asterisk matches zero or more directories.
logs/*day/debug.log logs/monday/debug.log
logs/tuesday/debug.log
but not
logs/latest/debug.log
Wildcards can be used in directory names as well.
logs/debug.log logs/debug.log
but notdebug.log
build/logs/debug.log
Patterns specifying a file in a particular directory are relative to the repository root. (You can prepend a slash if you like, but it doesn’t do anything special.)

FAQ

What is HEAD in git ?

The HEAD in Git is the pointer to the current branch reference, which is in turn a pointer to the last commit you made or the last commit that was checked out into your working directory.

Git reset

Ref

Suppose we have a branch master with A/B/C commits:
- A - B - C (master)

  • reset --soft B: Moves pointer to B; changes staged; run commit and will get a new commit as C
  • reset --mixed B: Default. moves pointer to B; changes remain but unstaged; run add and commit and will get a new commit as C
  • reset --hard B: Moves pointer to B; changes permanently reset; always run status to make sure changes can be discarded

Undo a commit

undo add: git reset
undo commit: git reset --hard HEAD~1 (moves to one commit before and --hard resets staging and working changes)

  • In existing directory, git init .
  • git remote add origin <remote repo url>(origin is a conventional name for remote repo)
  • git push origin <local branch name>

What is a leading slash in .gitignore ?

The leading slash anchors the match to the root.

How can I ignore everything but one file in a directory ?

Original Answer

1
git add -f Website\bin\Settings.json

What is fast-forward ?

Fast forward

Git pull and git fetch

  • Ref: Fetch vs pull
  • Git pull: Incorporates changes from a remote repository into current branch and then fast-forward/merge current branch.
  • Git fetch: If don’t want to fast-forward/merge, use this.
  • pull = fetch + merge

Branches

  • git branch
    Show all local branches, with current branch marked with an asterisk.

    1
    2
    * master
    Pages
  • git branch -r
    Show all remote branches.

    1
    2
    origin/HEAD -> origin/master  // Currently checked out branch, which is origin/master
    origin/master
  • git branch -a
    List all branches.

  • git branch newb
    Create new branch named newb.

  • git checkout newb
    Switch to branch newb.

  • git checkout -b newb
    Shorthand for git branch newb and git checkout newb.

  • git branch -d newb
    Delete local branch newb.