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 characters
| :%!python -m json.tool |
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 characters
| # How to figure out the length of a strign in bash? | |
| #expr length | |
| expr length "string" #This works on Ubuntu, but not on Mac | |
| #wc -c | |
| echo -n "string" | wc -c # -n not to output trailing newline in echo |
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 characters
| def unicode_to_ascii(data): | |
| """"Convert all unicode string into ascii string""" | |
| if isinstance(data, basestring): | |
| return str(data) | |
| elif isinstance(data, collections.Mapping): | |
| return dict(map(unicode_to_ascii, data.iteritems())) | |
| elif isinstance(data, collections.Iterable): | |
| return type(data)(map(unicode_to_ascii, data)) | |
| else: | |
| return data |
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 characters
| Testing gist. |
NewerOlder