2015年5月4日 星期一

MySQL語法

1. Login MySQL with password
$mysql -u -root -p
Enter password:

2. How to get a list of user accounts
mysql> SELECT User FROM mysql.user;

3. How to delete user
mysql> DROP USER 'user_name'@'localhost';

4. Create user
mysql>CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'user_name';

5. Change user password
mysql> UPDATE user SET Password=PASSWORD("your_password") WHERE User='user_name';

6List all database
mysql>SHOW DATABASES;

7. Show current use database
mysql>SELECT DATABASE();

8. Change database
mysql>use database_name;

9. Create database
mysql>CREATE DATABASE db_name;

10. Delete database
mysql>DROP DATABASE db_name;

11. allow user to connect to the server from localhost with password
mysql>grant usage on *.* user_name@localhost identified by'user_password';

12. grant all privileges on database to this user
mysql>grant all privileges on db_name.* to user_nae@localhost;

13. Show tables
mysql>SHOW TABLES FROM db_name;

14 Show all tables
mysql>SHOW TABLES;

15. Show data from table
mysql>select * from table_name;

16. update column
update 資料表名稱 set 欄位1='值1',欄位2='值2',欄位3='值3',... 欄位N='值N'
where 條件式 (例如 sn='5' 或 name='塔司尼' );


2015年2月10日 星期二

How to setup NFS in Ubuntu

How to setup NFS in Ubuntu

  1. install nfs
$sudo apt-get install nfs-kernel-server
  1. check hosts name
$hostname --fqdn
ex:
$hostname --fqdn
usernamehost
The host name could not have special character, like "-, _, ", only "usernamehost". if return error, modify the host name, log-out then log-in.
$sudo vim /etc/hosts
127.0.1.1 kelseylaiAS5551
.
  1. setup nfs
$vim /etc/hosts.allow
portmap: [tv_ip]
lockd: [tv_ip]
rquotad: [tv_ip]
mountd: [tv_ip]
statd: [tv_ip]
ex:
$sudo vim /etc/hosts.allow
...
portmap: 192.168.0.107
lockd: 192.168.0.107
rquotad: 192.168.0.107
mountd: 192.168.0.107
statd: 192.168.0.107
/etc/hosts.deny /etc/hosts.allow 設定對portmap的訪問. 採用這兩個配置檔案有點類似黑名單,白名單的意思. 先在/etc/hosts.deny中禁止所有用 戶對portmap的訪問.再在/etc/hosts.allow 中允許某些特殊用戶對portmap的訪問。
  1. modify NFS directory permission

$sudo vim /etc/exports
/home/NFS 192.168.0.*(rw,sync,no_root_squash)

$exportfs -r

NFS掛載目錄及權限由/etc/exports檔案定義
例如,我在家目錄下建立一個名為NFS的目錄,作為共享給板子的,則在該檔案裡加入
/home/NFS/192.168.0.*(rw,sync,no_root_squash)
  1. make direcotry for NFS
$mkdir [you_want_nfs_path]
ex:
$sudo mkdir /home/NFS

   6. restart nfs server
$sudo service nfs-kernel-server restart



2014年2月18日 星期二

android adb

一、adb連線方式
Android default adb是使用USB連線,但也可以透過ethernet或是wifi
如果要改設adb的模式
1. usb to ethernet(wifi)
in device端
$su
$setprop service.adb.tcp.port 5555
$stop adbd
$start adbd

in computer端
$adb tcpip 5555
$adb connect 192.168.0.101:5555 

2. 如果要將adb改成usb連線
in device端
$setprop service.adb.tcp.port -1 
$stop adbd 
$start adbd


二、如何啟動adbd

adb實際是透過adbd(adb daemon )在運作的,android 本身有透過property "persist.service.adb.enable"去儲存adbd的狀態,透過更改值為0或1來啟動或停止adb. 例如在init.rc中設定啟動及停止的條件

add property in init.rc
on property:persist.service.adb.enable=1 
    start adbd 
on property:persist.service.adb.enable=0 
    stop adbd

這樣就可以在 runtime中,藉由修改property 來達到改變adb狀態

三、取得adb id
$adb shell id


2013年8月9日 星期五

Android Makefile

1. build binary file to host; out/host/linux-x86/bin/xxx

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PREBUILT_EXECUTABLES := aaa
include $(BUILD_HOST_PREBUILT)


2. build prebuilt APK to system/app

include $(CLEAR_VARS)
LOCAL_MODULE := install_flash_player
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)

3. build multiple prebuilt lib to system/lib

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PREBUILT_LIBS := libflashplayer.so \
  libysshared.so
LOCAL_SHARED_LIBRARIES := libflashplayer \
 libysshared
include $(BUILD_MULTI_PREBUILT)

4. build prebuilt binary file to system/bin

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := bbb
LOCAL_MODULE := bbb
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
prebuilt_files :=
$(call add-prebuilt-files, EXECUTABLES, $(prebuilt_files))

5. build .jar

LOCAL_PATH:= $(call my-dir)
#MAKE_JAR
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_MODULE := selfthread
LOCAL_MODULE_TAGS := optional
#need these jar built first, used in code base: core, ext, framework
LOCAL_JAVA_LIBRARIES := core ext framework
include $(BUILD_JAVA_LIBRARY)
#MAKE_XML
include $(CLEAR_VARS)
LOCAL_MODULE := selfthreadxml.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)

6. execute shell script in Android make file

#one shell call shell command once, if you don't want exit shell, use ";"
#use "``", in some environment it will shoe missing separator
#example $(shell `pwd`)
PWD := $(shell pwd)/vendor/company/anymote-protocol/java
$(shell `echo $(PWD)`)
$(shell `cd $(PWD);\
make;\
cd -`)

#or in one line
$(shell `cd $(PWD);make;cd -`)

#if use target, type $mm target, but default won't execute it, example
#$mm anymote
anymote:
cd vendor/company/anymote-protocol/java;\
echo `pwd`;\
make;\
cd -

7. make order, for example, run anymote.mk, polo.mk first

LOCAL_PATH:= $(call my-dir)
include $(call all-makefiles-under, $(LOCAL_PATH))

include $(ANDROID_BUILD_TOP)/vendor/company/anymote-protocol/java/anymote.mk
include $(ANDROID_BUILD_TOP)/vendor/company/google-tv-pairing-protocol/java/polo.mk

8. what is different with all-subdir-makefiles and all-makefiles-under

all-subdir-makefiles: 表示“當前目錄下沒有需要編譯的文件,請向子目錄深入”,是告訴編譯器繼續向目錄深處遞迴的一種寫法。
all-makefiles-under: 為當前目錄下有文件需要編譯,而且在當前目錄下還有子目錄,子目錄中也有文件需要編譯,同樣也要包含告訴編譯器在編譯完當前目錄下的文件後,繼續向子目錄深入的語句。

2013年5月24日 星期五

Android Resource

How get Resource

1. getResources().getString(android.R.string.cancel);
2. Resources.getSystem().getString(android.R.string.cancel);
3. getString(android.R.string.cancel);

The first and the third ones are using "context." invisibly. So, very often (in static members or out of activity members) you can't use them directly, unless you pass context or resource as a static variable or as a parameter into your scope. But the second one

Resources.getSystem().getString(android.R.string.cancel)
You can use ABSOLUTELY EVERYWHERE in your application, even in static constants declaration! But for system resources only


GetLocals


Resources.getSystem().getassets().getLocals()
getAsset() 是從下列路徑取得,不是從frameowrks-res.apk中取得
framework/base/core/java/android/content/res/AssetManager.java
framework/base/core/jni/android_util_AssetManager.cpp
framework/base/include/utils/AssetManager.h
framework/base/libs/utils/AssetManager.cpp
framework/base/libs/utils/ResourceTypes.cpp




2012年7月9日 星期一

重建Ubuntu MBR

Ubuntu的MBR不見了,只剩下windows的MBR
1. 準備Ubuntu LiveCD
2. 利用Ubuntu LiveCD開機
3. 進入terminal
    # cd /
    # sudo -s -H
    # mount -t ext4 /dev/sda6 /mnt      ->sda6為Ubuntu所在的磁區
    # mount -t proc proc /mnt/proc
    # mount -t sysfs /sys /mnt/sys
    # mount -o bind /dev /mnt/dev
    # chroot /mnt /bin/bash         ->切換 root到硬碟上的Ubuntu

如果不知道Ubuntu在那一個磁區,查詢硬碟上的partition資訊    
    # ls -l /dev/disk/by-label
    # fdisk -l

安裝grub2
    # aptitude install grub2 grub-pc

如果已經安裝了grub,先移除
    # apt-get pruge grub

更新grub
   # update-grub
   # grub-install /dev/sda
   # reboot
恢復原先Ubuntu的grub

如果開機後,沒有任何開機選單,只出現
  grub >  -> 這代表沒有grub menu
  grub > find /boot/grub/core.img
  grub > root (hd0, 5)    -> root (hdx, y) previous command will tell you the x, y in this case is (hd0, 5)
  grub > kernel /boot/grub/core.img
  grub > boot
  現在可以進入Ubuntu 系統

如果開機會直接進入Ubuntu,沒有menu可以選擇要那個OS
   # update-grub
  讓 grub自動建立menu.list, 檔案位置在/boot/grub/menu.list
  grub2沒有menu.list,是grub.cfg, 檔案位置在/boot/grub/grub/cfg

2012年7月6日 星期五

git 相關

git error
fatal: unable to create 'abc/.git/index.lock' File exist.
If no other git process is currently running, this probably means a git process crashed in this repository earlier, Make sure no other git process is running and remove the file manual to continue.

Solution:
remove ../.git/index.lock
ex: rm -r ./.git/index.lock

git command
1. repo sync
2. repo start new_branch . (新增 branch)
3. git branch (確認branch狀態)
4. git branch -d branch_name( 刪除branch)
5. git diff > diff.txt ( 將有修改的檔名的不同處存下來)
6. git status (顯示所有有動變的檔案)
7. git commit -a
8. git show HEAD( show上一個commit 資訊)
9. repo upload . (實際上傳到server)

如果還要修改但還沒merge
1 git add .
2. git commit --amend
3. repo upload .

切換到別的branch
git checkout branch_name

將存下的 patch加入source code 之中(打 patch)
patch -R p1 < xxx.patch --dry-run

將檔案回歸到原始(server)狀態
git checkout -- filename

新增一個檔案
git add -p file_name(只加這一個檔案,有時路徑下有很多檔案修改,但只想上傳這一個)

新增 folder
git add folder_name(先新增folder, 才會出現此folder下的檔案)
PS. 如果新增一個空資料夾,必須在此資料夾加一個隱藏檔

取得git log並格式化
git log --pretty=format:"%h%x09%an%x09%ad%x09%s"