Kernel Panic了就有用了
The magic SysRq key is a key combination in the Linux kernel which allows the user to perform various low level commands regardless[......]
Kernel Panic了就有用了
The magic SysRq key is a key combination in the Linux kernel which allows the user to perform various low level commands regardless[......]
网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的取值有private、no-cache、max-age、must-revalidate等,默认为private。其作用根据不同的重新浏览方式分为以下几种情况:
(1) 打开新窗口
如果指定cache-control的值[......]
1.格式化输出整数
1 2 3 |
strHello = "the length of (%s) is %d" %('Hello World',len('Hello World')) print strHello #输出果:the length of (Hello World) is 11 |
2.格式化输出16制整数
#%x --- hex 十六进制
#%d --- dec 十进制
#%d --- oct 八进制
1 2 3 4 |
nHex = 0x20 print "nHex = %x,nDec = %d,nOct = %o" %(nHex,nHex,nHex) #输出结果:nHex = 20,nDec = 32,nOct = 40 #使用整数的各个制打印同一个数 |
3.[......]
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 |
#!/usr/bin/env python # -*- coding=utf-8 -*- # Implementation of Charikar simhashes in Python # See: http://dsrg.mff.cuni.cz/~holub/sw/shash/#a1 class simhash(): def __init__(self, tokens='', hashbits=128): self.hashbits = hashbits self.hash = self.simhash(tokens) def __str__(self): return str(self.hash) def __long__(self): return long(self.hash) def __float__(self): return float(self.hash) def simhash(self, tokens): # Returns a Charikar simhash with appropriate bitlength v = [0]*self.hashbits for t in [self._string_hash(x) for x in tokens]: bitmask = 0 #print (t) for i in range(self.hashbits): bitmask = 1 << i #print(t,bitmask, t & bitmask) if t & bitmask: v[i] += 1 #查看当前bit位是否为1,是的话则将该位+1 else: v[i] += -1 #否则得话,该位减1 fingerprint = 0 for i in range(self.hashbits): if v[i] >= 0: fingerprint += 1 << i #整个文档的fingerprint为最终各个位大于等于0的位的和 return fingerprint def _string_hash(self, v): # A variable-length version of Python's builtin hash if v == "": return 0 else: x = ord(v[0])<<7 m = 1000003 mask = 2**self.hashbits-1 for c in v: x = ((x*m)^ord(c)) & mask x ^= len(v) if x == -1: x = -2 return x def hamming_distance(self, other_hash): x = (self.hash ^ other_hash.hash) & ((1 << self.hashbits) - 1) tot = 0 while x: tot += 1 x &= x-1 return tot def similarity(self, other_hash): a = float(self.hash) b = float(other_hash) if a>b: return b/a return a/b if __name__ == '__main__': #看看哪些东西google最看重?标点? s = '看看哪些东西google最看重?标点?' hash1 =simhash(s.split()) #print("0x%x" % hash1) #print ("%s\t0x%x" % (s, hash1)) s = '看看哪些东西google最看重!标点!' hash2 = simhash(s.split()) #print ("%s\t[simhash = 0x%x]" % (s, hash2)) print '%f%% percent similarity on hash' %(100*(hash1.similarity(hash2))) print hash1.hamming_distance(hash2),"bits differ out of", hash1.hashbits |
传统的hash函数能够将一样的文本生成一样的hash函数,但是,通过simhash方法,能够差不多相同的文档得到的hash函数也比较相近。
Charikar's hash 通过Charikar‘s has[......]
实际上是字典举穷,把汉字码表和拼音对应起来了
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 |
#!/usr/bin/env python # encoding: utf-8 """ Created by Eric Lo on 2010-05-20. Copyright (c) 2010 __lxneng@gmail.com__. http://lxneng.com All rights reserved. """ class Pinyin(): def __init__(self, data_path='./Mandarin.dat'): self.dict = {} for line in open(data_path): k, v = line.split('\t') self.dict[k] = v self.splitter = '' def get_pinyin(self, chars=u"你好吗"): result = [] for char in chars: key = "%X" % ord(char) try: result.append(self.dict[key].split(" ")[0].strip()[:-1].lower()) except: result.append(char) return self.splitter.join(result) def get_initials(self, char=u'你'): try: return self.dict["%X" % ord(char)].split(" ")[0][0] except: return char |
1 2 3 4 5 6 |
from xpinyin import Pinyin p = Pinyin() p.get_pinyin(u"上海") #输出: 'shanghai' p.get_initials(u"上") #输出 'S' |
下载数据库:http://github.com/lxneng/xpinyin/raw/master/Ma[......]
[......]
正则表达式口诀及教程(推荐)
由 Knightby 撰写 http://www.knightby.net/regular-expressions-formula-and-tutorial-recommended.html
转载自 http://bbs.php.cn/thread-20557-1-[......]
Arguments
该对象代表正在执行的函数和调用它的函数的参数。
[function.]arguments[n]
参数function :选项。当前正在执行的 Function 对象的名字。 n :选项。要传递给 Function 对象的从0开始的参数值索引。
说明A[......]
整数比较
-eq 等于,如:if [ "$a" -eq "$b" ]
-ne 不等于,如:if [ "$a" -ne "$b" ]
-gt 大于,如:if [ "$a" -gt "$b" ]
-ge 大于等于,如:if [ "$a" -ge[......]