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 socket | |
| from binascii import hexlify | |
| def convert_ip4_address(): | |
| for ip_addr in ['127.0.0.1', '192.168.0.1']: | |
| packed_ip_addr = socket.inet_aton(ip_addr) #將IP轉換為32位元二進制格式 | |
| unpacked_ip_addr = socket.inet_ntoa(packed_ip_addr) #將32位元二進制格式轉換為IPv4 | |
| print ("IP Address: %s => Packed: %s, Unpacked: %s" %(ip_addr, hexlify(packed_ip_addr), unpacked_ip_addr)) #hexlify(packed_ip_addr)轉換二進製成十六進制 | |
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 sys | |
| import socket | |
| import argparse | |
| def main(): | |
| # setup argument parsing | |
| parser = argparse.ArgumentParser(description='Socket Error Examples') | |
| parser.add_argument('--host', action="store", dest="host", required=False) #從CMD取的參數,儲存在"host" | |
| parser.add_argument('--port', action="store", dest="port", type=int, required=False) |
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 RPi.GPIO as gpio | |
| class IC7447(): | |
| def __init__(self,A,B,C,D): | |
| self.A = A # mapping to 7447 input A - D | |
| self.B = B | |
| self.C = C | |
| self.D = D | |
| gpio.setup(self.A,gpio.OUT) | |
| gpio.setup(self.B,gpio.OUT) |
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 RPi.GPIO as gpio | |
| class IC74595(): | |
| def __init__(self,DS,STCP,SHCP): | |
| self.DS = DS | |
| self.STCP = STCP | |
| self.SHCP = SHCP | |
| gpio.setup(self.DS, gpio.OUT) | |
| gpio.setup(self.SHCP, gpio.OUT) | |
| gpio.setup(self.STCP, gpio.OUT) |
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
| REQUIRE_FILE_LIST = '%__REQUIRE_FILE_LIST%' #require file list | |
| END_CONNECT = '%__END_CONNECT%' #結束連線 | |
| SET_SEARCH_TYPE = '%__SET_SEARCH_TYPE%' #[1]搜尋檔案 [2]搜尋資料夾 | |
| SET_PATTERN_KEY = '%__SET_PATTERN_KEY%' #搜尋條件 | |
| SEARCH_TARGET = '%__SEARCH_TARGET%' #開始搜尋目標 | |
| SELECT_TARGETS = '%__SELECT_TARGETS%' #選擇目標 | |
| SET_MAIL_RECVER = '%__SET_MAIL_RECVER%' #郵件寄送對象 | |
| SET_SEARCH_ROOT_PATH = '%__SET_SEARCH_ROOT_PATH%' #設定搜尋根目錄 | |
| class ClientManager(object): |
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 smtplib | |
| import yaml | |
| from email.mime.text import MIMEText | |
| from email.mime.multipart import MIMEMultipart | |
| from email.mime.application import MIMEApplication | |
| from os.path import basename | |
| def sendMail(send_from: str, subject: str, text: str, send_to: list, files= None): | |
| msg = MIMEMultipart() |
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 __searchTarget(self): | |
| path = self.searchPath | |
| files = [] | |
| searchType = self.searchType | |
| searchStr = self.patternKey | |
| # r=root, d=directories, f = files | |
| for r, d, f in os.walk(path): | |
| searchTarget = 0 | |
| if(searchType == 1): | |
| searchTarget = f |
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
| # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to | |
| # newer versions of the distribution. | |
| deb http://free.nchc.org.tw/ubuntu/ xenial main restricted | |
| # deb-src http://free.nchc.org.tw/ubuntu/ xenial main restricted | |
| ## Major bug fix updates produced after the final release of the | |
| ## distribution. | |
| deb http://free.nchc.org.tw/ubuntu/ xenial-updates main restricted | |
| # deb-src http://free.nchc.org.tw/ubuntu/ xenial-updates main restricted |
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
| """ | |
| pytorch CrossEntropyLoss 用法 | |
| """ | |
| import torch | |
| import torch.nn as nn | |
| import math | |
| loss = nn.CrossEntropyLoss() | |
| input = torch.randn(1, 5, requires_grad=True) | |
| target = torch.empty(1, dtype=torch.long).random_(5) | |
| output = loss(input, target) |
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 gensim.models.doc2vec import Doc2Vec, TaggedDocument | |
| import csv | |
| import jieba | |
| # jieba初始化 | |
| jieba.set_dictionary('dict/dict.txt.big') | |
| jieba.load_userdict('dict/my_dict') | |
| jieba.initialize() | |
| # 讀入waimai_10k_tw.csv,並且使用jieba斷詞 |