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
import click | |
all_colors = 'black', 'red', 'green', 'yellow', 'blue', 'magenta', \ | |
'cyan', 'white', 'bright_black', 'bright_red', \ | |
'bright_green', 'bright_yellow', 'bright_blue', \ | |
'bright_magenta', 'bright_cyan', 'bright_white' | |
@click.command() |
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
cat new.txt | xargs -I{} sh -c 'printf {}; curl -s -o /dev/null -w " %{http_code}\n" {};' | grep -v 200 |
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
# if e is immutable | |
[e] * n | |
# [e] is mutable | |
list_of_list = [[e] for _ in range(n)] | |
# if you do [e] * n, you will get n references to the same [e] | |
foo = [[]] *4 | |
foo[0].append('x') | |
[['x'], ['x'], ['x'], ['x']] |
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
$ ipython profile create | |
$ vi ~/.ipython/profile_default/ipython_config.py | |
c.InteractiveShellApp.extensions = [] to c.InteractiveShellApp.extensions = ['autoreload'] | |
c.InteractiveShellApp.exec_lines = [] to c.InteractiveShellApp.exec_lines = ['%load_ext autoreload', '%autoreload 2'] |
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 |
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
-- 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
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
# 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
# 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__ |
NewerOlder