cd ~/some_project_path/
source .venv/bin/activate
pid install ipython
alias ipy="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
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
| import os | |
| import sys | |
| CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.append(CURRENT_PATH) | |
| # then you can safely import everything in this module folder | |
| from current.path.module import ( | |
| function_you_need, varible_you_need | |
| ) |
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
| import requests | |
| from bs4 import BeautifulSoup | |
| def get_difinition(word): | |
| headers = { | |
| 'User-Agent': ('User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) ' | |
| 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36') | |
| } | |
| url = 'http://dictionary.cambridge.org/dictionary/english-chinese-traditional/{}'.format(word) | |
| res = requests.get(url, headers=headers) |
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
| #### Run app | |
| library(shiny) | |
| app_dir <- '~/Projects/shiny/yourapp/' | |
| setwd(app_dir) | |
| options(shiny.fullstacktrace=TRUE) | |
| options(shiny.error=browser) | |
| runApp(appDir=app_dir) | |
| #### Deploy app | |
| library(shiny) |
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
| from datetime import datetime, timedelta | |
| def get_last_month_datetime(now): | |
| return now.replace(day=1) - timedelta(days=1) | |
| now = datetime.now() | |
| last_month_datetime = get_last_month_datetime(now) | |
| print(last_month_datetime) | |
| before_last_month_datetime = get_last_month_datetime( |
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 save_excel_with_proper_width(output_excel_path, | |
| sheet_name, | |
| df): | |
| writer = pd.ExcelWriter(output_excel_path) | |
| df.to_excel(writer, sheet_name=sheet_name, index=False) | |
| work_sheet = writer.sheets[sheet_name] | |
| def proper_cht_len(col_name): | |
| import re |
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
| from difflib import SequenceMatcher | |
| def similar(a, b): | |
| return SequenceMatcher(None, a, b).ratio() | |
| similar('abc', 'abc') |
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
| from selenium import webdriver | |
| DRIVER_PATH = './drivers/chromedriver' | |
| br = webdriver.Chrome(DRIVER_PATH) | |
| url = ('https://www.amazon.com/Economist-Guide-Economic-Indicators-Economics/product-reviews' | |
| '/0471248371/ref=cm_cr_arp_d_show_all?ie=UTF8&reviewerType=all_reviews&sortBy=recent&pageNumber=1') | |
| br.get(url) | |
| res_text = br.page_source |