def generate_header():
    r_list = RandomList()
    header_dict = {}

    # cookie
    cookie_str = '''
_T_WM=bd80db78b4ed27825deaa022e62b0c4d; ALF=1490583082; SCF=AsAX-nl6za_tqmlP7Wc4KZBfnM5lvn6m2-lc1hztSI7kOIqTS7AgSwx49SYl9Zp0VjD5FBSRDRdqq9zWMjoHnq8.; SUB=_2A251t6DpDeRxGeRN61EX9CrJyjyIHXVXW8ChrDV6PUNbktBeLVenkW00qpJdPx7uyVWiIrZ6o3dbKcj-1Q..; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9Wh3LNHVkce-0__UlEggblno5JpX5KMhUgL.Foz0ehecShBfeK52dJLoIEBLxK.L1-qLBK.LxK.L1-qLBK.LxKqLBoqLBKqLxKnLBoqL1h-t; SUHB=08JKhus4sxO2oe; SSOLoginState=1488179386
                 '''.strip()
    header_dict['Cookie'] = cookie_str
    header_dict['Accept-Language'] = 'zh-CN,zh;q=0.8'
    header_dict['User-Agent'] = r_list.get_random_ua()
    header_dict['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
    #header_dict['Accept-Encoding'] = 'gzip, deflate, sdch'
    header_dict['Cache-Control'] = 'max-age=0'
    header_dict['Connection'] = 'keep-alive'
    header_dict['Host'] =  'weibo.cn'
    header_dict['Referer'] = 'weibo.cn/2303644510/info' # r_list.get_random(referers)
    header_dict['Upgrade-Insecure-Requests'] = '1'
    return header_dict
Beispiel #2
0
class FontManager():
    def __init__(self, fontSize):
        self.fontSize = fontSize
        self.allFonts = QtGui.QFontDatabase().families(QtGui.QFontDatabase.Latin)
        self.randomList = RandomList(len(self.allFonts))

    def step(self):
        return self.allFonts[self.randomList.step()]
        
    def changeFontSize(self, delta):
        self.fontSize += delta
Beispiel #3
0
class FontManager():
    def __init__(self, fontSize):
        self.fontSize = fontSize
        self.allFonts = QtGui.QFontDatabase().families(
            QtGui.QFontDatabase.Latin)
        self.randomList = RandomList(len(self.allFonts))

    def step(self):
        return self.allFonts[self.randomList.step()]

    def changeFontSize(self, delta):
        self.fontSize += delta
Beispiel #4
0
def run():
    def set_led_color():
        led.color = Color(*colors_list.values)

    def change_led_color():
        colors_list.shuffle()
        set_led_color()

    led = RGBLED(PIN_RED, PIN_GREEN, PIN_BLUE)
    button = Button(PIN_BUTTON)
    colors_list = RandomList(3, MIN_VALUE, MAX_VALUE)

    set_led_color()
    button.when_pressed = change_led_color
    pause()
Beispiel #5
0
class IdeazMultipleLists(object):
    '''
    - This class takes a list of text files from the commandline.
    - Each text file i stores N_i lines.
    - By calling step(), one item from each file is selected and returned as a list of strings.
    - There are in total \prod_i N_i combinations.
    - Algorithm:
    -- There are \prod_i N_i combinations
    -- A candidate is randomly selected from the range 0..N_combinations-1
    -- A candidate is represented as a linear combination 
       candidate = i + N_i*j + N_i * N_j*k + ...
    -- i, j, k are computed by alternating mod and division
    '''
    def __init__(self, filenames):
        self.filenames = filenames
        self.data, self.list_lengths = self.parseCommandLine(filenames)
        N_combinations = np.prod(self.list_lengths)
        self.candidates = RandomList(N_combinations)

    def parseCommandLine(self, filenames):
        data = []
        list_lengths = []
        for fn in filenames:
            data.append([line.strip() for line in open(fn, 'r')])
            list_lengths.append(len(data[-1]))
        return data, list_lengths

    def getRawIndices(self, candidate):
        rawIndices = np.array([np.mod(candidate, self.list_lengths[0])],
                              dtype=np.uint32)
        for i, length in enumerate(self.list_lengths[:-1]):
            candidate = np.uint32(candidate / length)
            rawIndices = np.append(rawIndices,
                                   np.mod(candidate, self.list_lengths[i + 1]))
        return rawIndices

    def getSelectedData(self, data, rawIndices):
        selectedData = []
        for i, rawIndex in enumerate(rawIndices):
            selectedData.append(data[i][rawIndex])
        return selectedData

    def step(self):
        rawIndices = self.getRawIndices(self.candidates.step())
        return self.getSelectedData(self.data, rawIndices)

    def getNrOfLayers(self):
        return len(self.filenames)
Beispiel #6
0
class IdeazMultipleLists(object):
    '''
    - This class takes a list of text files from the commandline.
    - Each text file i stores N_i lines.
    - By calling step(), one item from each file is selected and returned as a list of strings.
    - There are in total \prod_i N_i combinations.
    - Algorithm:
    -- There are \prod_i N_i combinations
    -- A candidate is randomly selected from the range 0..N_combinations-1
    -- A candidate is represented as a linear combination 
       candidate = i + N_i*j + N_i * N_j*k + ...
    -- i, j, k are computed by alternating mod and division
    '''
    def __init__(self, filenames):
        self.filenames = filenames
        self.data, self.list_lengths = self.parseCommandLine(filenames)
        N_combinations = np.prod(self.list_lengths)
        self.candidates = RandomList(N_combinations)

    def parseCommandLine(self, filenames):
        data = []
        list_lengths = []
        for fn in filenames:
            data.append([line.strip() for line in open(fn, 'r')])
            list_lengths.append(len(data[-1]))
        return data, list_lengths

    def getRawIndices(self, candidate):
        rawIndices = np.array([np.mod(candidate, self.list_lengths[0])], dtype=np.uint32)
        for i, length in enumerate(self.list_lengths[:-1]):
            candidate = np.uint32(candidate/length)
            rawIndices = np.append(rawIndices, np.mod(candidate, self.list_lengths[i+1]))
        return rawIndices

    def getSelectedData(self, data, rawIndices):
        selectedData = []
        for i, rawIndex in enumerate(rawIndices):
            selectedData.append(data[i][rawIndex])
        return selectedData

    def step(self):
        rawIndices = self.getRawIndices(self.candidates.step())
        return self.getSelectedData(self.data, rawIndices)
        
    def getNrOfLayers(self):
        return len(self.filenames)
Beispiel #7
0
class IdeazOneList(object):
    def __init__(self, filenames, N_layers):
        self.data = self.parseCommandLine(filenames)
        self.setNrOfLayers(N_layers)
        
    def setNrOfLayers(self, N_layers):
        self.N_layers = N_layers
        self.N_combinations = np.prod(len(self.data)-np.arange(N_layers))
        self.candidates = RandomList(self.N_combinations)
        
    def parseCommandLine(self, filenames):
        data = []
        for fn in filenames:
            data += [line.strip() for line in open(fn, 'r')]
        return data
    
    def getRawIndices(self, candidate):
        N = len(self.data);
        rawIndices = np.array([np.mod(candidate, N)], dtype=np.uint32)
        for i in np.arange(self.N_layers-1):
            candidate = np.uint32(candidate/(N-i))
            rawIndices = np.append(rawIndices, np.mod(candidate, N-i-1))
        return rawIndices
        
    def getFineIndices(self, rawIndices):
        allIndices = np.arange(self.N_combinations)
        fineIndices = np.array([], dtype=np.uint32)
        for i in np.arange(self.N_layers):
            fineIndices = np.append(fineIndices, allIndices[rawIndices[i]])
            allIndices = np.delete(allIndices, rawIndices[i])
        return fineIndices
        
    def getSelectedData(self, fineIndices):
        selectedData = []
        for i in fineIndices:
            selectedData.append(self.data[i])
        return selectedData
        
    def step(self):
        rawIndices = self.getRawIndices(self.candidates.step())
        fineIndices = self.getFineIndices(rawIndices)
        return self.getSelectedData(fineIndices)
        
    def getNrOfLayers(self):
        return self.N_layers
Beispiel #8
0
class IdeazOneList(object):
    def __init__(self, filenames, N_layers):
        self.data = self.parseCommandLine(filenames)
        self.setNrOfLayers(N_layers)

    def setNrOfLayers(self, N_layers):
        self.N_layers = N_layers
        self.N_combinations = np.prod(len(self.data) - np.arange(N_layers))
        self.candidates = RandomList(self.N_combinations)

    def parseCommandLine(self, filenames):
        data = []
        for fn in filenames:
            data += [line.strip() for line in open(fn, 'r')]
        return data

    def getRawIndices(self, candidate):
        N = len(self.data)
        rawIndices = np.array([np.mod(candidate, N)], dtype=np.uint32)
        for i in np.arange(self.N_layers - 1):
            candidate = np.uint32(candidate / (N - i))
            rawIndices = np.append(rawIndices, np.mod(candidate, N - i - 1))
        return rawIndices

    def getFineIndices(self, rawIndices):
        allIndices = np.arange(self.N_combinations)
        fineIndices = np.array([], dtype=np.uint32)
        for i in np.arange(self.N_layers):
            fineIndices = np.append(fineIndices, allIndices[rawIndices[i]])
            allIndices = np.delete(allIndices, rawIndices[i])
        return fineIndices

    def getSelectedData(self, fineIndices):
        selectedData = []
        for i in fineIndices:
            selectedData.append(self.data[i])
        return selectedData

    def step(self):
        rawIndices = self.getRawIndices(self.candidates.step())
        fineIndices = self.getFineIndices(rawIndices)
        return self.getSelectedData(fineIndices)

    def getNrOfLayers(self):
        return self.N_layers
Beispiel #9
0
'''
Created on 2016年1月12日
# encoding: utf-8
@author: tcliu
'''

from random_list import RandomList
R = RandomList(10, 100)
lst = R.gen()


#lst = [1, 3, 5, 3, 9]
def bucket_sort(lst=[]):
    sorted_list = []
    lenth = max(lst) - min(lst) + 1
    bucket = [0] * lenth
    for item in lst:
        bucket[item - min(lst)] += 1
    for i in range(len(bucket)):
        if bucket[i] > 0:
            sorted_list.extend([(i + min(lst))] * bucket[i])
    print(sorted_list)
    return sorted_list


bucket_sort(lst)
Beispiel #10
0
'''
Created on 2016年1月18日
# encoding: utf-8
@author: tcliu


'''
from random_list import RandomList
R = RandomList(5, 10)
lst = R.gen()


def path_sort(list, start_index, end_index):
    flag = list[end_index]
    i = start_index - 1
    for j in range(start_index, end_index):
        if list[j] > flag:
            pass
        else:
            i += 1
            tmp = list[i]
            list[i] = list[j]
            list[j] = tmp
    tmp = list[end_index]
    list[end_index] = list[i + 1]
    list[i + 1] = tmp

    return i + 1


def Quick_sort(list, start_index, end_index):
Beispiel #11
0
'''
Created on 2016年1月13日
# encoding: utf-8
@author: tcliu
'''
from random_list import RandomList
R = RandomList(5, 10)
lst = R.gen()

def bubble_sort(l = []):
    for i in range(len(l)):
        for j in range(len(l) - i -1):
            if l[j] > l[j + 1]:
                #(l[j + 1], i[j]) = (l[j], l[j + 1])
                l[j], l[j+1] = l[j+1], l[j]
            else:
                continue   
    print(l)    
bubble_sort(lst)         
Beispiel #12
0
 def __init__(self, fontSize):
     self.fontSize = fontSize
     self.allFonts = QtGui.QFontDatabase().families(QtGui.QFontDatabase.Latin)
     self.randomList = RandomList(len(self.allFonts))
Beispiel #13
0
 def setNrOfLayers(self, N_layers):
     self.N_layers = N_layers
     self.N_combinations = np.prod(len(self.data) - np.arange(N_layers))
     self.candidates = RandomList(self.N_combinations)
Beispiel #14
0
 def __init__(self, filenames):
     self.filenames = filenames
     self.data, self.list_lengths = self.parseCommandLine(filenames)
     N_combinations = np.prod(self.list_lengths)
     self.candidates = RandomList(N_combinations)
Beispiel #15
0
 def __init__(self, filenames):
     self.filenames = filenames
     self.data, self.list_lengths = self.parseCommandLine(filenames)
     N_combinations = np.prod(self.list_lengths)
     self.candidates = RandomList(N_combinations)
Beispiel #16
0
 def setNrOfLayers(self, N_layers):
     self.N_layers = N_layers
     self.N_combinations = np.prod(len(self.data)-np.arange(N_layers))
     self.candidates = RandomList(self.N_combinations)
Beispiel #17
0
 def __init__(self, fontSize):
     self.fontSize = fontSize
     self.allFonts = QtGui.QFontDatabase().families(
         QtGui.QFontDatabase.Latin)
     self.randomList = RandomList(len(self.allFonts))