Giter VIP home page Giter VIP logo

python-utilitybelt's Introduction

Utility Belt

CircleCI PyPI PyPI PyPI

Entropy

>>> from binascii import hexlify
>>> from utilitybelt import dev_random_entropy, dev_urandom_entropy
>>> hexlify(dev_random_entropy(16))
'cc8752461384261063a979bf5d92ad49'
>>> hexlify(dev_urandom_entropy(16))
'874ac235edfa658bd46c763079acc096'

Base16

>>> from utilitybelt import hex_to_int, int_to_hex, is_hex, is_int
>>> hex_to_int('deadbeef')
3735928559
>>> int_to_hex(3735928559)
'deadbeef'
>>> is_hex('deadbeef')
True
>>> is_hex('xdeadbeefx')
False
>>> is_int(123)
True
>>> is_int('deadbeef')
False

Dicts

Recursive dicts

>>> from utilitybelt import recursive_dict, recursive_dict_to_dict
>>> rd = recursive_dict()
>>> rd['a']['b']['c'] = 1
>>> rd['a']['b']['c']
1
>>> rd['a']['b']['d']
defaultdict(<function <lambda> at 0x102912b90>, {})
>>> d = recursive_dict_to_dict(rd); print d
{'a': {'b': {'c': 1, 'd': {}}}}

Scrubbing dicts

>>> from utilitybelt import scrub_dict
>>> d
{'a': {'b': {'c': 1, 'd': {}}}}
>>> scrub_dict(d)
{'a': {'b': {'c': 1}}}

Converting objects to dicts

>>> from utilitybelt import to_dict
>>> class Rectangle():
>>>     def __init__(self, width, length):
>>>         self.width = width
>>>         self.length = length
>>> rectangle = Rectangle(2, 4)
>>> to_dict(rectangle)
{'width': 2, 'length': 4}

Charsets

Moving from string charsets to ints and vice versa

>>> from utilitybelt import charset_to_int, int_to_charset
>>> charset_to_int('deadbeef', string.hexdigits[0:16])
3735928559
>>> int_to_charset(3735928559, string.hexdigits[0:16])
'deadbeef'

Changing arbitrary charsets

>>> from utilitybelt import change_charset
>>> change_charset('deadbeef', string.hexdigits[0:16], '01')
'11011110101011011011111011101111'
>>> change_charset('11011110101011011011111011101111', '01', string.hexdigits[0:16])
'deadbeef'

python-utilitybelt's People

Contributors

shea256 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.