2023/1/16

login, push to github in windows

因為 github 的新政策,所以舊的username/password login 方式不能用了。
windows 上就..好像沒有 linux 那種 token 的方法。
所以,就 follow 說明,安裝 github cli,裝完就有 gh 命令了。
開啟 dosbox,輸入 gh 有說明。
最後是參考這一頁 要再dosbox 執行gh,在 git 的 mingw64 執行的話,好像因為arrow-key mapping 的關係,會直接跳掉。

在dosbox 輸入...
gh auth login
他就會叫你用 up/down 選,Github.com
然後要你選 operation,ssh
然後因為我用 git mingw54 create 過 ssh,所以他直接找到我的id_rsa.pub
之後都 Enter,然後選開啟 web login..
browser 打開login 畫面,要你輸入剛剛dosbox 顯示的8 個 characters.
然後就完成了。

dosbox auth login 完成後,在git 的 mingw 中 push ssh://github.com/... 就 OK 了。

2023/1/13

bookmark: android camera hal 跟 v4l2

ndk build failed : "permission denied"

好誇張,新版ndk 使用的 windows api 不支援 windows 7,所以 windows 7 run 會 fail:
    Run Build Command(s):D:\Android\AndroidSdk\cmake\3.22.1\bin\ninja.exe cmTC_1e3b7 && [1/2] 
    Building C object CMakeFiles/cmTC_1e3b7.dir/testCCompiler.c.o
    [2/2] Linking C executable cmTC_1e3b7
    FAILED: cmTC_1e3b7 
    cmd.exe /C "cd . && D:\Android\AndroidSdk\ndk\23.1.7779620\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe 
--target=aarch64-none-linux-android30 --sysroot=D:/Android/AndroidSdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/windows-x86_64/sysroot 
-DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat 
-Werror=format-security -fexceptions  -O2 -g -DNDEBUG -Wl,--build-id=sha1 -Wl,--fatal-warnings -Qunused-arguments -Wl,--no-undefined  
-Wl,--gc-sections CMakeFiles/cmTC_1e3b7.dir/testCCompiler.c.o -o cmTC_1e3b7  -latomic -lm && cd ."
    ld: error: failed to write to the output file: Permission denied
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.
ref: 內容是:

You are correct. ProcessMonitor seems to indicate that in NDK version 23.1.7779620 the ld.exe is using a newer API calls that are not supported on Win7.
enter image description here
It looks like ld erroneously interprets the failed API call as a "permission denied" error. The same happens in NDK version 23.0.7599858.
The last NDK that seems to work on Win7 is 22.1.7171670.
After the system was upgraded to Win10 ld started to work normally for the 23.x NDK versions.

但是最新版的android studio 好像不允許自行決定 ndk 位置,而且每次都會自動更新到最新版..
到這邊(archive) 才能下載到舊板。

2023/1/4

bookmark: latex math render

因為chatgpt 回答數學式用的是 latex format。
所以需要一個把 latex 轉成數學式的網站。
雖然有人寫了 geasmonkey 的 plugin 來做,安裝到 chrome 後,直接在 chatgpt 就可以直接轉。
但是畢竟還是有點危險,
所以還是用 網站 版的。

www.quicklatex.com

2022/12/28

Try coverity scan for opensource project

coverity scan有提供 opensource 專案免費使用的服務。
就是用你的 github 帳號登入後,按下上面頁面的 "find your project"。
他就會列出你所有的 github project。
你就可以選一個你的 project (為了安全起見,最好選有 opensource license 的project,為你的project 增加 LICENSE 聲明可參考github 說明)。
然後就跟隨網頁說明,一步一步做..
接著就是 submit build

build 的動作要在自己的 local 完成。
download 他提供的 build (and analysis ?)tool,build project 後,把結果upload 到 coverity 網站。
他就會產生分析結果。

2022/12/22

simple example : swagger-py-codgen, ui and flask-resetful server

就是..從朽 api.yaml 開始,然後 codegen, 寫api.py,啟動 ui and restful sever,最後用 ui 測試 server 的 api

先寫一個簡單的 myapi.yaml: (copy from pet.yaml)
openapi: 3.0.0
info:
  version: 1.0.0
  title: Hello API
  description: An API to return hello in request language

servers:
  - url: http://127.0.0.1:5000/v1
    description: local server

paths:
  /api:
    get:
      tags:
        - Hello
      description: Return hello in specified language
      parameters:
        - in: query
          name: lang
          required: true
          description: language
          schema:
            type: string
            example: es

      responses:
        '200':
          description: hello in
          content:
            text/plain:
              schema:
                type: string
                example: hoa
然後 codegen..
$swagger_py_codegen --swagger-doc myapi.yaml site --ui --spec
然後為 api get 增加動作:
diff --git a/v1/api/api.py b/v1/api/api.py
index 2efe114..50aacd3 100644
--- a/v1/api/api.py
+++ b/v1/api/api.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import, print_function
 
-from flask import request, g
+from flask import request, g, make_response
 
 from . import Resource
 from .. import schemas
@@ -10,6 +10,6 @@ from .. import schemas
 class Api(Resource):
 
     def get(self):
-        print(g.args)
+        print(request.args)
 
-        return None, 200, None
\ No newline at end of file
+        return make_response(request.args['lang'],200)
然後到 site/site 下啟動 resetfule and ui server:
python __init__py
開啟覽器,到 swagger-ui 位置: http://127.0.0.1:5000/static/swagger-ui/index.html。
就可以用 swagger-ui,測試剛剛寫的 restfule server。


有些要注意的地方..

因為啟動的 __init__.py 有設定 :
    app.register_blueprint(
        v1.bp,
        url_prefix='/v1')
所以會在後面 v1/routes.py 中, path-handler 定義的位址加上 /v1/:
routes = [
    dict(resource=Api, urls=['/api'], endpoint='api'),
]
上面 /api 會變成 /v1/api,所以 myapi.yaml 的 servers 就要加上 /v1 ,這樣 swagger-ui 才能對正確的 url 動作。
這個github project 就是上面的說明,增加了 new user, userlist 的 api: 有比較多的 api 可以測試。

restful api and flask-restful

restful api 除了 http 的 PUT,GET,POST,DELETE 之外,有兩個地方可以"傳遞"參數給resetful server (flask)
  • url : /device/<devicde_id>/voltage/<meter_id>
  • body : 一般用 json 格式傳遞內容

其中 url 的部份, flask 用 api.add_resource(devicevoltage,'/device/<devicde_id>/voltage/<meter_id>)
產生變數 device_id, meter_id 在 devicevoltage 這個實做 http handler class 的 api入口,作為 參數:
class devicevoltage(Resource):
  def get(self,device_id,meter_id):
    ..
至於 body 的部份,在 flask-resetful 中,就會用 request 這個公用變數(? module?) 來提供:
   email    = request.get_json().get('email')
   username = request.get_json().get('username')