예제 #1
0
class TestShortId(unittest.TestCase):
    def setUp(self):
        self.shortid = ShortId()

    def test_should_be_unambiquous_on_a_bunch_of_iterations(self):
        ids = []
        for i in range(0, 100000):
            ids.append(self.shortid.generate())

        self.assertEqual(len(set(ids)), len(ids))

    def test_should_be_unambiquous_on_a_bunch_of_iterations_new_instance(self):
        ids = []
        for i in range(0, 100000):
            ids.append(ShortId().generate())

        self.assertEqual(len(set(ids)), len(ids))

    def test_generate_max_length(self):
        lengths = []
        for i in range(0, 50000):
            lengths.append(len(self.shortid.generate()))
        self.assertEqual(max(lengths) < 12, True)

    def test_generate_max_length_new_instance(self):
        lengths = []
        for i in range(0, 50000):
            lengths.append(len(ShortId().generate()))
        self.assertEqual(max(lengths) < 12, True)
예제 #2
0
class TestShortId(unittest.TestCase):
    def setUp(self):
        self.shortid = ShortId()

    def test_should_be_unambiquous_on_a_bunch_of_iterations(self):
        ids = []
        for i in range(0, 100000):
            ids.append(self.shortid.generate())

        self.assertEqual(len(set(ids)), len(ids))

    def test_should_be_unambiquous_on_a_bunch_of_iterations_new_instance(self):
        ids = []
        for i in range(0, 100000):
            ids.append(ShortId().generate())

        self.assertEqual(len(set(ids)), len(ids))

    def test_generate_max_length(self):
        lengths = []
        for i in range(0, 50000):
            lengths.append(len(self.shortid.generate()))
        self.assertEqual(max(lengths) < 12, True)


    def test_generate_max_length_new_instance(self):
        lengths = []
        for i in range(0, 50000):
            lengths.append(len(ShortId().generate()))
        self.assertEqual(max(lengths) < 12, True)
예제 #3
0
    def copy_to_clipboard(self):
        clipboard = QApplication.clipboard()

        if self.canvas.mode == 'selectrect' and self.canvas.locked:
            clipboard.setPixmap(self.canvas.selectrect_copy())
            sid = ShortId()
            id = sid.generate()
            path =r'.//stamps//' + id + '.png'
            STAMPS.insert(0, path)
            self.canvas.selectrect_copy().save(path, "PNG")
            self.current_stamp_n = -1
            self.next_stamp()
            self.canvas.set_mode('selectrect')

        elif self.canvas.mode == 'selectpoly' and self.canvas.locked:
            clipboard.setPixmap(self.canvas.selectpoly_copy())
            path, _ = QFileDialog.getSaveFileName(self, "Save file", "", "PNG Image file (*.png)")
            self.canvas.selectrect_copy().save(path, "PNG")
            # sid = ShortId()
            # id = sid.generate()
            # path = r'.//stamps//' + id + '.png'
            # STAMPS.insert(0, path)
            # self.canvas.selectrect_copy().save(path, "PNG")
            # self.current_stamp_n = -1
            # self.next_stamp()
            # self.canvas.set_mode('selectpoly')
        else:
            clipboard.setPixmap(self.canvas.pixmap())
예제 #4
0
파일: user.py 프로젝트: DESECTORCON/noteit
    def __init__(self,
                 email,
                 password,
                 _id=None,
                 nick_name=None,
                 last_logined=datetime.datetime.now(),
                 friends=[],
                 group_id=None,
                 picture=None):
        """

        :param email:
        :param password:
        :param _id:
        :param nick_name:
        :param last_logined:
        :param friends:
        :param group_id:
        """
        self.email = email
        self.password = password
        self._id = uuid.uuid4().hex if _id is None else _id
        sid = ShortId()
        self.nick_name = "User " + sid.generate(
        ) if nick_name is None else nick_name
        self.last_logined = last_logined
        self.friends = friends
        self.group_id = group_id
        if picture is None:
            self.picture = 'img/index.jpg'
        else:
            self.picture = picture
예제 #5
0
class TestShortId(unittest.TestCase):
    def setUp(self):
        self.shortid = ShortId()

    def test_should_be_unambiquous_on_a_bunch_of_iterations(self):
        ids = []
        for i in range(0, 50000):
            ids.append(self.shortid.generate())

        self.assertEqual(len(set(ids)), len(ids))
예제 #6
0
 def __init__(self,
              email,
              password,
              _id=None,
              nick_name=None,
              last_logined=datetime.datetime.now()):
     self.email = email
     self.password = password
     self._id = uuid.uuid4().hex if _id is None else _id
     sid = ShortId()
     self.nick_name = "User " + sid.generate(
     ) if nick_name is None else nick_name
     self.last_logined = last_logined
예제 #7
0
class TestShortId(unittest.TestCase):
    def setUp(self):
        self.shortid = ShortId()

    def test_should_be_unambiquous_on_a_bunch_of_iterations(self):
        ids = []
        for i in range(0, 50000):
            ids.append(self.shortid.generate())

        self.assertEqual(len(set(ids)), len(ids))

    def test_shortid_should_generate_the_right_string_length(self):
        self.assertEqual(len(shortid(7)), 7)

    def test_shortid_should_use_the_right_alphabet(self):
        self.assertTrue(re.match(r'^[a-zA-Z0-9_-]+$', shortid()))

    def test_generate_should_use_the_right_alphabet(self):
        self.assertTrue(re.match(r'^[a-zA-Z0-9_-]+$', self.shortid.generate()))

    def test_generate_should_generate_the_right_string_length(self):
        self.assertTrue(7 <= len(shortid(7)) <= 14)
예제 #8
0
파일: models.py 프로젝트: jdcantrell/spice
    def __init__(
        self, name, filename, path, handler, filetype, access, user_id
    ):
        self.name = name
        self.filename = filename
        self.path = path
        self.handler = handler
        self.filetype = filetype
        self.user_id = user_id
        self.access = access
        sid = ShortId()
        self.key = sid.generate()

        self.views = 0
예제 #9
0
파일: pool_executor.py 프로젝트: asrvsn/lkf
def pool_execute(args: list,
                 gen_system: Callable,
                 seed=None,
                 reduce_result=lambda x: x):
    global _implicit_gen
    _implicit_gen = gen_system

    idgen = ShortId()
    results = dict()

    with tqdm(total=len(args)) as pbar:

        def add_result(result):
            results[result['id']] = reduce_result(result)
            pbar.update(1)

        with multiprocessing.Pool() as pool:
            for arg in args:
                arg['id'] = idgen.generate()
                pool.apply_async(worker, args=(arg, seed), callback=add_result)
            pool.close()
            pool.join()

    return [results[arg['id']] for arg in args]
예제 #10
0
파일: models.py 프로젝트: jdcantrell/kodiak
 def __init__(self, data, access='limited'):
     self.data = data
     self.access = access
     sid = ShortId()
     self.key = sid.generate()
예제 #11
0
            #datas = []
            #labels = []

            #face = cv2.imread(filepath, cv2.CV_LOAD_IMAGE_GRAYSCALE)
            #datas.append(np.array(face, 'uint8'))
            #labels.append(int(student_number))

            #if os.path.exists('./models/student.yml'):
            #    lbph.update(np.array(datas), np.array(labels))
            #else:
            #    lbph.train(np.array(datas), np.array(labels))
            #model = True
            #lbph.save('./models/student.yml')
        
        if ch in [chr(32)]:
            short = sid.generate()
            img.save('default.png', frame)
            filepath = save_face(img, short)

            url = upload(filepath)            
            key_face_id = face_detect(url)
            if key_face_id != -1: 
                res = recognition_search(key_face_id)
                print('=====================')
                print(res)
                similarity = res['candidate'][0]['similarity']
                if similarity > 80:
                        os.system('node ./index.js');


                confidence = similarity
예제 #12
0
"""
This tracks anonymized usage statistics of gluestick using Mixpanel.
If you'd like to disable this, please refer to the gluestick docs https://docs.gluestick.xyz
"""
import os

from mixpanel import Mixpanel
from shortid import ShortId

mp = Mixpanel('c1183ed0e00132d88ad169ddd3f3673b')
sid = ShortId()
anon_id = sid.generate()

def track(event_name, event_data = {}):
    """
    Sends event to Mixpanel using anon_id 
    """
    # Check if usage stat collection is enabled
    is_enabled = os.environ.get("GLUESTICK_USAGE_STATS", "ENABLE") == "ENABLE"
    if not is_enabled:
        return

    # Send event to Mixpanel
    mp.track(anon_id, event_name, event_data)