{ Snipperize } /generator
Snippets about generator
Generator of permutations with repetition
A simple tool for generating all n-permutations of a sequence seq seems. The solution above uses the not so well known idiom function(*x) for inserting sequences x with variable length in function calls. # Examples: # a = gen_perm_wr([0,1],3) # print a # <itertools.product object at 0x4187f194> # print a.next() # (0,0,0) # print a.next() # (0,0,1) # print a.next() # (0,1,0) # b = perm_wr([0,1],3) # print b # [(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
Python / permutation, itertool, generator / by ThePeppersStudio (266 days, 12.17 hours ago)
Short URL Generator
Python implementation for generating Tiny URL- and bit.ly-like URLs. A bit-shuffling approach is used to avoid generating consecutive, predictable URLs. However, the algorithm is deterministic and will guarantee that no collisions will occur. The URL alphabet is fully customizable and may contain any number of characters. By default, digits, upper- and lower-case letters are used, with some removed to avoid confusion between characters like o, O and 0. The default alphabet is shuffled and has a prime number of characters to further improve the results of the algorithm. The block size specifies how many bits will be shuffled. The lower BLOCK_SIZE bits are reversed. Any bits higher than BLOCK_SIZE will remain as is. BLOCK_SIZE of 0 will leave all bits unaffected and the algorithm will simply be converting your integer to a different base. The intended use is that incrementing, consecutive integers will be used as keys to generate the short URLs. For example, when creating a new URL, the unique integer ID assigned by a database could be used to generate the URL by using this module. Or a simple counter may be used. As long as the same integer is not used twice, the same short URL will not be generated twice. The module supports both encoding and decoding of URLs. The min_length parameter allows you to pad the URL if you want it to be a specific length. >>> import short_url >>> url = short_url.encode_url(12) >>> print url LhKA >>> key = short_url.decode_url(url) >>> print key 12 Use the functions in the top-level of the module to use the default encoder. Otherwise, you may create your own UrlEncoder object and use its encode_url and decode_url methods.
Python / url, generator, encode, decode, deterministic / by ThePeppersStudio (335 days, 8.75 hours ago)
Unique elements in an iterable without losing order
Python / generator, iteration, iterable, unique, set, yield / by ThePeppersStudio (408 days, 10.96 hours ago)
flexible random password generator
PHP / generator, password, random / by ThePeppersStudio (408 days, 11.11 hours ago)
- 1
- Home
- New Snippet
- Languages
-

