2018年9月16日 星期日

MySQL

DATE_ADD(date,INTERVAL days), DATE_SUB(date,INTERVAL days)
CURRENT_TIMESTAMP(),NOW() return your now time
basically you can also write the string+-INTERVAL unit
it will also return your function results.

Note:
if you want to know the time after sleep(n),you should use SYSDATE(),
However you should note that...
Because SYSDATE() can return different values even within the same statement, and is not affected by SET TIMESTAMP, it is nondeterministic and therefore unsafe for replication if statement-based binary logging is used. If that is a problem, you can use row-based logging.
-->Binary logging makes it unsafe.
-->So please log in one by one.
 ##USE DATE_SUB(your date,last month,number of  days in this month-1(bc you want the first day)) to reach your first day /last day in your calendar!!!


2018年8月30日 星期四

AI

Data Hunting:
ML系統: 提供給系統的訓練資料可以很多元並不侷限於照片,也可以是具備多種特徵的數據表格、文字、感測器的讀數、聲音等等。

2018年8月27日 星期一

Python -Tkinter

Functions:
  1. Label
  2. Button
  3. Radiobutton
  4. Checkbutton
  5. Entry
  6. Frame
  7. LabelFrame
  8. Listbox
  9. Text
  10. Message
  11. PanedWindow
  12. Scrollbar
  13. Scale
  14. Spinbox
  15. Menu
  16. OptionMenu
  17. Menubutton
  18. Canvas
  19. Image
  20. Bitmap
  21. Toplevel
  22. http://yhhuang1966.blogspot.com/2016/05/python-gui-tkinter.html

2018年6月30日 星期六

錯誤總複習筆記

程式篇:(C++)

  • virtual function:
  1. abstract class: 擁有 pure virtual function 的類別,該類別只能被繼承,不能產生實例
  2. pure virtual function:指定函式只能提供一個介面,由子類別繼承,重新定義
  3. polymorphic class:擁有多個 virtual functions
  • redefinition ,overriding差別:
  1. redefinition(重新定義):不限制為虛函數,在衍生類別中,重新定義子函式
  2. overriding(複寫):重定的對象是virtual function就為override,若想要複寫基礎類別而不是繼承別人的話,用override,若不想被繼承,用final,用來避免虛擬函式被複寫
  • 編譯器還為每個類別加上一個VTABLE,VPTR指向VTABLE的開頭。 VTABLE 紀錄了基礎類別內被宣告為 virtual function 的成員函數。
  • 若沒overriding,就記錄基礎類別的位址
  • 解構時必須把解構函數宣告成virtual function ,才能釋放 VPTR VTABLE,否則memory leak

  • Pointer&Reference:

void swap (int *c , int *d){
   int temp=*c;
   *c=*d;
   *d=temp; "做deference,對指定位址的值做交換"
}
int main(){
   int a=5,b=10;
   swap(&a,&b);
   printf(" %d %d ", a,b);
}

  • (如上)對指定位址的值做交換,本身位址是不變的
  • void swap (int &c , int &d){
       int temp=c;
       c=d;
       d=temp;
    }
    int main(){
       int a=5,b=10;
       swap(a,b);
       printf(" %d %d ", a,b);
       return 0;
    }
  • 傳參考就直接控制本人

  • 有關指標:

  • 基本上,int *a=&b;(位址需要 非 常數)
  • 但是,請看如下例題:
int *p1;int *p2;
p1=new int;p2=new int;
*p1=0;p2=0;p2=p1;//deference 直接指值是被允許的,bc有allocate memory
*p2=1;*p1=3;p1=0;
//p1已經被p2定址到0身上了,所以p1已有定址,但是,由於定址後不能再改變位址,p1=0及不成立,
雖然都為零,但是為重複定義,就會出現錯誤

  • 封裝:nest class,local class Vs.private,protected
  • public:當資料可以給user、自己和derived class存取時使用。
    protected:當資料不可以給user存取,只能給自己和derived class存取時使用。
    private:當資料不可以給user和derived class使用,只可以給自己存取時使用。
    friend:指定一個global function可存取private資料。
  • 遇到Nest class&local class時,封裝可能被會產生質疑:
  • Nest class:
          內部類別不能存取外部類別的private成員,外部類別亦不能存取內部的private成員
           (就算彼此層層相扣,環環相護,private就是不能動)
  • Local class:
類別可以定義於函式中,但不能存取函式中的變數,能存取外部類別的private成員

  • 重載運算符:
  • <.   ::   .*   ?:>不能重載運算子
  • 所接收的物件引數來自被重載的運算子右邊
  • Point2D operator+(const Point2D&); // 重載+運算子 (const Point2D&)因為要整陀丟入
    Point2D operator-(const Point2D&); // 重載-運算子 
    Point2D& operator++(); // 重載++前置,例如 ++p (使用Point2D&的原因是因為,前置++作修改)
    Point2D operator++(int); // 重載++後置,例如 p++
    Point2D& operator--(); // 重載--前置,例如 --p 
    Point2D operator--(int); // 重載--後置,例如 p--
  • p1+p2;

  • C++ v.s. Java  ((C++)reference and pointer,(J)only reference)

  •         C++                        Java++
    copy      複製一份內容數值                                      複製一份參考給別人 

        C++中的參考,必須在宣告時就指定其所指之處,且不得改變                                                                                                              指向同份object的數值
    C++:
    Java:
    Point p1(5,5);
    p1
    XXXX : 0000
    5
    XXXX : 0004
    5
    XXXX : 0008
    XXXX : 000C
    Point p1 = new Point(5,5);
    p1
    XXXX : 0000
    XXXX : 0100
    XXXX : 0004
    XXXX : 0008
    XXXX : 000C
    . . .
    Instance of
    XXXX : 0100
    5
    Point Object
    XXXX : 0104
    5
    XXXX : 0108
    XXXX : 010C

    Point p2 = p1;
    p1
    XXXX : 0000
    5
    XXXX : 0004
    5
    p2
    XXXX : 0008
    5
    XXXX : 000C
    5
    Point p2 = p1;
    p1
    XXXX : 0000
    XXXX : 0100
    p2
    XXXX : 0004
    XXXX : 0100
    XXXX : 0008
    XXXX : 000C
    . . .
    Instance of
    XXXX : 0100
    5
    Point Object
    XXXX : 0104
    5
    XXXX : 0108
    XXXX : 010C


    • (c++)Point& p2 = p1;指向同塊記憶體
    • Pointer p3(7,7);
    • p2=p3;複製一份p2給p3;
    • C++的參考,比較常用的場合是在呼叫函式時























  • Dymanic Memory
  • malloc-安排空間,未安排初始值
  • calloc-安排空間,安排初始值0
  • realloc-重新安排指定空間
  • free-釋放空間

2018年6月29日 星期五

I/O流

  • include
  • void ifstream::open(const char *filename, openmode mode=ios::in); 
    void ofstream::open(const char *filename, openmode mode=ios::out |ios::trunc);
    void fstream::open(const char *filename, openmode mode=ios::in | ios::out);
  • filename是檔案名稱,而mode決定檔案的開啟模式
  • 如果您使用ofstream來開啟檔案,若指定的檔案原先存在,則檔案會被清空,您可以使用附加方式,或是使用ifstream並指定ios::in與ios::out,即可保留原檔案的內容。

  • 如果開啟失敗則串流會傳回false,您可以使用下面的片段來判斷: 
    if(!fin) { 
        cout << "無法讀取檔案\n"; 
        // 其它處理 

    最低階的輸出與輸出函式為get()和put()函式,它們被重載(overload)多次,我們這邊介紹最基本的字元輸入與輸出,它們的函式雛型如下: 
    istream &get(char &ch); 
    ostream &put(char); 

    當讀取至檔尾時,get()函式會傳回false,也可以使用eof()函式來判斷是否讀取至檔案尾端;下面這個程式示範如何讀入一個文字檔案,並顯示在主控台上
    ios::in檔案open為輸入模式(istream default)
    ios::out檔案open為寫入(ostream default)
    ios::ate從檔案尾端輸入輸出
    ios::app在檔案尾端以append模式寫入
    ios::trunc如果檔案存在,則清除檔案內容
    ios::binary以二進位模式open檔案

重載 ">>" "<<"



  • 通常重載 << 運算子時,會使用friend函式,這是因為重載 << 函式時,它不是一個成員函式,理由在於 << 左邊不是物件,而是一個輸出串流,由於 << 函式不是成員函式,若要能存取資料成員,則該資料成員必須設定為public,使用friend函式來進行重載的話,則不用受此限制。 

friend ostream &operator<<(ostream &s, Point p); 
ostream &operator<<(ostream &s, Point p) { 
    s << "("<< p.x << ", " << p.y << ")"; 
    return s; 
} 
 friend istream &operator>>(istream &s, Point &p); 
    friend ostream &operator<<(ostream &s, Point p); 
}; 
istream &operator>>(istream &s, Point &p) { //必須要是 &p input
    cout << "輸入點座標: "; 
    s >> p.x >> p.y; 
    return s; 
} 
ostream &operator<<(ostream &s, Point p) { 
    s << "("<< p.x << ", " << p.y << ")"; 
    return s; 
} 

Ethereum- Learn Solidity step by step

Common Function Types: public: Anyone can call this function,but it isn't really used for any type of security per se. priv...