網頁

2017年10月19日 星期四

Catch exit code in bash shell script

The key variable is $?

Example code :

#!/bin/bash

./execute_some_script.sh

if (( $? == 0 ))
then
    echo "the script in script was executed successfully."
else
    echo "the script in script was failed !"
fi

Also a tip for comparing variable as numeric is " if (( $var op $another_var_or_number )) "

2017年10月16日 星期一

String index V.S. Array index in Delphi

I'm used to develop code in C, however someday I meet the need which the code was written in Delphi.

The amazing fact in Delphi is the index on array and string differs ! This is really shock, it shocked me almost put hands in my mouth. 嚇得我吃手手...

In Delphi, Strings are 1-indexed, but arrays are 0-indexed.

也就是說如果有一個變數被設為 String 例如說 S:=Foo.Bar().AsString;
如果要存取 S 的第一個字元要使用 S[1] 才會是正確的字元。

If S is assigned as a string variable, the first character would be S[1] not S[0];

2017年10月12日 星期四

如何找出資料庫中的表格還有建立日期?

很簡單,要去 INFORMATION_SCHEMA 撈資料

SELECT create_time FROM INFORMATION_SCHEMA.TABLES
  WHERE table_schema = '資料庫名稱'
  AND table_name = '表格名稱'

以某次應用,每個月都會新增一張表格,而前端網頁會選擇最近期三筆新增的表格,讓使用者做選擇。這時候下的語法就是
SELECT TABLE_NAME,create_time  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA="資料庫" \
ORDER BY create_time DESC;

當然這樣的語法撈出來的是所有的 table 但是做完查詢後,不論是用 perl 還是 PHP 就可以撈出來前三筆資料知道是最近三筆新增的 table。

Python TypeError: 'module' object is not callable

程式碼其實相當簡單 import random random.random() 那問題出在哪?出在當初的檔名取名為 random.py 結果造成 Python 在 import 的時候造成問題。所以在取名Python 的檔名時,切記不要取成跟 Default Module...