Skip to content

Commit

Permalink
README.md updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Smarties89 committed Apr 30, 2017
1 parent 3c82205 commit a04c987
Showing 1 changed file with 7 additions and 53 deletions.
60 changes: 7 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,12 @@
My Python Snippets

My Python Snippets is a collection of nice to have and missing batteries for Python.
The snippes are organised as a library, but is separated into individual files that can be included in projects together.
The snippes are organised as a library, but is separated into individual files that can be copy/pasted into projects.
Contributing is easy and welcomed!
The flow is generally

Documentation is on this one page.
1. Fork
2. Make some nice functionality
3. Make tests
4. Make a pull request


# Table of Contents

* [randstr](#randstr) - get a random string of numbers/characters
* [hdcache](#hdcache) - hdcache makes it easy to use the harddrive as a cache for function results
* [Contributors](#Contributors)



# randstr
randstr creates a random string of numbers and upper/lowercase characters.

```
>>> import mps
>>> mps.randstr()
'N5KZRC06'
>>> mps.randstr(nsize=100)
'5QRDHYESVHMNL68E0IPYEIP3TXBUU86V26PSIEZ4AWE1FAX3G2WCSJ38NAIHB9DM3ZCCI102AI6TAOC967XM3UW6ZH5X9S8OQR23'
>>>
```

# hdcache
hdcache makes it easy to use the harddrive as a cache for function results. An example below shows how to do it, and the result of calling the script twice is below that.

```#!/bin/python
from mps import hdcache
@hdcache("cachedresult")
def docomputation(x, y):
print("Doing hard computation for {} + {}".format(x, y))
return str(x+y)
result = docomputation(2, 3, cachekey="2 plus 3")
print("Result is {}".format(result))
```
This saves the docompuation on the cacheid of *2+3* in the file "cachedresult". The cachekey should be a unique string of the computation.

```
user@hostname:~$ python testhdcache.py
Doing hard computation for 2 + 3
Result is 5
user@hostname:~$ python testhdcache.py
Result is 5
user@hostname:~$
```


Contributors
==========

* smarties89

0 comments on commit a04c987

Please sign in to comment.