Skip to content

Instantly share code, notes, and snippets.

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
)
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)
#### 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)

Execute IPython always by current virtualenv

cd ~/some_project_path/
source .venv/bin/activate
pid install ipython

alias ipy="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
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(
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
from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
similar('abc', 'abc')
@Shih-Po
Shih-Po / minimal_selenium.py
Last active July 24, 2017 07:09
minimal-pieces
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