Skip to content

Instantly share code, notes, and snippets.

View PttCodingMan's full-sized avatar
🎯
Seeking new job

CodingMan PttCodingMan

🎯
Seeking new job
View GitHub Profile
@PttCodingMan
PttCodingMan / remove.py
Created August 2, 2022 10:03
移除所有標點符號
re.sub(r'[^\w\s]', '', c)
from linebot import LineBotApi
line_uuid = 'qq'
line_bot_api = LineBotApi('qq_token')
line_bot_api.push_message(
line_uuid,
TextSendMessage(text='晚安,早點睡'))
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
if (length := len(nums)) < 3:
return []
result_map = {}
result = []
targets = []
for i in range(length):
def permutations(data, start_index, end_index):
if start_index == end_index:
print(data)
return
for i in range(start_index, end_index):
data[i], data[start_index] = data[start_index], data[i]
permutations(data, start_index + 1, end_index)
data[i], data[start_index] = data[start_index], data[i]
@PttCodingMan
PttCodingMan / init.sh
Last active June 21, 2021 06:05
init Minecraft server in debian or ubuntu
# set your java installer here, must with tar.gz
java_installer=https://cdn.azul.com/zulu/bin/zulu16.30.15-ca-jre16.0.1-linux_x64.tar.gz
installer_name_full="$(basename -- $java_installer)"
installer_name="${installer_name_full%.*}"
installer_name="${installer_name%.*}"
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get -y install git
@PttCodingMan
PttCodingMan / no_bug.py
Created April 30, 2021 13:09
Bless the code is no bugs
# ____________
# | |
# | |
# | |
# | |
# | |
# | |
# | |
# _____________________| |_____________________
# | |
@PttCodingMan
PttCodingMan / run_cmd.py
Last active March 29, 2021 07:02
Run command in Python 3 and get the execute result
import subprocess
import locale
def run_cmd(cmd, use_cmd=False):
if use_cmd:
# windows
cmd = ['cmd', '/c'] + cmd
# Linux
cmd = ['/bin/sh', '-c'] + cmd
result = subprocess.run(cmd, stdout=subprocess.PIPE)
@PttCodingMan
PttCodingMan / walk.py
Created November 10, 2020 03:40
List all files in the folder in Python 3, recursion is an option
import os
if __name__ == '__main__':
def walk_dir(current_path, recursive=True):
result = []
for (parent_path, folder_names, file_names) in os.walk(current_path):
# I don't like -> \ <-
parent_path = parent_path.replace('\\', '/')
if not recursive:
def quick_sort(data: list[int]) -> list[int]:
if (length := len(data)) <= 1:
return data
pivot = data.pop(length // 2)
smaller_list = [i for i in data if i < pivot]
bigger_list = [i for i in data if i >= pivot]
return quick_sort(smaller_list) + [pivot] + quick_sort(bigger_list)