This file contains 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. |
This file contains 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 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 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 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
# A context manager to shut down stdout | |
# Within this context, sys.stdout will be written into devnull. | |
# so, effectively it's muted. | |
@contextlib.contextmanager | |
def shut_stdout(): | |
sys.stdout = open(os.devnull, 'w') | |
yield | |
sys.stdout = sys.__stdout__ |
This file contains 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
# Clone the repo, depth=1 means only last 1 commit | |
git clone --depth=1 git://urloftherepo | |
# Remove the .git directory recursively | |
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs rm -rf |
This file contains 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 is_ascii(s): | |
return all(ord(c) < 128 for c in s) | |
This file contains 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
-- EU is identified by the country code list: https://dev.maxmind.com/geoip/legacy/codes/eu_country_list/ | |
( | |
--"country code","country name" | |
'EU', --"Europe" | |
'AD', --"Andorra" | |
'AL', --"Albania" | |
'AT', --"Austria" | |
'BA', --"Bosnia and Herzegovina" | |
'BE', --"Belgium" | |
'BG', --"Bulgaria" |
This file contains 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
# Get rid of `UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.` | |
pip uninstall psycopg2 -y | |
pip install --no-binary :all: psycopg2 | |
# On Mac, you will most likely run into issue with ' ld: library not found for -lssl’. Then you will need to run `brew install openssl` and `export LIBRARY_PATH=/usr/local/Cellar/openssl/1.0.2o_1/lib`. Finally, run `pip install --no-binary :all: psycopg2` |
This file contains 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
# Install mongodb | |
brew update | |
brew install mongodb | |
mkdir -p /data/db | |
sudo chown -R `id -un` /data/db | |
# Get a sample databaes | |
wget http://media.mongodb.org/zips.json | |
mongoimport -v --file=zips.json #loads into test.zips | |
# if you want to specify a database and collection |
OlderNewer