Home
JE Sharing
Cancel
Preview Image

.h vs .hpp (English)

.h vs .hpp In a project, you often see files with .h and .hpp extensions. What is the difference between them? .hpp and .h files are essentially the same .hpp and .h files serve the same funda...

Preview Image

Item 8 (2/2)- Enhanced support for multithreading(English)

Inter-thread Communication std::condition_variable is used for communication between threads, allowing one thread to wait for a notification from another thread. Multithreading #include <iost...

Preview Image

Item 8 (2/2)- 多線程支持的增強(中文)

線程間的通信 std::condition_variable 用於線程間的通信,允許一個線程等待另一個線程發送的通知。 多執行序 #include <iostream> #include <thread> #include <mutex> #include <condition_variable> std::mutex mtx; std...

Preview Image

Item 8(1/2) - 多線程支持的增強(中文)

多執行序 在 C++11 之前,C++ 並沒有標準化的多線程支持,因此需要依賴於平台特定的庫來實現多線程。 簡單來說,就是很麻煩。無法達到跨平台的效果, 例如: 在 Windows 上可以使用 WinAPI, 必須包含 <windows.h> 標頭檔,不需要額外安裝庫但僅適用於 Windows 系統。 而在 POSIX 系統(如 Linux 和 macOS)上則可以使用 ...

Preview Image

Item 8(1/2) - Enhanced Multithreading Support(English)

Multithreading in C++ Before C++11, C++ did not have standardized support for multithreading, which meant developers had to rely on platform-specific libraries to implement multithreading. This ap...

Preview Image

Item 29 - 三向比較運算符 <=> (中文)

三向比較運算符 當我們在寫自己的 struct or class 時,有時候要去該物件的比較, 也就是 &lt;, &lt;=, ==, !=, &gt;=, &gt; 這些 operator。 但寫過的人就知道,上述 6 個 operator 都要去寫非常麻煩。 而且還很容易錯誤。 C++20 引入了三向比較運算符(spaceship operator, &lt;=&gt;),它是一個...

Preview Image

Item 29 - Three-way Comparison Operator <=> (English)

Three-way Comparison Operator When writing your own struct or class, sometimes you need to compare objects, which involves implementing operators like &lt;, &lt;=, ==, !=, &gt;=, and &gt;. Impleme...

Preview Image

c++ 委派 delegate (中文)

Delegate 在 C++ 中實現 delegate(委派)功能,通常可以使用函數對象、std::function 以及 std::bind 來達成。這可以讓你把對某個函數的調用委派給另一個對象或函數。 以下是一個簡單的範例,展示如何使用這些工具來實現類似 delegate 的行為。 使用函數指針 #include &lt;iostream&gt; // 函數指針類型 typed...

Preview Image

c++ algorithm (中文)

algorithm C++ 中的 標頭檔提供了許多常用的演算法,用於處理各種容器和範圍內的數據。 這些演算法涵蓋了排序、搜索、修改和數據處理等操作。標準函示庫都幫你寫了,就用吧! 不要花時間重造輪子了 以下是一些常用的 12 個函數和它們的簡要介紹! std::sort : 用於對範圍內的元素進行排序 #include &lt;algorithm&gt; #include &lt;...

Preview Image

FastAPI + Front-End + Database Integration(English)

FastAPI + Front-End + Database Integration We are going to complete the following integration Due to the length of the front-end and back-end code, I’ll first discuss the issues encountered to ...

Preview Image

fastapi + 前端 + 資料庫串接(中文)

fastapi + 前端 + 資料庫串接 我們接下來要完成以下的串接 由於這次前後端的 code 比較長,這邊先講遇到的問題, 避免看完 code 後,暈頭轉向。 錯誤訊息 fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that class 'item_to_db.Ite...

Preview Image

Fastapi (5) CORS (English)

CORS(Cross-Origin Resource Sharing) CORS (Cross-Origin Resource Sharing) is a browser security feature that restricts how web scripts can interact with server resources from different domains. If ...

Preview Image

Fastapi (5) CORS (中文)

CORS(Cross-Origin Resource Sharing) CORS 是一種瀏覽器安全特性,用於限制來自不同域的網頁腳本如何與伺服器資源進行互動。 如果你在構建一個前後端分離的應用,前端和後端位於不同的域(或端口),你就需要配置 CORS。 為什麼? 簡單來講,如果不限制請求的來源,那只要知道 url 的不明來源都可以發請求,而且伺服器還很聽話的把資料傳給對方,如果涉及敏感資...

Preview Image

Item 24 - Range (English)

Ranges in C++20 C# has Linq, and Python has built-in functions like filter and map for quickly filtering elements that meet specific conditions from a collection. What about C++? Do you have to lo...

Preview Image

Item 24 - Range (中文)

Range C# 有 Linq,Python 有 filter 和 map 等內建函式,可以快速從一個集合中,篩選出符合特定條件的元素。 那 C++ 呢 ? 只能自己 Loop 容器一遍,然後慢慢找出自己需要的部分 ? No ! C++20 header &lt;ranges&gt; 提供許多方便的函式,可以幫我們去完成這個情形。 code 以下示範一個簡單的例子,從一堆數字中, 找出...

Preview Image

Docker 上使用 Nginx(中文)

What is Nginx Nginx(發音為 “engine-x”)是一個高性能的HTTP和反向代理服務器, 個人最喜歡功能強大的工具,然後檔案 size 還很小。 Nginx 以其高性能和低資源消耗著稱,並在高並發連接處理方面表現出色。它常被用來作為負載均衡器、反向代理、HTTP快取以及靜態文件伺服器。 應用場景 靜態資源服務:用於提供靜態文件(如圖片、CSS、JavaS...

Preview Image

Pyinstaller Packaged Application Execution Location in MacOS(English)

Application Execution Location When we use PyInstaller to package our Python program into an executable, the behavior for reading and writing files can differ between Windows and macOS. As shown i...

Preview Image

Pyinstaller 打包後執行檔位置 in MacOS(中文)

應用程式執行位置 當我們使用 pyinstaller 將我們的 python 程式打包成執行檔後,如果牽涉到讀寫檔的程式,Windows 和 MacOS 的執行狀況會不太一樣,如下圖,我們有個執行檔和一個檔案。 執行檔只是一個簡單的讀檔程式 with open("myfile.txt", "a", encoding="utf-8") as file: file.write(...

Preview Image

Item 21 - aggregate classes (中文)

聚合類 聚合類(aggregate classes)是一種特殊類型的類型,主要特徵是其成員可以直接使用大括號初始化器進行初始化 來看以下的例子吧 struct Point { int x; int y; }; Point p{50,100}; 上述這個簡單的 struct, 可以直接使用大括號進行初始化 Point p{50,100}; 在 C++17 之前...

Preview Image

Item 21 - Aggregate Classes (English)

Aggregate Classes Aggregate classes are a special type of class characterized by their members being directly initialized using brace initializers. Let’s take a look at the following example: st...

Preview Image

SQLAlchemy 欄位變動(中文)

Alembic Alembic 是一個輕量級的資料庫遷移工具,它專門為 SQLAlchemy 設計,用來處理資料庫結構的變更(例如新增欄位、修改欄位類型、刪除欄位等)。它允許你在不丟失資料的情況下,管理和版本化資料庫的結構變更。 主要功能 版本控制:Alembic 使用版本號來跟蹤資料庫的結構變更。每次變更都會創建一個新的版本文件,包含升級和降級的指令。 ...

Preview Image

PyInstaller 打包 python App (中文)

PyInstaller python 有很多非常便利的地方和很強大的模組,因此很多人都會使用 python 寫些小工具。但是,如果寫完後,如果要給其他人用,那該怎麼辦? 在其他的電腦上裝 python ? 太麻煩了。pyinstaller 可以解決這樣的問題!! PyInstaller 是一個將 Python 應用程序打包成獨立可執行文件的工具。它支持 Windows、Linux 和 m...

Preview Image

PyInstaller packages python App (English)

PyInstaller Python offers a lot of convenience and powerful modules, which is why many people use Python to write small tools. But once you have written your tool, how do you share it with others?...

Preview Image

SQLAlchemy - Delete(中文)

Delete 刪除單個記錄 刪除 LBJ 吧,(我是詹黑無誤) user = session.query(NBA_Player).filter_by(name='LBJ').first() if user: session.delete(user) session.commit() # 提交刪除 批量刪除記錄 刪除所有 id 大於 3 的 player s...

Preview Image

openpyxl 讀寫 Excel(中文)

讀 Excel 的 python lib Excel 是大家常常拿來整理資料的工具,它非常的方便好用,這邊就不需贅述了。 但如何讀取 Excel 的資料去做更複雜的資料整理? openpyxl 和 pandas 都可以,以下針對做兩個模組的比較。 openpyxl vs pandas 功能 Openpyxl Pandas ...

Preview Image

openpyxl Read/Write Excel(English)

Python Libraries for Reading Excel Excel is a commonly used tool for organizing data due to its convenience and versatility. But how can we read Excel data for more complex data processing? openp...

Preview Image

SQLAlchemy - Update(中文)

Update 更新單個記錄 幫 LBJ 換個背號吧! user = session.query(NBA_Player).filter_by(name='LBJ').first() if user: user.number = 6 # 更新 number session.commit() # 提交更新 批量更新記錄 把大家的背號,都換成 Kobe 的背號吧...

Preview Image

SQLAlchemy - Read(中文)

Read 當我們把資料寫進去 DB 後,一定會遇到需要查詢的時候,不然寫進去要幹嘛? 以下有多種查詢的方式: 查詢所有紀錄 篩選條件查詢 查詢特定欄位 使用多重條件篩選 排序 限制結果數 聚合函數 其實還可以使用原生 SQL 查詢,但這邊就不提了,因為我們學 SQLAlchemy 的目的,就是能像操作物件一樣,簡單的去存取 DB. 查詢所有紀錄 我們多...

Preview Image

SQLAlchemy - Create(中文)

Create 建立(Create): 建立新資料紀錄。 這個操作通常是將新資料插入資料庫中的一個表格。 SQL 中的 INSERT 語句即為這類操作的典型例子。 範例:INSERT INTO users (name, email) VALUES (‘John Doe’, ‘john@example.com’); 定義 Model 我們來定義一個 class NBA_Player, 裡...

Preview Image

SQLAlchemy Basic(中文)

基本語法 以下介紹使用 SQLAlchemy 連結資料庫的基本語法。 engine = create_engine('postgresql://myuser:mypassword@172.17.0.3:5432/mydatabase', echo=True) Base = declarative_base() Base.metadata.create_all(engine) Ses...