Skill

VSCode 安裝 SFTP/FTP sync 實現即時更新上傳

VSCode 安裝 SFTP 實現即時更新上傳

在多數付費IDE 都具備有 SFTP/FTP sync 更新即時上傳SFTP功能,實現本地開發遠端程式碼。

在這裡說明 VSCode 的擴充,如何達到本地開發遠地程式碼的流程設定。

Continue Reading

快速建立 Telegram Bot (入門)

這裡記錄如何快速建立一個 Telegram bot 以及透過 bot 發送訊息到群組。

Continue Reading

理解 程序(Process)、執行緒(Thread)、協程(Coroutine) 、生成器(yield) 差異

Process 是電腦中已執行 Program 的實體 每一個 Process 是互相獨立的 同一個 Process 中會有很多個 Thread ,每一個 Thread 負責某一項功能 同一個 Process 底下的 Thread 共享資源,如 記憶體、變數等

在多執行緒中(Multithreading),執行緒屬於同步機制,在同時間運行的執行緒,若兩個執行緒若同時存取或改變全域變數(Global Variable),則可能發生同步(Synchronization)問題。若執行緒之間互搶資源,則可能產生死結(Deadlock)

Coroutine的程式概念, 在1958年由Melvin Edward Conway提出, 是一種類似多執行緒的單執行緒程式概念, 且可以避開多執行緒的race condition問題, 因為他是單執行緒!!!, 所以不會有第二個執行緒來搶著操作.

Coroutine Coroutine 屬於非同步機制,在執行過程擁有自己的上下文,同時具有可暫時儲存上下文的機制,當一個 Coroutine 儲存後,執行完其他任務可在重新進入,並且從上一次執行的狀態繼續進行。這樣的功能讓程式可以達到分段執行。

同執行緒的比較 協程非常類似於執行緒。但是協程是協同運作式多工的,而執行緒典型是搶占式多工的。這意味著協程提供並行性而非並列性。協程超過執行緒的好處是它們可以用於硬性即時的語境(在協程之間的切換不需要涉及任何系統呼叫或任何阻塞呼叫),這裡不需要用來守衛關鍵區段的同步性原語(primitive)比如互斥鎖、號誌等,並且不需要來自作業系統的支援。有可能以一種對呼叫代碼透明的方式,使用搶占式排程的執行緒實現協程,但是會失去某些利益(特別是對硬性即時操作的適合性和相對廉價的相互之間切換)。

Yield Yield 又稱為生成器,也叫作「半協程」,屬於協程的子集。他跟 Coroutine 一樣,都可以分段執行,但兩者還是有差別。首先,Coroutine 可以控制接續執行另一個協成,過某一段時間再切回繼續跑。Yield 只能在呼叫時,被呼叫的對象控制,並且只能在該Yield ,無法跳到其他 Coroutine 。但事實並非這麼絕對,其實可透過一些dispatcher 的模式來透過上層以token等方式控制yield,在邏輯上達到切換到其他 Coroutine 。

Continue Reading

工廠模式 (Factory)

工廠模式 (Factory)

在 Design Pattern 中,工廠模式(Factory) 基本的理念是建構一套完整工廠鍊,可以用來生產各種類別品項。

例如,建構資料庫工廠,可以用來產生 mysql, mongodb, redis…. 等物件。

對於使用者而言,他只需要在初始化工廠時,指定要生產的是什麼,

後續在操作資料庫的行為,都會一致。

Continue Reading

建構者模式 (Builder)

建構者模式 (Builder)

建構者模式,主要透過條件堆疊取得產物。

每一個堆疊的步驟,都是一個 Builder,例如透過 set 的方式來傳入 Builder。

實際用途,可運用在設計資料庫查詢器的功能,例如,要查詢一個用戶,名字為 john

Continue Reading

什麼是繼承抽象 Abstract

Abstract 可以用來定義 Abstract 類、一般方法名稱及參數,Abstract 方法。

一般的方法可以實作邏輯。

如果是 Abstract 方法,則僅作描述,不實作邏輯。邏輯會保留到某個類別繼承(extends)時,來實作(強制)。

透過抽象,可以讓我們定義好規則以及實作一些方法,讓其他類別擴充時,可遵照規則實作,以及直接可使用這些方法。

Continue Reading

Guzzle PUT 傳輸參數方式說明

Guzzle PUT 數據方式說明

使用 Guzzle

使用 Guzzle 只能透過 POST 方式來傳遞 application/x-www-form-urlencoded form params

( 官方原文:form_params - Used to send an application/x-www-form-urlencoded POST request. )

若使用 PUT, DELTE 則需要改用 body 或者 json 格式傳輸,例如:

Continue Reading

介面 Interface

Interface

Interface 類別主要用於定義一些關鍵字及 public 的抽象方法,不需要定義方法的 body 及參數。

<?php
interface Logger{
    public function excute();
}

首先,針對未使用 Interface 的情況進行說明,

如果在大型專案只有使用 Class,例如以下範例,當我們要切換不同的 Log 方式時,就要透過手動方式在多處 constructor 處進行 hard-coded 變更,例如

<?php

class LogToDatabase {
    public function execute($message)
    {
        var_dump('log the message to a database :'.$message);
    }
}

class LogToFile {
    public function execute($message)
    {
        var_dump('log the message to a file :'.$message);
    }
}

class UsersController { 
    protected $logger;
    
    public function __construct(LogToFile $logger)
    {
        $this->logger = $logger;
    }
    
    public function show()
    { 
        $user = 'nahid';
        $this->logger->execute($user);
    }
}

$controller = new UsersController(new LogToFile);
$controller->show();

例如,目前在 UsersController 使用 LogToFile,

Continue Reading

Vue - VSCode 基本配置 ESLine & Prettier 代碼自動風格化

Vue - VSCode 基本配置 ESLine & Prettier 代碼自動風格化

這裡記錄 Vue 初始設定會用到的一些基本設定

包括語法亮潔以及代碼自動風格化設定.

另外會提到如何在 VSCode settings.json 設定儲存自動將語法進行整理,風格化

Continue Reading

總彙整 PHPStorm 快捷鍵(Mac, Linux, Mac)

總彙整 PHPStorm 快捷鍵(Mac, Linux, Mac)

Mac 符號

符號 解釋
Command
Shift
Control
Enter/Return
Option / Alt

Continue Reading

中國區域 Zoom 問題排解

在中国的 Zoom 软件安装后,会分别有国内及国外两种选项,在近期因中国国家安全政策,考量Zoom 软件对外沟通方面因为无法确定是谁对国外发起会议,因此进行屏蔽。针对这个变动,在第一时间进行处理,帮助排除问题的解决方式进行纪录

Q: 如何确保软件有更新?

请检查相关装置的 Zoom 版本有高于以下版本: Windows 软件: 5.0.41687.0910 Apple 软件: 5.0.41687.0910 苹果 APP Store: 4.5.2 安卓: 4.5.3

Q: 如何卸载 Zoom 软件?

可以点选 Windows > 控制面板 > 卸载程序 > 在软件滑鼠右键点击出现卸载弹窗 > 点击卸载

https://jingyan.baidu.com/article/5d368d1eb2270f3f60c057b0.html

Q: 去哪儿下载Zoom 软件?

首先,卸载本地的 Zoom 软件,前往官方下载最新软件。 下载安装 Zoom : https://www.zoomvip.cn/download.html

Q: 遇到 Zoom 无法进入会议时,怎么办?

(1) 请家长提供 Zoom 软件登入会议的画面。 (2) 使用的装置型号,在提供给技术判断。 (3) 询问家长是否有其他装置可以先进入会议。

Q: 学生无法听到学霸声音?

(1) 请家长提供 Zoom 软件登入会议的画面。 (2) 手机或平板请检查是否关到静音键。 (3) 桌机请开启扬声器设置,检查 Zoom 软件扬声器是否开启。 (4) 询问家长是否有其他装置可以先进入会议。

Continue Reading

解決 Mac - ERROR: No matching distribution found for MySQLdb

Mac - ERROR: No matching distribution found for MySQLdb

在 Mac 直接透過 brew 安裝 MySQLdb,會出現錯誤提示:No matching distribution found for MySQLdb

解決方式:

brew install mysql-connector-c  

pip install mysqlclient  

這時會出現錯誤,請前往

cd /usr/local/Cellar/mysql-connector-c/6.1.11/bin/  
cp  mysql_config mysql_config.bak #備份
chmod u+w mysql_config  
vi mysql_config  

將 114 行的 ```libs="$libs

接著再執行安裝就成功了

CVT2HUGO: -l "``` 改為 ```libs="$libs -lmysqlclient -lssl -lcrypto"```
pip install mysqlclient  

Continue Reading

Command line 快捷鍵

Command Editing Shortcuts Ctrl + a – go to the start of the command line Ctrl + e – go to the end of the command line Ctrl + k – delete from cursor to the end of the command line Ctrl + u – delete from cursor to the start of the command line Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word) Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor Ctrl + xx – move between start of command line and current cursor position (and back again) Alt + b – move backward one word (or go to start of word the cursor is currently on) Alt + f – move forward one word (or go to end of word the cursor is currently on) Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word) Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word) Alt + u – make uppercase from cursor to end of word Alt + l – make lowercase from cursor to end of word Alt + t – swap current word with previous Ctrl + f – move forward one character Ctrl + b – move backward one character Ctrl + d – delete character under the cursor Ctrl + h – delete character before the cursor Ctrl + t – swap character under cursor with the previous one Command Recall Shortcuts Ctrl + r – search the history backwards Ctrl + g – escape from history searching mode Ctrl + p – previous command in history (i.e. walk back through the command history) Ctrl + n – next command in history (i.e. walk forward through the command history) Alt + . – use the last word of the previous command Command Control Shortcuts Ctrl + l – clear the screen Ctrl + s – stops the output to the screen (for long running verbose command) Ctrl + q – allow output to the screen (if previously stopped using command above) Ctrl + c – terminate the command Ctrl + z – suspend/stop the command

Continue Reading

Vimeo / 403 Forbidden 解決方式

Vimeo / 403 Forbidden 解決方式

在過去學習系統的影片為了避免被濫用,緊急情況下採用了 Vimeo 上架我們的線上學習影片,好處是可以直接針對影片設定允許IP及網域。

但最近前線反應在 Vimeo 上傳影片後,無法從後台同步回來。

後台檢查發現有 403 的錯誤,描述如下:

Continue Reading

Composer git hooks

Composer git hooks

Composer Git Hooks 可以讓你直接在 composer 設定進行管理 git hooks,透過這樣管理的好處在於,能避免每個開發者都有各自的git hooks 設定,透過 composer git hooks 能將所有開發者的 git hooks 統一納入版控。

Continue Reading

parent 與 child 資料結構

公司新專案,在執行學習測驗完成後,需要跳出一個問券讓使用者填寫, 問券的架構必須要在選取特定選項後,再展開相關對應的題目, 大致示意如下:

Continue Reading

API Blueprint

API Blueprint

API Bluepirnt 是一個 API 描述語言,可以在開發 API 的過程,使用 markdown 方式快速彙整出 API 文件。

標準的 API Blueprint 是以 .apib 作為副檔名(media 類型為 text/vnd.apiblueprint),當拓展到 Github 上,會直接顯示對應的 Heightlight 。

Continue Reading

防駭,資料庫遭入侵勒索的安全應對機制

近期,公司營運多年的舊有專案,十幾套系統發生同時無法連線問題,查明原因發現資料庫被入侵,資料被清空,root密碼被更改,以及留下一個 PLEASE_READ_ME_MXG 資料表,內容如下:

WARNING
To recover your lost data : Send 0.05 BTC to our BitCoin Address and Contact us by eMail with your server IP Address or Domain Name and a Proof of Payment. Any eMail without your server IP Address or Domain Name and a Proof of Payment together will be ignored. Your File and DataBase is downloaded and backed up on our servers. If we dont receive your payment,we will delete your databases.

Bitcoint_Address
xxxxxxxxxxxxxxxxxxxxxxxxxx

Email
xxx@hello-database.xyz

在搜尋過相關類似攻擊 Your File and DataBase is downloaded and backed up on our servers 的真實性不高,事實上,在連線後資料就已經被刪除 ref

所以,如果你也遇到同樣遭遇,千萬別充值!

回歸到話題,關於系統資料庫由於每天都有做雲端備份,所以接下來要復原其實不是太大的問題。

慘痛之中,還是必須保持鎮定,掌握處理的步調

先開出任務清單,召集幾個 MIS 進行研擬狀況及對策,進行處理

Continue Reading

研發技術團隊如何訂立 KPI 指標及抉擇

研發技術團隊如何訂立 KPI 指標及抉擇

最近公司針對整體專案系統及KPI再進行整頓,因此被上級問到:研發部門團隊是否有適當的KPI指標可以作為參考?

針對這個問題,大致花了一點時間,整理了目前軟體管理的論述及自身想法:

公司經營靠 KPI 管理

公司組織,通常都會透過KPI來讓公司朝向成功事業的方向前進,而不是只單純看軟體開發的狀態。

流程大致是,由公司設定目標,並且由各層組織進行分配建立相對應KPI,公司會依照KPI作為獎懲依據,以利於整體效率管理。

那軟體開發的 KPI 呢?

Continue Reading

Page Keygen 防止使用者同時開啟多視窗瀏覽同一個頁面

Page Keygen 防止使用者同時開啟多視窗瀏覽同一個頁面

在現有維護的專案中,其中一個教學系統提供影片單元,

可以讓學生觀看教學影片,並且紀錄學生在各單元影片的學習進度及完成度。

卻發現有部分學生透過開啟多個瀏覽器,或者跨不同裝置來同時播放教學影片的方式快速累積完成度。

為了防止這種狀況,針對這個問題,設計了 Page keygen 的方式來進行處理:

Continue Reading