2012年8月2日星期四

vim tips

sp [filename]

ctrl+w+j/k

for 2 files copy and paste

2012年6月21日星期四

FEDORA16 /tmp

sudo /usr/sbin/tmpwatch -afv 3 /tmp

explanation is here in chinese

2012年3月19日星期一

inline and macro difference

First let's talk about the difference between macro and function

1. macro is done before compile, that's also why it is called pre-compile. So first of all, we use macro body to replace macro name. Then we do compile.

On the other hand, function is executed after compile. Actually, it is called in the process of execution. So we can see that macro take compile time and function take execution time.

2. Because we need to "call" function, we need to pay for some resource(cost). We need to keep the state, and then go into the called function, after "call" finish, we need to go back the function which call others. Then we need to recover state.

On the other hand, all these operation above will never happen in macro. What macro do is just string replacement(string! not other type). So the argument of macro will not occupy memory space. But function argument need memory space, since argument is variable info transfer. Argument is function's local variable. Also, we do not need to do computation for macro argument. Function is give the value of argument. Here, we use value which will lead to computation.

3. As we said above, macro is string replacement. But argument of function can be any type.
-----------------

What inline do is to "embed" its code to the function which call it. So we can save cost to call it.
We need be careful about inline function must be very simple. No loop, if else, etc.

PS: some compiler will handle simple function as inline automatically. Some complex function, even you declare it is inline, compile will not do so.
---------

NO grammar examination for MACRO! Inline will have grammar exam during compiling. That is the reason why most programmer choose inline but not macro.

2012年3月17日星期六

跟着环境走 放下身段

今天看一个视频,有两段话记下:
-------------------

一段是说一个女老板在日本开牛肉面店:

人要跟着环境走,跟着环境走不是说要顺流而下,而是你要跟周围的环境取得一个和谐的关系,你做什么就要像什么。

一段是一个师傅教咏春评价徒弟:

他学拳有少许障碍,就是爱面子。学拳有时,不管学拳其他东西也一样。如果不放下身段,很难有长足的进步。你不愿服输,如何能赢?
-----------------------
想到自己最近总是怀疑自己的能力,最终还是会调试出来。既然是自己选的路,不管自己的先天条件有多少,都不应该怀疑自己,如果连自己都不相信,遇到困难就会很沮丧而退缩。

而学东西的时候总是觉得自己工作过,尽管心底知道这和现在学的关系不大,但遇到问题总是不好意思去及时问别人,失去好多学习的机会。积少成多,自然不会出色。

熟能生巧,触类旁通,这能达到这个境界是要付出时间和精力的。另外,就是要学会集中注意力,这点也很重要,注意力意味着效率。

2012年2月26日星期日

fedora16 software

Fedora16 shortcut bug:

workaround:

gconftool-2 --type=string --set "/desktop/gnome/applications/terminal/exec" "gnome-terminal"

solution:

sudo yum install libgnome-devel.i686 gnome-devel-docs.noarch

-----------------------------------------------------------------------------------------

User is not in the sudoers file

change file /etc/sudoers

su

xxxx

visudo

add command below at the end:

username ALL=(ALL)ALL

------------------------------------------------------------------------

yum install libreoffice-base libreoffice-core libreoffice-calc libreoffice-impress libreoffice-writer libreoffice-langpack-en

------------------------------------------------------------------

Flashplayer

Flash player

  64bit:

  su yum install wget cd /tmpwget http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_2_p3_64bit_linux_111710.tar.gztar xzvf flashplayer10_2_p3_64bit_linux_111710.tar.gzmv /tmp/libflashplayer.so /usr/lib64/mozilla/plugins/

  32bit:

  su

rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm

  rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux

  yum update

  yum install flash-plugin

--------------------------------------

sudo yum install vlc

2012年2月25日星期六

X220 WIN7 & FEDORA 16

PRE:
A. prepare flash disk(at least 4G) to boot
and install fedora
B. need internet connection during fedora installation.
C. clear enough disk in windows
D. download
http://download.fedoraproject.org/pub/fedora/linux/releases/16/Fedora/i386/iso/Fedora-16-i386-DVD.iso
or
http://download.fedoraproject.org/pub/fedora/linux/releases/16/Fedora/x86_64/iso/Fedora-16-x86_64-DVD.iso
------------------------------------------------------------------
START:

1. download grubinst-1.1-bin-w32-2008-01-01 http://download.gna.org/grubutil/

2. download grub4dos-0.4.4 http://download.gna.org/grub4dos/

3. run grubinst_gui.exe(administrator mode), choose your flash disk, installation, u should see a window says "The MBR/BS has been successfully installed"

4. unzip grub4dos-0.4.4, copy
grldr and menu.lst to / of flash disk

5.copy
Fedora-16-Beta-i386-DVD.iso, initrd.img and vmlinux(these two are in iso, u need to extract them) to / of flash disk. So now flash disk have 5 files.

6. add commands below at the end of menu.lst:

title F16 setup

root (hd0,0)

kernel /vmlinuz root=/dev/hda1

initrd /initrd.img

----------------------------------------------------------------

ps: initrd.img might be initrd when extract from iso, do not care about that, do not add .iso.

-------------------------------------------------------------------

7. reboot, F12, choose to boot from flash disk

8.choose F16 setup

9. next, when you choose the installation storage type, I choose the last one, create blablabla, then you can cut your disk by yourself, make sure you backup your data first.

10. next next.....choose software development if you want to do some coding in fedora...

11. next.................

-------------------------------------------------------------------------------------------------------------

swap:2G

/:5G ext4

/home:30G ext4

/usr/locale:20G ext4

/tmp:1G ext4

/var:2G ext4

/boot:200M ext3

------------------------------------------------------------------------------------


Now you can go to a party or watch Big Bang Theory or White Collar(Moz is soooo cooool)

enjoy :)

2012年2月21日星期二

LOCK CV

OS161 PLATFORM

LOCK IMPLEMENTATION


CV(condition variable) is for multi thread use. wait-wakeup
eg: T1, T2, T1 need test_cond(bool type) is true to be run. And test_cond is controlled by T2. In this case, how to achieve this?

Method 1:

T1 is sleeping and wake up every 5ns (arbitrary, can be any time period) come to examine the value of test_cond,if it is false, keep sleep; otherwise, start to run.

Method2:

T1 call cond_wait and wait when test_cond is false, when the value of test_cond is changed, T2 will call cond_signal to wake up T1(which is sleep & busy waitng), tell T1: hi, the value of test_cond is changed. T1: got you, I am going to run.

We can see the scenario of the bathroom on a plane, T1(old lady)and T2(old man) are two people, T2 is in the bathroom, T1 want to use it...So T1 stand up again and again to see if the bathroom is available or not.(if there is no light to indicate that). That is a waste, it waste T1's energy , it influence the beautiful waitress to look after her, it waste other customers' energy to see her around.

So here we go,.we have a light outside the bathroom, when T2 is in the bathroom, the light is red, the lady can go back to the seat and sleep, when T2 is done with his work, he will turn the light to green, and the light will call old lady(advanced light), and old lady can use it now.

here is the chinese version.



here and here is the comparison between semaphore, mutex and cv





---------------------------------------------------


-------------------------------------


---------------------------------------------------