Wednesday, October 15, 2008

Great Article on Linux dd command

Author: AwesomeMachine @ LinuxQuestions.org

original link

I followed the instructions to create an image for my windows drive. It's killing me to reinstall xp.

creating backup image
dd if=/dev/hda1 | bzip2 > /home/winxp.image.bz2
restoring image
dd if=/home/winxp.image.bz2 | bunzip2 | dd of=/dev/hda1

Compiz Fusion: a not recommend configuration

UPDATE: Hooooray!! The border is on after I add the `decoration` plugin to the very last line of /usr/bin/compiz-start. Also I change this file to use `emerald` instead of `gtk-window-decorator` and it works!!!! So I know one thing, can't fully trust `ccsm` and always turn to reliable command line. Oh, if `emerald --replace` has no output, no error, it's probably means it's working. Compiz fusion rocks! Even better if I can have a better video card~



Compiz Fusion is not working perfectly on my gentoo. First of all, no window border. After several days googling, I gave up. A note, if `emerald --replace` or `gtk-window-decorator --replace` is working fine, then that's the compiz configuration problem. My case is that these two commands does nothing, no output, no change, no error. But I can live with that.

Second problem that took me a long time is the configuration. The setting in `ccsm` does not take effect and even cause a compiz segmentation error. Then I used a brute force configuration. Not recommended, only for desperate people.

  1. gain root privilege
  2. use `ccsm` to determine which plugins should be needed, the plugin name can be found in Preferences | plugins list.
  3. modify the last line of /usr/bin/compiz-start, delete "gconf", add all the plugins you want to enable. Backup before change.
  4. modify the corresponding xml files in /usr/compiz to change the behavior, remember to make backup file before change. And be careful.
  5. add all the compiz fusion related packages to package.mask to prevent from any modificaton.
  6. compiz-start and good luck. Check the error output in case the xml format is messed up.


APPENDIX: /etc/X11/xorg.conf
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "aticonfig-Screen[0]" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "TouchPad" "AlwaysCore"
InputDevice "Mouse1" "CorePointer"
EndSection

Section "Files"

FontPath "/home/fonts"
FontPath "/usr/share/fonts/100dpi"
FontPath "/usr/share/fonts/cyrillic"
FontPath "/usr/share/fonts/wqy-bitmapfont"
FontPath "/usr/share/fonts/75dpi"
FontPath "/usr/share/fonts/default"
FontPath "/usr/share/fonts/misc"
FontPath "/usr/share/fonts/Type1"
FontPath "/usr/share/fonts/ttf-bitstream-vera"
FontPath "/usr/share/fonts/corefonts"
FontPath "/usr/share/fonts/zh-kcfonts"
FontPath "/usr/share/fonts/util"
# FontPath "/usr/local/share/fonts"
# FontPath "/usr/X11R6/share/fonts"

EndSection

Section "Module"
Load "freetype"
# Load "xtt"
Load "extmod"
Load "glx"
Load "dri"
Load "dbe"
Load "record"
Load "xtrap"
Load "type1"
Load "speedo"
EndSection

Section "InputDevice"
Identifier "Mouse1"
Driver "mouse"
Option "Protocol" "IMPS/2"
Option "Emulate3Buttons"
Option "ZAxisMapping" "4 5"
Option "Device" "/dev/input/mice"
EndSection

Section "InputDevice"
Driver "synaptics"
Identifier "TouchPad"
Option "Device" "/dev/input/mouse0"
Option "Protocol" "auto-dev"
Option "LeftEdge" "1700"
Option "RightEdge" "5300"
Option "TopEdge" "1700"
Option "BottomEdge" "4200"
Option "FingerLow" "25"
Option "FingerHigh" "30"
Option "MaxTapTime" "180"
Option "MaxTapMove" "220"
Option "VertScrollDelta" "100"
Option "MinSpeed" "0.09"
Option "MaxSpeed" "0.18"
Option "AccelFactor" "0.0015"
Option "SHMConfig" "on"
EndSection


Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbModel" "pc104"
Option "XkbLayout" "us"
EndSection

Section "Monitor"

### Comment all HorizSync and VertSync values to use DDC:
Identifier "Monitor0"
HorizSync 31.5 - 64.3
VertRefresh 60.0 - 90.0
DisplaySize 331.8 207.3 ## for 15.4", DPI=98
EndSection

Section "Monitor"
Identifier "aticonfig-Monitor[0]"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
EndSection

Section "Device"
Identifier "Card0"
Driver "radeon"
Card "ATI Graphics Xpression"
EndSection

Section "Device"
Identifier "aticonfig-Device[0]"
Driver "fglrx"
# BusID "PCI:2:0:0"
Option "DesktopSetup" "horizontal"
Option "VideoOverlay" "on"
Option "UseFastTLS" "2"
Option "EnablePrivateBackZ" "on"
Option "DynamicClocks" "on"
Option "XAANoOffscreenPixmaps" "true"
Option "TexturedVideo" "On"
Option "DRI" "true"
Option "MonitorLayout" "LVDS,AUTO" #Enable Externel Monitor
EndSection

Section "DRI"
Mode 0666
EndSection

Section "Extensions"
Option "Xvideo" "Enable"
Option "Composite" "Enable" ## critical
EndSection

Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1280x800" "1024x640"
EndSubSection
EndSection

Section "Screen"
Identifier "aticonfig-Screen[0]"
Device "aticonfig-Device[0]"
Monitor "aticonfig-Monitor[0]"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1280x800" "1024x640"
EndSubSection
EndSection

Section "ServerFlags"
# Option "DontVTSwitch" "True" # kills the Ctrl+Alt+F(1-6) virtual terminal switch commands
# Option "DontZap" "True" # kills the Ctrl+Alt+Backspace command
EndSection


Sunday, October 12, 2008

Gentoo troubleshootings

After 3 and half days. I got gentoo upgraded on my acer 5102WLMi. Gentoo is a great distro. Love it. Now audio is working, but still not camera.

The Name:
The Gentoo species is the fastest swimming penguin.
Hardware specification
    1. Processors : AMD Turion 64x2 TL50 (1.60GHz, 512K L2 cache)
    2. Chipset: ATI RS480
    3. Displays: 15.4" WXGA (1280 x 800 resolution)
    4. Graphics Card: ATI Radeon Xpress 1100
    5. Optical Drive: DVDRW
    6. Sound Card: integrated, snd-hda-intel, realtek
    7. Wireless Networking: Atheros AR5005G 802.11abg
    8. MMC reader: ENE Technology Inc SD/MMC Card Reader
    9. I/O Ports : 3 USB 2.0, Audio jacks, 15-pin monitor connector, PCMCIA slot.
Useful links
  1. Gentoo documentation
  2. audio setup: http://gentoo-wiki.com/HARDWARE_Acer_Aspire_5102WLMi
  3. articles with gentoo tag: http://kunxi.org/
  4. Google
Notes:
  1. when upgrading, first emerge update all packages, resolve blockings(uninstall or upgrade, if circular blocking, --nodep). Then revdep-rebuild.
  2. use "equery" to look at installed packages
  3. gcc-config, kernel-config, etc to choose from different slots.
  4. make.conf, package.keywords, package.mask, package.unmask, package.use, ...
  5. if use "startx", add "gnome-session" to .xinitrc, else X will not load gnome.
  6. firefox+flash

    sudo echo "net-www/netscape-flash" >> /etc/portage/package.unmask
    sudo emerge -av netscape-flash nspluginwrapper

  7. firefox+mplayerplug-in (UPDATE: "emerge adobe-flash" will do the job)
    sudo echo "net-www/mplayerplug-in -firefox divx quicktime realmedia wmp" >> /etc/portage/package.use
    ## Make sure no browser running
    sudo emerge -av mplayerplug-in

    ln -s /usr/lib/nsbrowser/plugins/mplayerplug-in.so $HOME/.mozilla/plugins/mplayerplug-in.so
  8. cp936 support is not default in kernel, so need to add support in kernel.
    File Systems --->
    DOS/FAT/NT Filesystems --->
    Native Language Support
  9. teTeX set up, "latex" does not come with the package automatically, seems there are a lot of high-level TeX users.
    emerge -av tetex
    texconfig confall ## check all the output
    texconfig rehash
    texconfig init ## will generate all other binaries: latex, omega,...
    emerge -av app-emacs/auctex ## a must-have package for emacs+latex
    emerge -av emacs-update ## as the package suggest
  10. use TuxOnIce to do hibernate and hibernate-ram, just follow this HOWTO. Work like a charm. ATTENTION: if the lid-and-battery script is used, DO NOT put the code directly in `/etc/conf.d/local.conf'. It will run forever and will not act as a child. Instead, paste the script code into a file, say `/etc/lid_battery_suspend', do a `chmod u+x /etc/lid_battery_suspend.sh', and then add one line `/etc/lid_battery_suspend.sh &' to `/etc/conf.d/local.conf'.
    HOWEVER, after one suspend/hibernation, this script will be stopped and not be loaded. An alternative way is to let acpi take care of this. Look at /etc/acpi/events and change the actions for lid and battery. Then restart acpid service. Well, you take the risk.
  11. clean gnome desktop, use gconf-editor (looks like register table in Windows), find apps \ nautilus \ desktop, uncheck, uncheck, uncheck. Nice pure wallpaper.
  12. HOWTO take compiz screen shot: open gimp, go to File > Aquire > Screenshot. You can set a delay of however many seconds to give yourself time to get the cube in the right position. Hold it there until the PC's speaker beeps.
  13. HOWTO_NTP, NTP (Network Time Protocol) is used to synchronize your system's time with an online server.
    echo "net-misc/ntp caps" >> /etc/portage/package.use
    emerge -av ntp
    vi /etc/conf.d/ntp-client # can change the OPTS, change time servers
    /etc/init.d/ntp-client start # start sync
    #rc-update add ntp-client boot # optional
    ntp-client is only a wrapper of ntpdate program. If need to sync automatically, need to start ntpd. Ahh, before setting NTP, check /etc/localtime, if not in the right time zone, copy or link corresponding zone file from /usr/share/zoneinfo/.
  14. (Nov 16,2008) Well, alsa packages(alsa-driver, alsa-lib, alsa-headers, alsa-util) 1.0.18 update is not working and I cannot figure out why, the sound card can not be found. So I downgraded back to 1.0.17, but the alsa-lib remains 1.0.18. And it's back to work! Mask them at once.
xorg-x11 troubleshooting:
  1. "xauth: error in locking authority file /home/usrname/.Xauthority", will result in a dark screen with cursor usable after "startx", but nothing shows up. And the command window keeps prompting:
    xlib: connection to :0.0 refused by X server
    xlib: no specified protocol
    The solution is to use
    xauth -b quit
    to break existing lock, also check the permission of .Xauthority.
  2. ati-drivers
    fglrx(0): incompatible kernel module .......
    update ati-driver, even with the ~ keyword
  3. cannot startx, the error shows
    Synaptics DeviceOn Called
    Can't initialize SocketServer
    Failed to initialize Panel Agent

    It's probably because you have deleted or modified the /tmp directory, please check the permission of this directory, or just do a sudo chmod 777 /tmp.
hibernate troubleshooting:
  1. The Problem: hibernate works under text mode. But under X mode, it resumes at the "Going Atomic" step and gives an error saying
    another suspend already in progress?
  2. The Solution:
    The error in 'Going Atomic' is probably because you need to increase the
    allowance we make for drivers allocating memory during the atomic copy.
    Assuming you're using the hibernate script, this is done by editing
    /etc/hibernate/suspend2.conf. If you cat /sys/power/tuxonice/debug_info
    after an attempt at hibernating, the last line will say something like:

    - Extra pages: 1069/500.

    This means that 1069 pages were needed, but we only allowed for 500. In
    that case, you'd want to add something along the lines of

    ProcSetting extra_pages_allowance 2000

    to /etc/hibernate/suspend2.conf.

    (courtesy from http://lists.tuxonice.net/pipermail/tuxonice-users/2008-February/000202.html)

Wednesday, October 08, 2008

VIM tricks and tips

Efficient Editing With vim

Use Vim Like A Pro


Two important concepts in
vi:

marks and registers.

marks: start with ` and '
ma        set mark '''a''' at current cursor location
'a jump to line of mark a (beginning of line)
`a jump to position of mark a
d'a delete from current line to line of mark a
d`a delete from current cursor position to position of mark a
c'a change text from current line to line of mark a
y`a yank text to unnamed buffer from cursor to position of mark a
'' jump back (to line where jumped from)
`0 jump to position in last file edited (when exited Vim)
`` jump back (to position where jumped from)
:marks list all the current marks

registers start with ", use "* register to communicate with system clipboards.
There are nine types of registers:
1. The unnamed register ""
2. 10 numbered registers "0 to "9
3. The small delete register "-
4. 26 named registers "a to "z or "A to "Z
5. four read-only registers ":, "., "% and "#
6. the expression register "=
7. The selection and drop registers "*, "+ and "~
8. The black hole register "_
9. Last search pattern register "/

ATTENTION: 26 named registers, upper case is used to append contents, not different registers.

registers manual

fast notes for registers:

When you copy and cut stuff, it gets saved to registers. You can pull stuff from those registers at a later time.

 :reg     - show named registers and what's in them
"5p - paste what's in register "5

You can also record a whole series of edits to a register, and then apply them over and over.

 qk       - records edits into register k
(q again to stop recording)
@k - execute recorded edits (macro)
@@ - repeat last one
5@@ - repeat 5 times

"kp - print macro k
(e.g., to edit or add to .vimrc)
"kd - replace register k with what cursor is on

Tips And Tricks

The * and # Keys

In normal mode you can use * and # to search for the word under the cursor. * search forwards, # backwards.

The . Key

Also useful is the . key. In normal mode it repeats the last change. Very useful for XML editing and where you have to do similar stuff.

The % Key

Pressing the % key in normal mode while being on a parenthesis or a similar construct jumps to the opposite parenthesis. There are a couple of plugins that extend that functionallity but the default behavior is usually good enough for most of the programming languages.

The <> Keys

When working with Python you often have to indent or outdent a couple of lines. Just mark them using the visual mode and press > to indent them. press 4< to outdent them 4 steps etc.

Advanced Undo Features

Vim has a different system of undoing changes. The normal undo is u in normal mode and ^r is redo. But what happens if you undo a few things and then change something? A normal editor forgets about the new changes. It's not possible to redo that again.

In Vim it's different. Vim starts a new undo branch. Using :undolist you can have a look at the possible undo states. With :earlier 20s / 1m / 2h you can then go back 20 seconds, one minute etc. Traveling forward in time works using :later and a timedelta as argument.

The Search Feature

I really like the firefox search feature. Just hit "/" and you can search in the current file and get the results in real time. That works with vim exactly the same. All you have to to is to either add :set incsearch into your vimrc or type it into the command prompt. Using n you can go to the next result. If you want to have all the search results highlighted use :set hlsearch. Hiding the results works using :nohl

Closing XML Tags

If you have the closetag.vim plugin installed (link above) you can add this to your vimrc in order to get the feature working: autocmd FileType html,xhtml,xml source ~/.vim/scripts/closetag.vim (update the path to your installation and your filetypes of course) Once this is done you can close open tags using ^_.

Regexp Replacement after Search

If you searched for a text using /foo and you now want to replace the found results with something you don't have to write this regexp again. Just do :%s///replacement/g and is automatically replaced with the last search regular expression.

Using Bookmarks

Bookmarking in vim is darn easy. If you are on the current line just bookmark it with mX where X is a lowercase letter from a to z. Go to that mark using 'X where X is the same letter again. Using '' you can jump back to the position you were before jumping to the bookmark. You can get the list of bookmarks using :marks.

The Vim File Browser

The Vim File browser is a nice thing. If you open a file using :e and that file is a directory you get a nice file browser for the files in that directory. If you are a python developer you probably want to filter some files out (*.pyc etc). Add this to your vimrc: let g:explHideFiles='^\.,.*\.pyc$' This hides pyc files as well as hidden files.

The Wildmenu

The best vim feature is the wildmenu. Add a set wildmenu to your vimrc and discover the possibilities of filesystem surfing ^^ Enter :e in the command line and press ^D. Vim will show you all possibitilites in a nice little window. By entering the start of a filename and pressing tab it completes for you then. If it was a folder you can now press ^D again to get the contents. Once you finished the command this window will disappear again and you can continue working. Works of course for all commands not only the open command.

Vim Completion Features

Last tip but maybe the most powerful one :). If you have vim7 and omni completion for your language you can use ^X^O to get the completion similar to intelli sense or how it's called. Note that the default color (pink) can be overridden in the theme. In my fruity.vim file i use this to get white letters on a dark red background: hi Pmenu guifg=#ffffff guibg=#cb2f27

Also nice is ^N. It looks up all used words in the open buffers and presents then in a dropdown completion. Useful if you have long variable names and don't remember them. Just type in the start of the variable name and press ^N. Vim will either complete it or show the list of possibilities.