Skip to content

Instantly share code, notes, and snippets.

View PttCodingMan's full-sized avatar
🏠
正在支援下一代 PTT API

CodingMan PttCodingMan

🏠
正在支援下一代 PTT API
View GitHub Profile
import multiprocessing
import threading
import time
class ServerConsole:
def __init__(self):
self.msg_queue = multiprocessing.Queue()
self.console_process = threading.Thread(target=self.console, args=(self.msg_queue,))
@PttCodingMan
PttCodingMan / test.py
Created November 10, 2023 08:53
反數列使用 binary search
import bisect
from typing import List
def reversePairs(nums: List[int]) -> int:
q = []
res = 0
for v in nums:
i = bisect.bisect_left(q, -v)
res += i
module = None
try:
if module is None:
module = importlib.import_module(f'module_folder.module')
else:
module = importlib.reload(module)
except Exception as e:
raise e
@PttCodingMan
PttCodingMan / server_util.py
Created August 12, 2023 14:42
the server utils of Rock Minecraft server
import datetime
import os
import time
from argparse import ArgumentParser
from typing import List
def send_server_command(command) -> None:
os.system(f'screen -S rock-server -p 0 -X eval \'stuff "{command}"\\015\'')
name: deploy-blog
on:
schedule:
- cron: '22 22 * * *'
push:
branches:
- publish
paths:
- 'source/**/*.md'
import logging
import re
from queue import PriorityQueue
from sentence_transformers import SentenceTransformer, util
from sklearn.metrics.pairwise import cosine_similarity
from post_walker import post_walker
logging.basicConfig(
@PttCodingMan
PttCodingMan / check_network_status.py
Last active May 30, 2023 03:06
check network status
import logging
import threading
import time
import subprocess
import platform
def ping_ip(ip_address, results):
"""
檢查 IP 是否可連線,如果可連線則將結果寫入 results 變數中。
@PttCodingMan
PttCodingMan / example.c
Last active February 10, 2023 09:19
C language function example to avoid memory leak using goto.
int func(....){
// declare variable here
// check input here
if(pointer == NULL) goto end;
if(!run_condition) goto end;
// do something
@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)