發表文章

目前顯示的是 1月, 2017的文章

Let date output the english in Ubuntu

為何會需要將date輸出的結果改成英文,是為了方便產生build code的時間資訊 Check the default locale in Ubuntu $ locale -a 找類似於 en_US 的locale全名,我的是en_US.UTF-8 Set your local environment variable ~/.bashrc export LC_TIME=en_US.UTF-8 Test the result $ source ~/.bashrc $ date If you want to set in the global environment vairable $ sudo vim /etc/default/locale or $ sudo vim /etc/environment Reference: http://www.davidpai.tw/ubuntu/2011/ubuntu-set-locale/

Install latest git version on Ubuntu

Add the git PPA and install sudo add-apt-repository ppa:git-core/ppa sudo apt-get update sudo apt-get install git Check the installed version sudo apt-cache policy git git --version

Android 5.1在APP內綁定使用的網路裝置

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) {     Log.d(TAG,"try to bind ethernet for ekioh");     Network[] allnet = cm.getAllNetworks();     if (allnet==null || allnet.length==0) {         Log.e(TAG,"Failed to getAllNetworks from ConnectivityManager");     } else {         boolean isBinded = false;         Log.d(TAG,"getNetworkInfo() : " + allnet.length);         for (Network net : allnet) {             NetworkInfo info = cm.getNetworkInfo(net);             LinkProperties lnk = cm.getLinkProperties(net);             if (lnk != null) {                 Log.d(TAG, "Interface:   " + lnk.getInterfaceName());                 List addr = lnk.getLinkAddresses();                 for (LinkAddress a : addr) {                     Log.d(TAG, "  addr: " + a.toString());                 }                 List route = lnk.getRoutes();                 for (Route

Get and Compile H.265/HEVC Reference Software

H.265/HEVC(High Efficiency Video Coding) Reference Software (HM - HEVC test model) https://hevc.hhi.fraunhofer.de/ Install Subversion the source code version control system $ sudo apt-get install -y subversion Download the workspace of HM $ mkdir hm && cd hm && svn checkout https://hevc.hhi.fraunhofer.de/svn/svn_HEVCSoftware/ Compile with the trunk version $ cd svn_HEVCSoftware/trunk/build/linux $ make Location of the compiled executable files $ svn_HEVCSoftware/trunk/bin

Get and Compile H.264/AVC Reference Software

H.264/AVC(Advance Video Coding) Reference Software (JM - Joint test model) http://iphome.hhi.de/suehring/tml/ Please download the zip file which are the source code from the behind website. Unzip the zip file $ unzip jm19.0.zip -d jm Compile the source code $ cd jm/JM && make Location of the compiled executable files $ jm/JM/bin/lencode $ jm/JM/bin/ldecode

在Ubuntu上使用GnuPG進行PGP簽章加解密

安裝套件 sudo apt-get install gnupg 產生簽章用key gpg --gen-key 會需要填寫一些包含個人名稱, E-mail和輸入維護用的密碼 產生出的public key會存在家目錄~/.gnupg/pubring.gpg 產生出的private key會存在家目錄~/.gnupg/secring.gpg 如果需要修改已經產生的key,可以參考 這篇 列出本機上的public/private key gpg --list-keys 預設public key目錄~/.gnupg/pubring.gpg gpg --list-secret-keys 預設private key目錄~/.gnupg/secring.gpg 匯入public/private key gpg --import public_key 成功時會印出匯入成功的public key uid和hash code gpg --allow-secret-key-import --import priv_key 成功時會印出匯入成功的private key uid, hash ccode, 和public key 對檔案加密 這裡使用keyring裏面有我個人名稱MiroChiu的private key進行檔案加密 gpg --recipient MiroChiu --output demo.en.txt --encrypt demo.txt 簡短的寫法 gpg -r MiroChiu -o demo.en.txt -e demo.txt 對檔案解密 解密的時候不需要指定要用哪把key,因為加密檔會有解密所需的public key資訊,只要你的keyring中有這把key就能夠解開他, gpg -o demo.de.txt -d demo.en.txt ***由於GunPG是Linux的程式沒有副檔名的概念,所以拿GunPG加密我會建議在產生加密檔案的時候就把檔名多加上.pgp,避免其他使用者拿去Windows要解密的時候,因為沒有正常的副檔名而無法運作 對檔案加密並簽章 用自己的private key加密檔案,並用對方public key簽章,確定只有對方能夠解密 gpg --local

Android發送廣播訊息

發送某個廣播Action最簡單的程式碼,需要在Activity下操作 public void broadcastAction() {     //Log.d(TAG, "broadcastAction");     Intent intent = new Intent();     intent.setAction("com.example.SendBroadcast");     sendBroadcast(intent); } 除了能夠透過寫APP程式發送外也可以用android adb shell的指令發送 送給所有接收Action # am broadcast -a com.example.SendBroadcast Broadcasting: Intent { act=com.example.SendBroadcast } Broadcast completed: result=0 action可以自己定義,或者用Android已定義在文件中以ACTION_開頭的常數 http://developer.android.com/intl/zh-tw/reference/android/content/Intent.html 送給特定Package # am broadcast com.example.SendBroadcast Broadcasting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=com.example.SendBroadcast } Broadcast completed: result=0 加上要傳送的Action就變成下面這樣(不建議用boot completed測試,有些Android裝置會重啟) # am broadcast -a android.intent.action.BOOT_COMPLETED -p com.example.SendBroadcast 由於-p可省略就變成 # am broadcast -a android.intent.action.BOOT_COMPLETED com.example.

Ubuntu查看硬體資訊

圖片
sudo lshw # 跑的比較久, 要稍等一下 sudo lshw -C network # network部份 lshw的圖形化介面版本lshw-gtk 安裝: sudo apt-get install lshw-gtk 執行: sudo lshw-gtk 執行程式時不會自動掃描,要按上面的Refresh按鈕 有看到粗體字的部份可以滑鼠再上面點兩下來展開下一層資訊 另一種圖形化版本, 介面比較像Windows上的軟體 安裝: sudo apt-get install hardinfo 執行: hardinfo 察看主機板資訊 sudo dmidecode 後面可以帶 type資訊,在man dmidecode裏面有提到 sudo dmidecode -t 0 # BIOS info sudo dmidecode -t 2 # Motherboard info sudo dmidecode -t 4 # CPU info sudo dmidecode -t 11 # OEM info 察看cpu, pci, usb, 硬碟分割區, 已載入的核心模組 lscpu lspci lsusb lsblk lsmod

Automatically input password of sudo in Ubuntu shell

If your user password is "input-your-password" Example: echo "input-your-password" | sudo --stdin cat /proc/keys

Generate a binary file and print all in C++

#include  <iostream> #include  <cstdlib> #include  <fstream> #include <ctime> // for time using namespace std; int main() {   const int DATA_MAX_LENGTH = 100;   int  Data[DATA_MAX_LENGTH];   srand(time(NULL));   // write   ofstream out;   out.open("myfile.bin", ios::binary);   if (!out)   {     cerr << "output file error!" << endl;   }   else   {     for (int i=0 ; i<DATA_MAX_LENGTH ; ++i)       Data[i] = rand()%256;     out.write((char*)(&Data[0]), sizeof(Data[0])*DATA_MAX_LENGTH);     out.flush(); // before you close the output file, please flush it!     out.close();   }     // read   ifstream in;   in.open("myfile.bin", ios::binary);   if (!in)   {     cerr << "input file error!" << endl;   }   else   {     in.seekg(0, ios_base::end);     int filesize = in.tellg();     in.seekg(0, ios_base::beg);     int datanum = filesize/sizeof(Data[0]);    

Generate a binary file and print all in C

#include  < stdio.h > #include  < stdlib.h > int main() {   int i;   FILE *in, *out;   const int DATA_MAX_LENGTH = 100;   int  Data[DATA_MAX_LENGTH];      srand(time(NULL));      out = fopen("myfile.bin", "wb");   if (out == NULL)   {     fprintf(stderr, "output file error!\n");   }   else   {     for (i=0 ; i<DATA_MAX_LENGTH ; ++i)       Data[i] = rand()%256;     fwrite(Data, sizeof(Data[0]), DATA_MAX_LENGTH, out);     fflush(out); /* before you close the output file, please flush it! */     fclose(out);   }        /* read */   in = fopen("myfile.bin","rb");   if (in == NULL)   {     fprintf(stderr, "input file error!\n");   }   else   {     int filesize, datanum;          fseek(in, 0, SEEK_END);     filesize = ftell(in);     fseek(in, 0, SEEK_SET);     datanum = (filesize)/sizeof(Data[0]);     printf("File size=%d\n", filesize);     printf("Number of da

已習慣使用的vimrc設定

syntax on set t_Co=256 colorscheme desert set ruler " show line number set nu " show relative number  set rnu set autoindent set tabstop=4 set expandtab set shiftwidth=4 " Current line draw the underline set cursorline " Show the search set incsearch " Hilight the matched strings set hlsearch set wrapscan set history=255 set linebreak " Ignore case in searching set ignorecase set nowrap " Past text without auto indent on remote connection set paste " No vi compatible set nocompatible " Backspace anytime set backspace=indent,eol,start " we want to show special char, eg. tab, line-ending etc. set list " show symbol set listchars=eol:$,tab:>.,trail:~,extends:>,precedes:< " Enable clipboard (your vim should ) set clipboard=unnamed if has('unnamedplus')     set clipboard=unnamed,unnamedplus endif """""""""""""

計算16bit整數的bit數

關於這個議題,在面試的時候常會出現,不過我這裡感興趣的是 fcamel 針對做了相關的測試,從中可以一個演算法可能實作大於理論的做法,推薦給大家看看,站外全文連結在 這裡 。