發表文章

目前顯示的是有「筆記」標籤的文章

筆記:用curl上傳檔案

 這篇彙整一下用curl測試上傳檔案,驗證伺服端使用node.js。 之前 也有用node.js寫過伺服端,不過那時沒有用curl做測試

筆記:Node.js開發Azure Functions存取Azure Cosmos DB(serverless)

官方有許多文件在講述這樣的東西,我想我遭遇的問題,應該是改版所以就有點不太一樣,以下就分享我自己測試成功的方法。

筆記:以指令部屬Azure function函數應用程式

Deploy Azure function by azure cli on Ubuntu 20.04 不知道為什麼,我的Azure帳號只要不是手動指令部屬它都會失敗。Portal和VSCode外掛跟都是一樣會失敗,錯誤訊息因為沒接觸過,所以也不好理解。

筆記:網站整合LINE登入機制

原本只是想弄LINE通知,不過看到要oauth就覺得煩,乾脆直接了解LINE登入機制。這篇會講登入的作法,和需要存取的LINE API,以CURL指令舉例說明。建議可以先了解 LINE BOT機制 再來整合。

筆記:在Ubuntu20.04安裝Docker及Compose

Install docker/docker-compose in Ubuntu 20.04 今天想到自己沒有做個docker安裝的筆記,趕快補上! 安裝前需求套件 sudo apt update sudo apt -y install apt-transport-https ca-certificates curl gnupg lsb-release 加入gpg key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 設定來源 echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 安裝docker套件 sudo apt update sudo apt -y install docker-ce docker-ce-cli containerd.io 設定群組權限 將docker加入,這樣就不用每次docker時要sudo,而且使用VSCode remote development也需要這個設定  sudo groupadd docker sudo usermod -aG docker $USER newgrp docker 參考: https://docs.docker.com/engine/install/linux-postinstall/ 測試 docker run hello-world docker會去官方repository抓示範用的image,只會印出歡迎訊息。 安裝Compose sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-comp...

筆記:ffmpeg和alsa指令錄音PCM及WAV

因為工作研發及驗證需要整理一下ffmpeg和alsa錄音指令

Docker-compose使用筆記

Docker-compose使用筆記 前一篇的 Dockerfile筆記 已經先學會基本的Docker用法,但是docker只能一次操作一個系統,如果要產生MEAN stack不就要下好多個指令嗎? 同事推薦再學一下docker-compse指令,只要寫好yml,你可以一個指令操作好多個docker container,關閉時也很簡單。 以下搭配我已經建立好的 php-mariadb的docker-compose 來講解

Docker指令使用筆記

Docker指令使用筆記 因為工作上需要開發簡單的API server並自動化部屬,就開始學習docker該如何使用。

javascript語言特性:Number的bitwise operation(位元操作)是使用32bit處理

最近想要移植C的一些64bit資料處理的小程式到JS上,就遭遇這個問題位元指令32bit的問題。實際上JS所有的位元操作(bitwise operation),諸如:左移(left shift)、右移(right shift)、OR、AND、XOR等都是只能用在32位元內操作。

筆記:建立FB粉絲團Messanger的BOT

參考 FB Messenger Bot 建置教學 聊天機器人 try try 抗之 Facebook Messenger Bot 特輯 流程簡記 啟用FB的developer帳號 https://developers.facebook.com/ 新增應用程式 新增產品>Messanger FB developer主控台>產品>Messanger>設定>存取權杖>創建粉絲團>產生權杖(PageAccessToken) FB developer主控台>設定>基本資料>應用程式密鑰(SecretKey) 下載官方範例,將node資料夾拷貝出來當作自己的BOT專案 https://github.com/fbsamples/messenger-platform-samples.git 修改node底下的config/default.json檔案內容,填入前面的權杖和密鑰,validationToken是你自訂的驗證權杖,和你預計放上BOT的server的網址。以我來說,BOT是放上heroku取名miro-fb-bot專案的話,server URL就是填上https://miro-fb-bot.herokuapp.com/ 將BOT專案佈屬到server上 回到FB developer主控台>產品>Messanger>設定>Webhooks>將你的server URL/webhook填入回呼網址(以我的BOT為例是填入https://mirochiu-fb-bot.herokuapp.com/ webhook ),和你剛自訂的驗證權杖,進行測試 驗證webhooks後,下面webhook至少要選擇訂閱"messages"欄位 開FB,到你剛創建的紛絲團頁面,按"分享"按鈕旁邊的選項>以粉絲團訪客的角度檢視,這時FB就會自動叫出BOT在右下角,隨意輸入文字就會看到返回相同文字訊息

筆記:github page

如果你要創建一個xyz.github.io的github page github註冊使用者xyz  創建一個repository名為xyz.github.io (選項)將branch取名為gh-pages (可以從Setting分頁選擇,已不是必要步驟) 將網頁圖文資料加入到該branch,並將分支上傳到github。 進入該repository的Settings分頁,選擇GitHub Pages要使用的branch (預設上傳完應該自動就選好了)。 瀏覽你的github page https://xyz.github.io 如果你有其他repository也是可以設定github page,只是預設會是xyz.github.io/respository_name 如果你有自己的CNAME,也可以在GitHub Pages上設定指到github page。 缺點: 只能放靜態網頁。 所有資料都是公開的。 有網站容量限制。 有流量及瀏覽量限制。 Github官方Steps https://help.github.com/en/github/working-with-github-pages/getting-started-with-github-pages 或參考龍哥的介紹 https://gitbook.tw/chapters/github/using-github-pages.html

筆記:分享圖片/文字/HTML到其他App

分享文字/圖片到其他App,例如FB、Line 以前分享文字 以前分享文字,自己寫intent,然後開啟Activity static Intent getSendTextIntent(String text) {     Intent intent = new Intent();     intent.setAction(Intent.ACTION_SEND);     intent.setType("text/plain");     intent.putExtra(Intent.EXTRA_TEXT, text);     return intent; } startActivity(getSendTextIntent("Hello, just do a test!")); 一般還會建議應該再判斷是否可以啟動Activity if (intent.resolveActivity(getPackageManager()) != null) {     startActivity(intent); } 現在分享文字 現在用ShareCompat就好了 import android.support.v4.app. ShareCompat ; 最新的JetPack是引用 import androidx.core.app. ShareCompat ; ShareCompat.IntentBuilder.from( MainActivity .this)         .setType("text/plain")         .setChooserTitle("Share Text")         .setText("Hello, just do a test!")         .startChooser(); 如果要Intent也是可以getIntent...

筆記:gdb debug指令概要

1. b/break設定中斷點 1.1 針對function名稱設定中斷點b func_name gdb內可以用TAB的auto completion,預設最多顯示200筆資料 (gdb) b avpriv_mpegts avpriv_mpegts_parse_close   avpriv_mpegts_parse_open    avpriv_mpegts_parse_packet (gdb) b avpriv_mpegts_parse_packet Breakpoint 1 at 0x749540: file libavformat/mpegts.c, line 3369. 1.2 針對特定source code行數設定中斷點b file_name:line_num (gdb) b libavformat/mpegts.c:3163 Breakpoint 2 at 0x7451a7: file libavformat/mpegts.c, line 3163. 1.3 針對目前source code設定中斷點b line_num (gdb) b 300 Breakpoint 2 at 0x4971a7: file fftools/ffprobe.c, line 300. 如果你還沒有執行程式,b 300的意思是設定main程式所在檔案的第300行 例如ffprobe的main程式在fftools/ffprobe.c, 就會設定在ffprobe.c的300行 1.4 針對當前位置設定中斷點 b (gdb) b 1.5 顯示中斷點i b/info break (gdb) i b Num     Type           Disp Enb Address            What 1       breakpoint     keep y   0x0000000000749540 in avpriv_mpegts_parse_p...

筆記:app當機時用gdb遠端debug

參考來源: Debugging apps or processes that crash https://source.android.com/devices/tech/debug/gdb 1. 在目標裝置上設置debug.debuggerd.wait_for_gdb Android 7之後可以使用內建功能, 首先設置debuggerd的property $ adb shell setprop debug.debuggerd.wait_for_gdb true 2. 模擬APP當機 使用ps確定測試用APP是com.myapp.test $ adb shell "ps | grep com.myapp.test" 產生SIGABRT信號模擬APP當機 $ adb shell kill -6 2823 從adb logcat中可以看到下面一段debuggerd印出的dump資訊, 有看到下面 藍色部份 就是表示系統已正在等待gdb連線 --------- beginning of crash 02-13 15:45:52.820  2823  2823 F libc    : Fatal signal 6 (SIGABRT), code 0 in tid 2823 (ht.mod.watchdog) 02-13 15:45:52.821  1650  1650 W         : debuggerd: handling request: pid=2823 uid=1000 gid=1000 tid=2823 02-13 15:45:52.923  3190  3190 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 02-13 15:45:52.924  3190  3190 F DEBUG   : Build fingerprint: '...:user/release-keys' 02-13 15:45:52.924  3...

筆記:gdb透過網路debug目標裝置

1. 於目標裝置置入gdbserver 以AOSP為例, 在prebuilts目錄下有已經編譯好的gdbserver版本(64-bit要找gdbserver64), $ find -name gdbserver prebuilts/misc/android-arm/gdbserver prebuilts/misc/android-arm/gdbserver/gdbserver ... 我手邊裝置是arm,從本機用adb push把gdbserver置入目標裝置中即可 adb push prebuilts/misc/android-arm/gdbserver/gdbserver /system/bin/ 如果push不上去,應該是read-only狀態,需要先adb remount後再adb push上去 2. 啟動目標裝置上的gdbserver 啟動gdbserver有兩種不太一樣的debug模式如下: Debug情境1. debug已在跑的Process 例如:假設已用ps確認要debug已在跑的程式recorder之PID為2947。 # ps | grep recorder root      2947  2939  40352  11380 hrtimer_na b2656f50 S recorder 在目標裝置上執行gdbserver在port 9999等待gdb連線,並附掛上指定PID為2947之程式 # gdbserver :9999 --attach 2947 Attached; pid = 2947 Listening on port 9999 Debug情境2. 從啟動程式開始debug 例如:在目標裝置上用gdbserver直接啟動待debug的程式recorder,並帶入啟動參數http://www.google.com, 在port 9999等待gdb連線近來 # gdbserver :9999 recorder http://www.google.com Process recorder created; pid = 3039 Listening on port 9999 注意:程式啟動參數無法從本機電腦端(gd...

筆記:gdb 執行/帶參數/停止/顯示help

執行gdb 第一個參數ffprobe_g是待會要debug的程式。 $ gdb ffprobe_g GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 ... Type "apropos word" to search for commands related to "word"... Reading symbols from ffprobe_g...done. (gdb) 如果該程式有symbol在內,會顯示上面 藍色標示 字串,  如果要debug應該要載入symbol。 如果你的程式已經strip過,可能就沒有symbol可以參考,需要編譯成沒有strip 這裡也可以不指定第1參數,之後再指定, 請跳到"載入/改變執行程式"部份。 顯示子指令i/info (gdb) i List of info subcommands: info address -- Describe where symbol SYM is stored info all-registers -- List of all registers and their contents info args -- Argument variables of current stack frame .... 顯示說明h/help (gdb) help List of classes of commands: aliases -- Aliases of other commands breakpoints -- Making program stop at certain points data -- Examining data .... 針對特定指令顯示說明 (gdb) h help Print list of commands. (gdb) h run Start debugged program.  You may specify arguments to give it. Args may include "*", or "[...]"; they are expanded usi...

筆記:netstat指令

顯示路由表 netstat -r 顯示網路裝置設定 netstat -i netstat -an # netstat -antp|wc -l # 檢測本機使用的port netstat -an | grep LISTEN | grep ":21" # ftp netstat -an | grep LISTEN | grep ":22" # ssh netstat -an | grep LISTEN | grep ":25"  # smtp mail service netstat -an | grep LISTEN | grep ":25"  # pop3 mail service netstat -an | grep LISTEN | grep ":80" # www netstat -an | grep LISTEN | grep ":8080" 計算每一個 ip 在主機上建立的連線數量 netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n 列出從 TCP 或 UDP 連線到主機的 ip 的數量 netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n 列出每個 ip 建立的 port 80 連線數量 netstat -plan|grep :80|awk {’print $5′}|cut -d: -f 1|sort|uniq -c|sort -nk 1 列出連線的協定及使用的應用程式 netstat -alp 列出完整的 URL 位址 netstat -tup -W 這個指令可以驗證 MySQL 是否是透過 UNIX domain socket 連線 netstat -lx | grep -i sql 參考資料 http://aries.dyu.edu.tw/~tarng/dyu_c.c/netstat.htm https://www.php...

DesignPattern: Null Object, Singleton

Null object pattern/空物件模式 我認為空物件模式是讓程式碼保持乾淨,並且語意明確的一種方法。 為了好debug,在寫C時我已養成加上要檢查函數參數中的指標是否為NULL,不然可能程式執行到一半就會crash掉,然後找半天都不知道錯誤在哪裡;不過在寫Java時,這習慣就會變成不檢測,直接讓程式crash反正最後也會有jvm會幫我印出錯誤位置點。 Christopher Okhravi教學影片 https://www.youtube.com/watch?v=rQ7BzfRz7OY 如何實現 Null Object Pattern ? (使用PHP展示) http://oomusou.io/design-pattern/nullobject/ Null Object 模式並非出自 設計模式 一書,而是出現在 重構 的 Ch 9.7,教大家將  null  值重構成  null  物件,因為只要有  null  值,就必須去  if  判斷是否  null ,甚至於去  try catch ,這樣的 API 並不好用,而且只要忘記判斷就可能出錯。 Singleton pattern/單例模式 這個類別在整個世界中只會存在一個實體, 不論如何取得都是同一個實體。 Christopher Okhravi教學影片 https://www.youtube.com/watch?v=hUE_j6q0LTQ 良葛格和RunNoob.com都有用java語言寫幾種範例 這個影片動態的展示了未保護的singleton在multithread狀態會有問題 https://www.youtube.com/watch?v=iyfqDV4wKAQ 1. 實作單例基本精神, 並具備multithread保護的能力 public class Singleton {   private static Singleton instance;   private Singleton (){}   public static synchronized Singleton getInstance() { ...

git remote指令操作

推入遠端 將最新的commit(HEAD)推入遠端origin (Code Review) git push origi n HEAD:refs/for/master 推入遠端 git push origin master 邪惡版推入遠端(強制) git push origin master --force -f是--force的短指令 如果我目前分支不是master而是yhchiu , 但是我想推到遠端上改成new_patch這個分支 git push origin yhchiu:new_patch 實際上不見得一定要推分支 , 指定某個commit也可以推 顯示本地跟遠端所有branch git branch -a 顯示有哪幾個遠端名稱/遠端名稱及網址/遠端詳細訊息 git remote show git remote -v 加入新的遠端伺服器,命名為origin2 git remote add origin2 ssh://yhchiu@192.168.10.30:29418/NewDevice 下面是一個遠端同步的應用: 我在遠端伺服器192.168.10.30上面用我的帳號yhchiu的家目錄中建立了一個資料夾public並在上面clone了NewDevice的git庫,所以我就會有一個/home/yhchiu/public/NewDevice的git資料夾 我可以在另一台電腦上直接clone我家目錄下的這個git ssh://yhchiu@192.168.10.30/home/yhchiu/public/NewDevice 另外我也可以將這個url加入remote變成合併原本的目錄和我在我家目錄上建的目錄 刪除某個遠端伺服器 git remote rm origin2 遠端伺服器改名 git remote rename pb paul 更新遠端資料 git pull 不要隨便在任一個commit/branch之後或是使用這個指令,是否亂掉可以用gitk查看左上角的分支線路,不是一條而是有迴圈就是出問題了,得先要恢復到某個版本 git pull origin master 從所有的遠端伺服器上抓取資料/從預...

git全域設定,局部設定與移除/取消設定

git分為全域設定和局部設定(Repo內) 忽略空白處變化,如果是寫python的話就不能忽略空白處變化 基於讓每個環境都有一致的呈現結果,我也不建議忽略空白處變化 git config --global apply.whitespace nowarn 有些git下載回來設定檔裡面有no-fast-forward的設定,會阻止我們用force push修改以前的修正 git config branch.master.mergeoptions "--no-ff" 如果想拿掉某個config就用unset來取消設定 git config --unset branch.master.mergeoptions 若主要是在ubuntu中開發, 而偶爾會在windows上開發,建議windows部份設定忽略檔案的屬性改變,以及讓git自動轉換換行字元(CRLF->LF) 非常不建議同一份git目錄在windows開發又搬移到linux上開發, 因為會有換行/權限/等等的問題 git config --global core.fileMode false # In Windows/Mac, push/pull convert the line feed git config --global core.autocrlf true # In Ubuntu/Linux,convert CRLF to LF while push git config --global core.autocrlf input Ref:https://help.github.com/articles/dealing-with-line-endings/ Windows  CRLF => \r\n Linux LF \n Mac CR \r 檢查文件是否混合兩種換行方法,若有就會拒絕commit, 因為換行會成script無法正確的parsing,所以我會建議設定這個 git config --global core.safecrlf true 如果檔案被拒絕,可以用dos2unix將檔案的換行符號換成unix的LF 如果你修改了上面這些設定,請確保你的git目錄內的檔案都是一致的 git rm --cac...