Skip to content

Instantly share code, notes, and snippets.

View ZenRay's full-sized avatar
🏠

ZenRay

🏠
View GitHub Profile
中文的正则一般用 `[ \u4e00-\u9fa5]+` 即可。但对特殊字符不能完全匹配,例如:火星文、全角的字符标点符号。
中文世界字符主要来自于中日韩统一表意文字(CJK Unified Ideographs),以及一些特殊的字符。大范围覆盖字符推荐用 `[ \u2E80-\uFE4F]+` 。
根据Unicode5.0整理(reference [Unicode中文和特殊字符的编码范围](https://gist.github.com/shingchi/64c04e0dd2cbbfbc1350))如下:
1)标准CJK文字
http://www.unicode.org/Public/UNIDATA/Unihan.html
2)全角ASCII、全角中英文标点、半宽片假名、半宽平假名、半宽韩文字母:FF00-FFEF
@ZenRay
ZenRay / awk.sh
Last active June 9, 2020 00:55
使用 awk 处理文本数据
1. 通过正则表达式检查文本内符合模式的数量
```{bash}
<<comment
命令格式:awk '/<pattern>/ { <variable> ++ }; END { print <variable>};' <filepath>
说明:<pattern> 为正则表达式模式,<variable> 统计符合模式的变量,<filepath> 文件路径
comment
$ awk '/\d+/ {x++} ; END { print x };' log/20200608.log
```
@ZenRay
ZenRay / id&hash.py
Last active September 23, 2019 17:07
Note#python
# Python 中 id 函数实现是通过 __hash__() 方法实现。__hash__() 方法保障没个对象是可以被哈希,并且哈希值是唯一的
x = object()
id(x)
hash(x)
# 如果要得到验证两者相关,可以将 id 函数的数据值除以一个数据值——具体数据值和平台、系统相关
id(x) / 16 == hash(x)
@ZenRay
ZenRay / formatString.py
Created September 23, 2019 16:07
FormatString#python
# specify the special format string
'{:{}{}{}.{}}'.format(2.7182818284, '>', '+', 10, 3)
'{:{}{sign}{}.{}}'.format(2.7182818284, '>', 10, 3, sign='+')
@ZenRay
ZenRay / family-and-alone.csv
Last active May 6, 2018 04:23
实现animation
Category Percentage Survived Dead
Alone 60 30 70
With Parents or Children 24 51 49
With Siblings or Spouses 32 47 53
@ZenRay
ZenRay / baseball.html
Last active September 25, 2019 02:15
D3
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.0.0.min.js"></script>
<script type="text/javascript">
function draw(data) {
// debugger;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.0.0.min.js"></script>
<script type="text/javascript">
function draw(data) {
"use strict";
name handedness height weight avg HR
Tom Brown R 73 170 0.0 0
Denny Lemaster R 73 182 0.130 4
Joe Nolan L 71 175 0.263 27
Denny Doyle L 69 175 0.250 16
Jose Cardenal R 70 150 0.275 138
Mike Ryan R 74 205 0.193 28
Fritz Peterson B 72 185 0.159 2
Dick Bertell R 72 200 0.250 10
Rod Kanehl R 73 180 0.241 6
Tom Brown R 73 170 0.0 0
Denny Lemaster R 73 182 0.130 4
Joe Nolan L 71 175 0.263 27
Denny Doyle L 69 175 0.250 16
Jose Cardenal R 70 150 0.275 138
Mike Ryan R 74 205 0.193 28
Fritz Peterson B 72 185 0.159 2
Dick Bertell R 72 200 0.250 10
Rod Kanehl R 73 180 0.241 6