This file contains 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
# |- <套件包名稱> | |
# |- core.py | |
from typing import List | |
def sum_array(arr: List[int]) -> int: | |
"""陣列總和器 | |
Args: | |
arr (List[int]): 整數陣列元素 |
This file contains 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 try_except_finally_example(): | |
try: | |
num1 = int(input("請輸入一個整數: ")) | |
num2 = int(input("請輸入另一個整數: ")) | |
result = num1 / num2 | |
except ZeroDivisionError: | |
print("錯誤:除以零。") | |
except ValueError: | |
print("錯誤:輸入的不是整數。") | |
finally: |
This file contains 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 try_except_else_example(): | |
try: | |
num1 = int(input("請輸入一個整數: ")) | |
num2 = int(input("請輸入另一個整數: ")) | |
result = num1 / num2 | |
except ZeroDivisionError: | |
print("錯誤:除以零。") | |
except ValueError: | |
print("錯誤:輸入的不是整數。") | |
else: |
This file contains 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 raise_example(num: int): | |
try: | |
if num <= 10: | |
raise ValueError(f"{num} 必須大於10") | |
except ValueError as e: | |
print(e) | |
raise | |
raise_example(9) |
This file contains 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 io | |
from typing import BinaryIO, Tuple, Union | |
import numpy as np | |
from pydub.utils import get_array_type | |
def decode_audio( | |
input_file: Union[str, BinaryIO], | |
sampling_rate: int = 16000, | |
) -> Tuple[np.ndarray, np.ndarray]: |
This file contains 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
func retry(maxRetryCount int, retryPeriod int, job func() error) error { | |
for retryCount := 1; ; retryCount++ { | |
err := job() | |
if err == nil { | |
return nil | |
} | |
// 進入retry模式 | |
if retryCount <= maxRetryCount { | |
glog.Errorf("error: %s, retry: %d, max: %d, wait: %ds", err, retryCount, maxRetryCount, retryPeriod) | |
time.Sleep(time.Second * time.Duration(retryPeriod)) |
This file contains 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
# -*- coding: UTF-8 -*- | |
import numpy as np | |
import os | |
import codecs | |
# shared global variables to be imported from model also | |
UNK = "$UNK$" | |
NUM = "$NUM$" | |
NONE = "O" |
This file contains 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
<?php | |
$options = array( | |
1 => 'Opt1', | |
2 => 'Opt2', | |
3 => 'Opt3', | |
); | |
?> |
This file contains 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
const portAudio = require('naudiodon'); | |
const fs = require('fs'); | |
const wav = require('wav'); | |
const request = require('request'); | |
const ai = new portAudio.AudioInput({ | |
channelCount: 1, | |
sampleFormat: portAudio.SampleFormat16Bit, | |
sampleRate: 8000, |
NewerOlder