Skip to content

Instantly share code, notes, and snippets.

@EdwinTai
EdwinTai / 3d.py
Created September 15, 2020 06:51
python random number usage
import random
def _3d1():#方法一,直接顯示
return print(str(random.randint(0, 9)) + " " + str(random.randint(0, 9)) + " " + str(random.randint(0, 9)))
def _3d2():#方法二,一次抽一顆
result = list()
_3d_ticket = set()
while len(_3d_ticket) < 3:
number = random.randint(0,9)
_3d_ticket.add(number)
@EdwinTai
EdwinTai / 3dv2.py
Created September 16, 2020 17:29
3d use numpy && pandas
import numpy as np
import pandas as pd
samplesize = 100000
Probability = np.random.choice([0,1,2,3,4,5,6,7,8,9], size=samplesize, p=[0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1])
valueCount = pd.Series(Probability).value_counts()
print(valueCount/samplesize)
@EdwinTai
EdwinTai / sharenting.py
Created October 8, 2020 03:14
sharenting date utility demo
from datetime import date
from dateutil.relativedelta import relativedelta
today = date.today()
#寶貝1號
baby1 = date(2018, 3, 21)
diff1 = relativedelta(today, baby1)
print("%dY %dM %dD" % (diff1.years, diff1.months, diff1.days))
#寶貝2號
baby2 = date(2016, 5, 20)
diff2 = relativedelta(today, baby2)
# -*- coding: utf-8 -*-
#參考https://blog.csdn.net/handsomekang/article/details/9397025
#當資料庫中文字長度限制判斷時需要特別注意,要配合資料庫datatype
#許功蓋 大五碼
print(len(u"測試".encode("utf-8")))#一個中文長度3
print(len(u"測試".encode("Big5")))#一個中文長度2
print(len(u"測試"))#unicode
#計算機
print(3+2)
print(3-2)
#整數
print(8888)
#二進位0b
print(0b001)
print(0b010)
print(0b011)
#八進位0o
print(0o010)
print(0o011)
#十六進位0x
import math
#真值表 and 只有TT才是True
print(True & True)
print(True & False)
print(False & True)
print(False & False)
#真值表 or 有T就是True
print(True | True)
print(True | False)
print(False | True)
@EdwinTai
EdwinTai / rankdeom.html
Created November 6, 2020 06:44
for jQuery order by rank use
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=<device-width>, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table border="2" bordercolor="black">
<tr>
@EdwinTai
EdwinTai / thsrtb.py
Created November 19, 2020 02:07
Taiwan high speed rail timetable
# -*- coding: UTF-8 -*-
#取得高鐵站名
import requests
import bs4
url = 'https://www.thsrc.com.tw'
htmlfile = requests.get(url)
htmlfile.encoding = 'utf-8'
objSoup = bs4.BeautifulSoup(htmlfile.text, 'lxml')
stations = objSoup.find('select', id='select_location01').find_all('option')
for station in stations:
@EdwinTai
EdwinTai / ascii_art.py
Created November 25, 2020 16:33
hands on from csdn
#https://blog.csdn.net/u014636245/article/details/83661559
#pip install opencv-python (cv2) matplotlib numpy
#先定义颜色和对应的16进制值
based = range(0,16)
based_palette = [
"%02x" %l #转为16进制
for l in based
]
colored = [0] + [0x5f + 40 * n for n in range(0, 5)] #array combined [0, 95, 135, 175, 215, 255]
@EdwinTai
EdwinTai / iplocation.html
Created December 2, 2020 18:32
check ip location
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ip location</title>
<script src="https://pv.sohu.com/cityjson"></script>
<script>document.write(returnCitySN["cip"]+"."+returnCitySN["cname"])</script>
</head>
<body>