2011年1月20日 星期四

[Tips] 基本的備份指令

當然,*nix上面有很多指令都可以做壓縮/打包的,也是複雜到不行
可是大部分我在用的大概就是tar或gzip或rar或zip,但今天遇到一個用上述方法都會出現的問題,只好改用cpio備份

Archival
$ find | cpio -ov > [file|device]
Extraction
$ cpio -idv < [file|device]
NAME
       cpio - copy files to and from archives

SYNOPSIS
       cpio {-o|--create} [--verbose] {-i|--extract} 

2011年1月11日 星期二

[Android] Compile Android module

1.add environment variables
$ cd /path/to/android
$ cd build
$ . envsetup.sh
$ help
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- croot:   Changes directory to the top of the tree.
- m:       Makes from the top of the tree.
- mm:      Builds all of the modules in the current directory.
- mmm:     Builds all of the modules in the supplied directories.
- cgrep:   Greps on all local C/C++ files.
- jgrep:   Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir:   Go to the directory containing a file.

Look at the source to view more functions. The complete list is:
add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help isviewserverstarted jgrep lunch m mm mmm pid printconfig print_lunch_menu resgrep runhat runtest setpaths set_sequence_number set_stuff_for_environment settitle smoketest startviewserver stopviewserver systemstack tapas tracedmdump

2.using mmm to compile module under root path
$ cd /path/to/android
$ mmm external/ping
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.2.1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=MASTER
============================================
target Non-prelinked: ping (out/target/product/generic/symbols/system/bin/ping)
Install: out/target/product/generic/system/bin/ping

2.or using mm to compile module under module path
$ cd /path/to/android
$ cd development/samples/NotePad
$ mm
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.2.1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=MASTER
============================================
Copying: out/target/common/obj/APPS/NotePad_intermediates/classes-full-debug.jar
Install: out/target/product/generic/system/app/NotePad.apk
Copying: out/target/common/obj/APPS/NotePadTests_intermediates/classes-full-debug.jar
Install: out/target/product/generic/data/app/NotePadTests.apk

2.or using make to compile module under root path
$ cd /path/to/android
$ make Phone
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.2.1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=MASTER
============================================
Install: out/host/linux-x86/bin/aapt
Install: out/host/linux-x86/bin/aidl
Copying: out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes-full-debug.jar
Install: out/host/linux-x86/framework/dx.jar
Install: out/host/linux-x86/bin/dx
Copying: out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes-full-debug.jar
Copying: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar
Copying: out/target/common/obj/APPS/Phone_intermediates/classes-full-debug.jar
Install: out/host/linux-x86/framework/signapk.jar
Install: out/host/linux-x86/bin/zipalign
target Package: Phone (out/target/product/generic/obj/APPS/Phone_intermediates/package.apk)
 'out/target/common/obj/APPS/Phone_intermediates/classes.dex' as 'classes.dex'...
Install: out/target/product/generic/system/app/Phone.apk

[Tips] Ubuntu安裝完成後常裝的軟體

最近常不小心砍掉我的家目錄,有些東西重複在做蠻討厭的,就把一些東西放到雲端上紀錄吧 XDDD
# development tool
sudo apt-get install sun-java5-jdk sun-java5-plugin sun-java6-jdk sun-java6-plugin eclipse   # java
sudo apt-get install gcc-4.1 gcc-4.3 gcc-4.4 g++-4.1 g++-4.3 g++-4.4 autoconf automake       # c/c++
sudo apt-get install libgtk2.0-dev libwebkit-dev                                             # gtk
sudp apt-get install gtkterm minicom putty                                                   # serial port utility
sudo apt-get install meld kdiff cscope ctags                                                 # programing utility
sudo apt-get install bootchart pybootchartgui                                                # boot analysis utility
sudo apt-get install ant maven2                                                              # java project utility
sudo apt-get isntall gpm                                                                     # deivce driver
sudo apt-get install procmail uboot-mkimage                                                  # uboot

# kernel
sudo apt-get install fakeroot build-essential makedumpfile kernel-package crash kexec-tools makedumpfile kernel-wedge build-dep dos2unix squashfs-tools                   

# data recovery
sudo apt-get install e2fslibs e2fslibs-dev e2fsprogs
Download extundelete

# android
sudo apt-get install git-core gitweb gnupg flex bison gperf build-essential zip curl  zlib1g-dev gcc-multilib g++-multilib x11proto-core-dev libx11-dev libncurses5 libncurses5-dev libc6-dev libreadline-dev libreadline6-dev
sudo apt-get install bison flex gettext patch build-essential texinfo                        # toolchain

# system administration
sudo apt-get install vncviewer gtkvncviewer xtightvncviewer                                  # vnc
sudo apt-get install ncdu htop                                                               # system utility
sudo apt-get install chkconfig sysv-rc-conf                                                  # service utility
sudo apt-get install vsftpd samba smbfs samba-tools smbclient openssh-server                 # service
sudo apt-get install filezilla wget bareftp ftp gftp-common gftp gftp                        # ftp
sudo apt-get install wireshark nmap                                                          # security

# emulator
sudo apt-get install qemu uml-utilities                                                      # qemu
sudo apt-get install busybox                                                                 # busybox
sudo apt-get install virtualbox                                                              # virtualbox
sudo apt-get install wine                                                                    # win32 emulator
Ubuntu Software Center -> PlayOnLinux                                                        # PlayOnLinux

# utility
sudo apt-get install shutter smartmontools preload prelink localepurge apt-file              # misc
sudo apt-get install pdfedit gs pdftk                                                        # pdf
$ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=firstANDsecond.pdf -dBATCH first.pdf second.pdf usage

# lamp
sudo apt-get install libtool libltdl-dev libgnutls-dev libssl-dev fig2ps libgpg-error-dev libgpg-error0 libexpat1 libexpat1-dev libxml2 libxml2-dev libgcrypt11 libgcrypt11-dev libmcrypt4 libmcrypt-dev mcrypt libt1-5 libt1-dev libfreetype6 libfreetype6-dev libjpeg62 libjpeg62-dev libxpm4

# Qt4
sudo apt-get install libqwt5-qt4 libqwt5-qt4-dev pyqt4-dev-tools python-qt4 python-qt4-dev python-qwt5-qt4 qsource-highlight libqt4-dbg libqt4-dbus libqt4-declarative libqt4-designer libqt4-dev libqt4-gui libqt4-help libqt4-network libqt4-script libqt4-scripttools libqt4-sql-sqlite libqt4-webkit-dbg libqt4-xml libqt4-xmlpatterns qt4-demos qt4-demos-dbg qt4-designer qt4-dev-tools qt4-doc qt4-doc-html qt4-qmake libqt4-assistant libqt4-core libqt4-webkit qt4-qtconfig

# development lib
sudo apt-get install emacsen-common exiv2 exuberant-ctags gdebi-kde graphviz install-package kate kdebase-runtime kdebase-runtime-data kdelibs-bin kdelibs-data kdelibs4c2a kdelibs5 kdelibs5-data kdepimlibs-data kdepimlibs5 kdesudo kpackagekit kubuntu-debug-installer libakonadiprivate1 libattica0 libavahi-qt3-1 libboost-program-options1.40.0 libclucene0ldbl libdbusmenu-qt2 libexiv2-6 libiodbc2 liblua50 liblualib50 libmng1 libmodplug0c2 libmpcdec3 libmysqlclient16 libpackagekit-glib2-12 libpackagekit-qt-12 libphonon4 libplasma3 libpolkit-qt-1-0 libqca2 libqt3-mt libqt4-assistant libqt4-dbus libqt4-designer libqt4-help libqt4-network libqt4-opengl libqt4-qt3support libqt4-script libqt4-scripttools libqt4-sql libqt4-sql-mysql libqt4-svg libqt4-test libqt4-webkit libqt4-xml libqt4-xmlpatterns libqtcore4 libqtgui4 libsoprano4 libssh-4 libstreamanalyzer0 libstreams0 libxcb-shape0 libxcb-shm0 libxcb-xv0 libxine1 libxine1-bin libxine1-console libxine1-misc-plugins libxine1-x mysql-common oxygen-icon-theme packagekit packagekit-backend-apt phonon phonon-backend-xine plasma-scriptengine-javascript polkit-kde-1 python-kde4 python-packagekit python-qt4 python-sip shared-desktop-ontologies software-properties-kde soprano-daemon ttf-dejavu ttf-dejavu-extra update-manager-kde virtuoso-nepomuk libelf-dev libdw-dev asciidoc binutils-dev

[Vim] .vimrc

筆記一下我目前在用的.vimrc

"=== basic ==="
filetype plugin on        "plugin enable
filetype indent on        "auto indent

"=== encoding ==="
set encoding=utf-8        "enc
set fileencodings=utf-8,gbk,big5,cp950,gb18030,gb2312   "fenc
set termencoding=utf-8    "tenc

"=== editing ==="
syntax on
set nocompatible
set backspace=indent,eol,start
set shiftwidth=2
set tabstop=2
set softtabstop=2
set expandtab
set ic                    "ignorecase
set ru                    "position
set nu                    "line number
set hls                   "hlsearch
set confirm
set wrapscan
set history=1000
set laststatus=2
set statusline=%4*%<\%m%<[%f\%r%h%w]\ [%{&ff},%{&fileencoding},%Y]%=\[Position=%l,%v,%p%%]

"=== buffer ==="
set clipboard+=unnamed

"=== color scheme ==="
set t_Co=256
colorscheme blackbeauty   "for java
colorscheme leo           "for c/c++

"=== vim ==="
autocmd FileType java runtime! autoload/javacomplete.vim
autocmd Filetype java setlocal omnifunc=javacomplete#Complete
autocmd Filetype java set completefunc=javacomplete#CompleteParamsInf
inoremap   
inoremap   

"=== tab ==="
nmap tc :tabnew
nmap te :tabedit
nmap tm :tabmove
nmap tk :tabclose

"=== folding ==="
set foldenable
set foldlevel=10000

2011年1月6日 星期四

[HTML5] HTML5 Rocks

2011年應該是HTML5開始有搞頭的一年...
前一陣子從Ericsk大大那邊看到的任天堂模擬器

昨天在GUTGGasolin介紹Knights of the round,還佛心的掛在google code

看來我應該想想看怎麼用websocket完成我的小遊戲了...

順手記一下有關的資源
* HTML5Rocks
* Dive Into HTML5
* HTML 5 Demos and Examples
* HTML5 Doctor

[Android] Create a fake character device driver

1.download Android kernel, details in here

2.get the current kernel configuration from the emulator
$ adb pull /proc/config.gz .
$ gunzip config.gz
$ mv config .config

3.modify .config file
$ vim .config
CONFIG_MODULES=y

4.modify kernel Makefile
$ vim Makefile
# Use --build-id when available.
#LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
#           $(call ld-option, -Wl$(comma)--build-id,))

5.compile kernel
$ make mrproper
$ sudo make ARCH=arm CROSS_COMPILE={/path/to/android}/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-

6.get kernel image
Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready

7.create fake driver, devone.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>

MODULE_LICENSE("Dual BSD/GPL");

static int devone_devs = 1; /* device count */
static int devone_major = 0; /* dynamic allocation */
static int devone_minor = 0;
static struct cdev devone_cdev;

ssize_t devone_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
{
  int i;
  unsigned char val = 0xff;
  int retval;

  for (i = 0 ; i < count ; i++) {
    if (copy_to_user(&buf[i], &val, 1)) {
      retval = -EFAULT;
      goto out;
    }
  }

  retval = count;
out:
  return (retval);
}

struct file_operations devone_fops = {
  .read = devone_read,
};

8.write fake driver Makefile
KERNELDIR={/path/to/android}/kernel
PWD := $(shell pwd)
obj-m := devone.o
modules:
  make -C $(KERNELDIR) M=$(PWD) modules
clean:
  rm -rf *.o *~ core.depend .*.cmd *.ko *.mod.c .tmp_versions modules.* Module*

9.compile kernel module
$ sudo make ARCH=arm CROSS_COMPILE={/path/to/android}/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-

10.start the emulator with our kernel
$ emulator -avd {name} -partition-size {number} -kernel {/path/to/kernel/zImage}

11.put busybox into emulator
$ adb push busybox /system/bin
$ adb shell chmod 755 /system/bin/busybox

12.put ko into emulator
$ adb remount
$ adb push devone.ko /system/lib

13.insert kernel module in emulator
$ adb shell
# insmod devone.ko
# lsmod
devone 1784 - - Live 0xbf000000

14.check the major number of devone
# cat /proc/devices
...
136 pts
252 devone
253 ttyS
...

15.insert the device node of devone
# /system/bin/busybox mknod /dev/devone c 252 0
# /system/bin/busybox ls /dev/
...
device-mapper       tty20               tty51
devone              tty21               tty52
eac                 tty22               tty53
...
# /system/bin/busybox ls -al /dev/devone
crw-rw-rw-    1 0        0        252,   0 Jan  4 05:33 /dev/devone

reference:
* 實作一個假的character driver 在emulator上跑
* Writing your first kernel module

2011年1月3日 星期一

[Vim] Color scheme

用Vim寫程式時通常會對原有的配色不太滿意,尤其是在切換不同的程式語言時會更有這樣的需求,強大的Vim有colorscheme這樣的好物

googlecode上有個專案已經幫我們整理好許多可用的color scheme,比如說寫C/C++的,或是寫Java的都可以在這邊找找看

使用/安裝color scheme相當簡單,
1.先建立存放顏色的目錄
$ mkdir ~/.vim/colors
2.看到喜歡的,下載{COLOR_SCHEME}.vim到colors目錄下
$ mv /path/to/{COLOR_SCHEME}.vim ~/.vim/colors
3.修改Vim顏色設定,我目前是用blackbeautyleo
$ vim ~/.vimrc
set t_Co=256              "support 256 colors
colorscheme blackbeauty   "blackbeauty is the name of color scheme
colorscheme leo           "leo is the name of color scheme
4.在Vim中使用
:colorscheme COLOR_SCHEME

Bye Bye 2010

2010年快結束了,今年發生一件大事,還有幾件小事,雖然最近運氣不太好,但強者我朋友要我強調總和來說還是旺的...
2011年希望一切順利,眾家親朋好友兄弟姊妹都能平安喜樂,比今年還好

Bye Bye 2010