-
-
Save fengjing/d634c0f9fd02c34f00433e4f45b7f740 to your computer and use it in GitHub Desktop.
Revisions
-
wonderbeyond revised this gist
Sep 16, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,5 +28,5 @@ def get_random_string(length=12, import random def get_random_string(N=12, allowed_chars=(string.ascii_letters + string.digits)): return ''.join(random.choice(allowed_chars) for _ in range(N)) -
wonderbeyond revised this gist
May 10, 2018 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,4 +19,14 @@ def get_random_string(length=12, time.time(), 'O_O-SECRET_KEY')).encode('utf-8') ).digest()) return ''.join(random.choice(allowed_chars) for i in range(length)) # --- Simple One --- import string import random def get_random_string(N=12, allowed_chars=(string.letters + string.digits)): return ''.join(random.choice(allowed_chars) for _ in range(N)) -
wonderbeyond revised this gist
Nov 20, 2017 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,18 @@ import os import binascii import uuid from xid import Xid def get_guid(style='uuid'): """Get a globally unique string for identify things""" if style == 'uuid': return uuid.uuid4().hex if style == 'xid': return Xid().string() raise RuntimeError('Unsupported guid style: {0}'.format(style)) # Equivalent implementation -
wonderbeyond revised this gist
Nov 16, 2017 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,13 @@ import os import binascii import uuid def get_guid(): """Get a globally unique string for identify things""" return uuid.uuid4().hex # Equivalent implementation def get_guid(): return binascii.hexlify(os.urandom(16)).decode() -
wonderbeyond revised this gist
Nov 16, 2017 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ import uuid def get_guid(): """Get a globally unique string for identify things""" return uuid.uuid4().hex -
wonderbeyond revised this gist
Nov 16, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,7 @@ def get_random_string(length=12, See also: https://github.com/rs/xid (globally unique id generator) https://stackoverflow.com/questions/41354205/how-to-generate-a-unique-auth-token-in-python https://docs.python.org/3/whatsnew/3.6.html#secrets """ random.seed( hashlib.sha256( -
wonderbeyond revised this gist
Nov 16, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,9 @@ def get_random_string(length=12, allowed_chars='abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'): """ See also: https://github.com/rs/xid (globally unique id generator) https://stackoverflow.com/questions/41354205/how-to-generate-a-unique-auth-token-in-python """ random.seed( hashlib.sha256( -
wonderbeyond revised this gist
Oct 17, 2017 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,9 @@ def get_random_string(length=12, allowed_chars='abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'): """ See also: https://github.com/rs/xid (globally unique id generator) """ random.seed( hashlib.sha256( ("%s%s%s" % ( -
wonderbeyond created this gist
Nov 29, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import random import hashlib import time def get_random_string(length=12, allowed_chars='abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'): random.seed( hashlib.sha256( ("%s%s%s" % ( random.getstate(), time.time(), 'O_O-SECRET_KEY')).encode('utf-8') ).digest()) return ''.join(random.choice(allowed_chars) for i in range(length))