使用OpenAI ChatGPT 進行了編碼嘗試
ChatGPT 是一種以類似聊天的方式進行互動的人工智慧網路,從名字上看起來像是另一個“聊天機器人”,但實際上已經遠超聊天的範疇了,當要求它編寫一些程式碼時,結果相等震撼,它可以寫出一些意想不到的連貫程式碼,而這些程式碼對於開發者很有啟發。
開始要求它使用 JavaScript 編寫一個雜湊(HASH)密碼的函式。具體一點就是編寫一個 JavaScript 函式,它接受密碼的字串輸入並輸出雜湊(HASH)密碼。
function hashPassword(password) {
return crypto.createHash("sha256").update(password).digest("hex");
}
然後逐步提高編碼的難度,實現一些更加符合專案開發的需求,於是輸入:
編寫一個在請求正文中包含使用者名稱和密碼的 Express 路由處理程式,對密碼進行雜湊處理,在 MySQL 資料庫中查詢現有使用者並檢查雜湊後的密碼是否匹配。
``` const express = require("express"); const bcrypt = require("bcrypt"); const mysql = require("mysql");
// 建立 MySQL 資料庫連線 const db = mysql.createConnection({ host: "localhost", user: "root", password: "", database: "mydb", });
// 連線資料庫 db.connect((err) => { if (err) { throw err; } console.log("MySQL connected..."); });
// 建立 express app const app = express();
// 路由 handler app.post("/login", (req, res) => { // get username and password from request body const { username, password } = req.body;
// HASH 密碼
const hashedPassword = bcrypt.hashSync(password, 10);
// 在資料庫中查詢使用者名稱稱
let sql = `SELECT * FROM users WHERE username = '${username}'`;
let query = db.query(sql, (err, result) => {
if (err) throw err;
// 檢查密碼是否匹配
if (bcrypt.compareSync(result[0].password, hashedPassword)) {
res.send("Login successful!");
} else {
res.send("Incorrect username or password");
}
});
}); ```
這段 JavaScript 程式碼基本是沒什麼問題的,可以直接複製到專案中進行除錯。接下來使用別的語言來試一下:
用C語言編寫一個連結串列結構的程式碼,具有根據“標識”屬性在連結串列中新增、刪除和查詢節點的功能。
```
include
include
// Structure for a node in the linked list typedef struct Node { int identity; // Property of the node struct Node next; // Pointer to the next node } Node; // Function to add a node to the linked list void addNode(Node head, int identity) { // Create a new node Node newNode = (Node)malloc(sizeof(Node)); // Set the identity of the new node newNode->identity = identity; // Set the next pointer of the new node to point to the head newNode->next = head; // Set the head to point to the new node head = newNode; } // Function to delete a node from the linked list void deleteNode(Node head, int identity) { // Create a temporary node to traverse the linked list Node temp = head; // Check if the head is the node to be deleted if (temp != NULL && temp->identity == identity) { // Set the head to point to the next node head = temp->next; // Free the memory allocated for the node free(temp); return; } // Traverse the linked list to find the node to be deleted while (temp != NULL && temp->identity != identity) { // Set the previous node to the current node Node prev = temp; // Set the current node to the next node temp = temp->next; } // Check if the node was found if (temp == NULL) return; // Set the previous node to point to the next node prev->next = temp->next; // Free the memory allocated for the node free(temp); } // Function to find a node in the linked list Node findNode(Node head, int identity) { // Create a temporary node to traverse the linked list Node temp = head; // Traverse the linked list to find the node while (temp != NULL) { // Check if the current node has the given identity if (temp->identity == identity) { return temp; } // Set the current node to the next node temp = temp->next; } // Return NULL if the node was not found return NULL; } int main() { // Create a head node for the linked list Node head = NULL; // Add some nodes to the linked list addNode(&head, 1); addNode(&head, 2); addNode(&head, 3); // Find a node in the linked list Node node = findNode(head, 2); // Print the identity of the node printf("Node with identity 2: %d\n", node->identity); // Delete a node from the linked list deleteNode(&head, 2); // Find the deleted node in the linked list node = findNode(head, 2); // Check if the node was deleted if (node == NULL) { printf("Node with identity 2 was deleted\n"); } return 0; } ```
於是似乎開始擔心未來的程式設計師,對於AI的機器學習能力,肯定是強於人類的。一個程式設計師寶貴的職業生涯就算 20 年,就假設這個程式設計師在職業生涯中相當勤奮好學,可AI應該可以通過學習收集全世界所有程式設計師的經驗!人腦無法與在極其龐大的資料集上訓練有素的 AI 模型的計算能力相提並論。未來是不是有可能程式設計師通過AI把自己這個職業淘汰掉!
本文正在參加「金石計劃 . 瓜分6萬現金大獎」 ”
- Neo4J 快速入門
- 使用 ChatGPT 輕鬆建立使用者註冊頁面
- 5 個 JavaScript 程式碼優化技巧
- 複習前端:前端應掌握的網路知識
- JSON.stringify() 的 5 使用場景
- WEB開發人員應該知道 10 個 Docker 命令
- 8 個很酷的 GitHub 技巧
- 使用OpenAI ChatGPT 進行了編碼嘗試
- 元宇宙(Metaverse)的 7 層結構
- 分享 7 個不錯的人工智慧(AI)工具
- 藉助免費AI藝術平臺生成頭像
- 分享7 個VUE專案用得上的JavaScript庫
- 如何在 Solidity 中為 Web3 遊戲開發錦標賽排行榜
- Web 實時通訊技術WebRTC
- Web3 中最佳 AI 藝術工具
- 從 async 和 await 函式返回值說原理
- 推薦 6 個實用的 Vue 元件庫
- 使用 PixCap 和 ReadyPlayerMe 快速製作3D 模型動畫
- 生成二維碼或條形碼JavaScript指令碼庫
- 區塊鏈開發:如何從 Solidity 智慧合約中傳送和取款