Skip to content

Instantly share code, notes, and snippets.

View turing4ever's full-sized avatar

Yi Wang turing4ever

View GitHub Profile
@turing4ever
turing4ever / autoreload.txt
Created July 10, 2018 16:14
Enable Auto reload in ipython
$ 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']
@turing4ever
turing4ever / gen_list_of_duplicate_items.py
Created August 19, 2018 05:18
Duplicate a list in python
# 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']]
@turing4ever
turing4ever / validate_url.sh
Created January 3, 2019 06:16
bash script that validates a list of URLs using curl
cat new.txt | xargs -I{} sh -c 'printf {}; curl -s -o /dev/null -w " %{http_code}\n" {};' | grep -v 200
@turing4ever
turing4ever / click_colors.py
Last active January 7, 2019 04:02
Use click to colorize cli output
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()