zzp's blog


  • 首页

  • 分类

  • 归档

  • 搜索

vundle插件安装器, nerdcommenter注释插件

发表于 2017-12-14 | 分类于 vim | 阅读次数

vundle vim 使用命令

1
2
3
4
" :PluginList       - 列出所有已配置的插件
" :PluginInstall - 安装插件, 加 `!` 用以更新或使用 :PluginUpdate
" :PluginSearch foo - 搜索 foo ;追加 `!` 清除本地缓存
" :PluginClean - 清除未使用插件,需要确认; 追加 `!`

nerdcommenter

Usage Doc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    n\cc : 为光标以下 n 行添加注释
n\cu : 为光标以下 n 行取消注释
n\cm : 为光标以下 n 行添加块注释

for python:

单行:
注释: \cs
取消注释:\cu

多行:
ctrl + v 块选中后:
注释: \cs
取消注释:\cu

\ci 为Inverts the commented state of each selected line.

parallel命令:并行处理

发表于 2017-12-01 | 分类于 linux | 阅读次数
1
ls | parallel -j 8 "python dic.py -f {}"

How can I use GNU Parallel to run a lot of commands in parallel | Minnesota Supercomputing Institute

GNU Parallel tutorial

find max squre submatrix

发表于 2017-11-10 | 分类于 algorithm , other | 阅读次数

输入0-1矩阵,返回最大边长的全为1的子矩阵的边长,及在原始矩阵中的位置

阅读全文 »

批量处理MP3文件tag乱码

发表于 2017-10-27 | 分类于 linux | 阅读次数
1
sudo apt install python-mutagen

切换到mp3所在目录下

1
find . -iname "*.mp3" -execdir mid3iconv -e gbk {} \;

vim操作大全

发表于 2017-09-22 | 分类于 vim | 阅读次数

粘贴模式

复制东西进vi时,为了避免vi自动缩进,
set paste之后再复制
复制完set nopaste

阅读全文 »

python判断字符编码

发表于 2017-09-16 | 分类于 python | 阅读次数
1
2
3
4

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

Python 字符编码判断

法一

1
2
3
4
5
6
7
8

#判断是否为一般字符串

isinstance(s, str)

#用来判断是否为unicode

isinstance(s, unicode)

或

1
2
if type(str).__name__  != "unicode":
str=unicode(str, "utf-8")

法二:

Python chardet 字符编码判断
使用 chardet 可以很方便的实现字符串/文件的编码检测。尤其是中文网页,有的页面使用GBK/GB2312,有的使用UTF8,如果你需要去爬一些页面,知道网页编码很重要的,虽然HTML页面有charset标签,但是有些时候是不对的。那么chardet就能帮我们大忙了。

1
2
3
4
5
6

import urllib

import chardet
rawdata = urllib.urlopen('http://www.google.cn/').read()
chardet.detect(rawdata)

Results:

1
2

{'confidence': 0.98999999999999999, 'encoding': 'GB2312'}

chardet可以直接用detect函数来检测所给字符的编码。

函数返回值为字典,有2个元数,一个是检测的可信度,另外一个就是检测到的编码。

python: operator

发表于 2017-09-16 | 分类于 python | 阅读次数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
"""
This program lets you create a simple command line calculator without using
the 'if..else' construct. It uses built-in 'operator' module to accomplish the
same

Created with help of an answer on stackoverflow. Don't have the exact link.
"""

import operator
ops = {
"+": operator.add,
"-": operator.sub,
"/": operator.truediv,
"*": operator.mul
}

x = input("Enter an operator [OPTIONS: +, -, *, /]: ")
y = int(input("Enter number: "))
z = int(input("Enter number: "))

print (ops[x](y, z))

python: set

发表于 2017-05-24 | 分类于 python | 阅读次数
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

>>> x = set("jihite")

>>> y = set(['d', 'i', 'm', 'i', 't', 'e'])

>>> x #把字符串转化为set,去重了

set(['i', 'h', 'j', 'e', 't'])

>>> y

set(['i', 'e', 'm', 'd', 't'])

>>> x & y #交

set(['i', 'e', 't'])

>>> x | y #并

set(['e', 'd', 'i', 'h', 'j', 'm', 't'])

>>> x - y #差

set(['h', 'j'])

>>> y - x

set(['m', 'd'])

>>> x ^ y #对称差:x和y的交集减去并集

set(['d', 'h', 'j', 'm'])
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

>>> x

set(['i', 'h', 'j', 'e', 't'])

>>> s = set("hi")

>>> s

set(['i', 'h'])

>>> len(x) #长度

>>> 'i' in x

True

>>> s.issubset(x) #s是否为x的子集

True

>>> y

set(['i', 'e', 'm', 'd', 't'])

>>> x.union(y) #交

set(['e', 'd', 'i', 'h', 'j', 'm', 't'])

>>> x.intersection(y) #并

set(['i', 'e', 't'])

>>> x.difference(y) #差

set(['h', 'j'])

>>> x.symmetric_difference(y) #对称差

set(['d', 'h', 'j', 'm'])

>>> s.update(x) #更新s,加上x中的元素

>>> s

set(['e', 't', 'i', 'h', 'j'])

>>> s.add(1) #增加元素

>>> s

set([1, 'e', 't', 'i', 'h', 'j'])

>>> s.remove(1) #删除已有元素,如果没有会返回异常

>>> s

set(['e', 't', 'i', 'h', 'j'])

>>> s.remove(2)




Traceback (most recent call last):

File "<pyshell#29>", line 1, in <module>

s.remove(2)

KeyError: 2

>>> s.discard(2) #如果存在元素,就删除;没有不报异常

>>> s

set(['e', 't', 'i', 'h', 'j'])

>>> s.clear() #清除set

>>> s

set([])

>>> x

set(['i', 'h', 'j', 'e', 't'])

>>> x.pop() #随机删除一元素

'i'

>>> x

set(['h', 'j', 'e', 't'])

>>> x.pop()

'h'

除了两个异类元素,其余都是成对出现的,O(n)时间复杂度找出它俩

发表于 2017-05-04 | 分类于 python | 阅读次数

#按位与(AND):处理两个长度相同的二进制数,两个相应的二进位都为1,该位的结果值才为1,否则为0

0b1010 & 0b1100

8 #1000

#按位或(OR): 按位或处理两个长度相同的二进制数,两个相应的二进位中只要有一个为1,该位的结果值为1

0b1010 | 0b1100

14 #1110

#按位异或(XOR): 对等长二进制模式按位,或二进制数的每一位执行逻辑异按位或操作。操作的结果是如果某位不同则该位为1,否则该位为0

0b1010 ^ 0b1100

6 #0110

#移位:将一个二进制数中的每一位全部都向一个方向移动指定位,溢出的部分将被舍弃,而空缺的部分填入一定的值。

0b1010 << 2

40 #101000

0b1010 >> 2

2 #10

#取反(NOT): 一元操作,对二进制每位执行逻辑反,1->0, 0->1, 值得注意的是此操作符与”逻辑非(!)”操作符不同

~0b1010
-11 #10000000 00000000 00000000 00001011

type(0b1010)

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
46
47
48
49
50
51
52
53
54
55
56
57
# coding:utf-8
'''
一个数组仅有两个不同的值是仅含一个的.
其余值都是含两个的. 例如:[1, 1, 2, 2, 3, 4]

目标:
找出那两个异常值.
要求:
算法复杂度O(n)
空间占用为常数,与n无关

为了不局限于比较对象,对hash值进行位操作.

'''

def XOR(a):
"""
XOR of all elements of a.
"""
xor = hash(a[0])
for i in a[1:]:
xor ^= hash(i)
return xor

def find(a):
r = XOR(a)
pos = 0
# pos 为r的2进制形式下从左往右首位不是0的位置.
while r & 1 == 0:
r = r>>1
pos += 1
num1, num2 = None, None
# 将原数组按照二进制在pos位置是否为1分成两组
for i in a:
if (hash(i) >> pos) & 1 == 0:
if num1 != None:
num1 ^= hash(i)
else:
num1 = hash(i)
else:
if num2 != None:
num2 ^= hash(i)
else:
num2 = hash(i)
for i in a:
if hash(i) == num1 or hash(i) == num2:
yield i

if __name__ == '__main__':
a = range(10)*2 + [11,12]
print(a)
for i in find(a):
print(i)
a = ['a', 'a', 'b', 'b', 'zsdf', 'fdfe']
print(a)
for i in find(a):
print(i)

mdcharm编辑器配置

发表于 2017-03-12 | 分类于 linux | 阅读次数

mdcharm打开方式消失

解决方法:

修改

1
2


Exec=/usr/bin/mdcharm %u

1
2
3
4
5
6
7
8
9
10
11
12

# 去掉启动打开历史记录的功能

```bash
# cd MdCharm config dir.
cd ~/.config/MdCharm/

# clear file history in session.xml.
vi session.xml

# -write
chmod -w session.xml

1…6789
ningning

ningning

86 日志
9 分类
GitHub
© 2018 - 2020 ningning
本站访客数 人次