Skip to content

Instantly share code, notes, and snippets.

View PttCodingMan's full-sized avatar
🎯
Building something new!

CodingMan PttCodingMan

🎯
Building something new!
View GitHub Profile
@PttCodingMan
PttCodingMan / convert.py
Created December 19, 2022 01:45
the convert between object and json using Python.
def obj2base64(obj):
# convert object to base64 string using json
return base64.b64encode(json.dumps(obj).encode('utf-8')).decode('utf-8')
def base642obj(s):
# convert base64 string to object using json
return json.loads(base64.b64decode(s).decode('utf-8'))
@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: