Skip to content

Instantly share code, notes, and snippets.

View turing4ever's full-sized avatar

Yi Wang turing4ever

View GitHub Profile
@turing4ever
turing4ever / Tidy_up_json_in_vim
Created February 22, 2018 00:02
Run json.tool in vim to clean up json formating
:%!python -m json.tool
@turing4ever
turing4ever / string_length.sh
Created February 5, 2018 23:24
How to figure out the length of a string in bash?
# 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
@turing4ever
turing4ever / unicode_to_ascii.py
Created February 5, 2018 17:37
Convert unicode into ascii recursively in nested object
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
@turing4ever
turing4ever / gist.py
Last active February 5, 2018 16:47
Hello World
Testing gist.