Thursday, February 19, 2009

VIM Cheat Sheet

Working with files
Vim commandAction
:e filenameOpen a new file. You can use the Tab key for automatic file name completion, just like at the shell command prompt.
:w filenameSave changes to a file. If you don't specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:qQuit Vim. If you have unsaved changes, Vim refuses to exit.
:q!Exit Vim without saving changes.
:wqWrite the file and exit.
:xAlmost the same as :wq, write the file and exit if you've made changes to the file. If you haven't made any changes to the file, Vim exits without writing the file.
These Vim commands and keys work both in command mode and visual mode.
Vim commandAction
j or Up ArrowMove the cursor up one line.
k or Down ArrowDown one line.
l or Right ArrowRight one character.
h or Left ArrowLeft one character.
eTo the end of a word.
ETo the end of a whitespace-delimited word.
bTo the beginning of a word.
BTo the beginning of a whitespace-delimited word.
0To the beginning of a line.
^To the first non-whitespace character of a line.
$To the end of a line.
HTo the first line of the screen.
MTo the middle line of the screen.
LTo the the last line of the screen.
:nJump to line number n. For example, to jump to line 42, you'd type :42
Inserting and overwriting text
Vim commandAction
iInsert before cursor.
IInsert to the start of the current line.
aAppend after cursor.
AAppend to the end of the current line.
oOpen a new line below and insert.
OOpen a new line above and insert.
CChange the rest of the current line.
rOverwrite one character. After overwriting the single character, go back to command mode.
REnter insert mode but replace characters rather than inserting.
The ESC keyExit insert/overwrite mode and go back to command mode.
Deleting text
Vim commandAction
xDelete characters under the cursor.
XDelete characters before the cursor.
dd or :dDelete the current line.
Entering visual mode
Vim commandAction
vStart highlighting characters. Use the normal movement keys and commands to select text for highlighting.
VStart highlighting lines.
The ESC keyExit visual mode and return to command mode.
Editing blocks of text
The Vim commands marked with (V) work in visual mode, when you've selected some text. The other commands work in the command mode, when you haven't selected any text.
Vim commandAction
~Change the case of characters. This works both in visual and command mode. In visual mode, change the case of highlighted characters. In command mode, change the case of the character uder cursor.
> (V)Shift right.
< (V)Shift left.
c (V)Change the highlighted text.
y (V)Yank the highlighted text. In Winblows terms, "copy the selected text to clipboard."
d (V)Delete the highlighted text. In Winblows terms, "cut the selected text to clipboard."
yy or :y or YYank the current line. You don't need to highlight it first.
dd or :dDelete the current line. Again, you don't need to highlight it first.
pIn Winblows terms, "paste" the contents of the "clipboard". In Vim terms, you "put" the text you yanked or deleted. Put characters after the cursor. Put lines below the current line.
PPut characters before the cursor. Put lines above the current line.
Undo and redo
Vim commandAction
uUndo the last action.
UUndo all the latest changes that were made to the current line.
Ctrl + rRedo.
Vim commandAction
/patternSearch the file for pattern.
nScan for next search match in the same direction.
NScan for next search match but opposite direction.
Replace
Vim commandAction
:rs/foo/bar/aSubstitute foo with bar. r determines the range and a determines the arguments.
The range (r) can be
nothingWork on current line only.
numberWork on the line whose number you give.
%The whole file.
Arguments (a) can be
gReplace all occurrences in the line. Without this, Vim replaces only the first occurrences in each line.
iIgnore case for the search pattern.
IDon't ignore case.
cConfirm each substitution. You can type y to substitute this match, n to skip this match, a to substitute this and all the remaining matches ("Yes to all"), and q to quit substitution.
Examples
:452s/foo/bar/Replace the first occurrence of the word foo with bar on line number 452.
:s/foo/bar/gReplace every occurrence of the word foo with bar on current line.
:%s/foo/bar/gReplace every occurrence of the word foo with bar in the whole file.
:%s/foo/bar/giThe same as above, but ignore the case of the pattern you want to substitute. This replaces foo, FOO, Foo, and so on.
:%s/foo/bar/gcConfirm every substitution.
:%s/foo/bar/cFor each line on the file, replace the first occurrence of foo with bar and confirm every substitution.

Lex and Yacc Installation with Cygwin

Install the following packages.

YACC (bison) ---->  Devel/bison
Lexx (Flex)      ---->  Devel/flex


Checking the installation

$ bison --version

Should result in something like:
bison (GNU Bison) 1.875b

$ flex --version

Should result in something like:

flex version 2.5.4



- Mihir Patel

Wednesday, February 18, 2009

Run Your Personal wiki from a USB Stick




You don't have to lease server space or keep your home computer always on to access a personal web server—you can run a web, FTP, and database server straight from a USB drive. A slim web server package called XAMPP fits on a USB stick and can run database-driven webapps like the software that powers Wikipedia, MediaWiki. Almost two years ago you learned how to set up your "personal Wikipedia" on your home web server to capture ideas and track document revisions in a central knowledge repository. Today we'll set up MediaWiki on your flash drive for access on any Windows PC on the go.

A word on security: The XAMPP web server package is intended for web developers to use while building web sites, so by default, the passwords are blank and configuration is not secure. Running server software opens up a port on your computer, which in and of itself is a security risk. Getting this set up requires getting your hands dirty editing configuration files. If you're not comfortable with the risks and implications of this solution but still want your own wiki, I highly recommend the free, hosted, PBWiki. Also check out the nifty TiddlyWiki for a less setup-intensive wiki-on-a-thumb-drive alternative.

Still with me? Let's get your personal wiki running on a thumb drive.

What You'll Need

In order to get your personal Wikipedia running on your thumb drive, you'll need:

  • A Windows XP PC with Service Pack 2 or Windows Vista Ultimate
  • A thumb drive with at least 150MB free. The bigger your drive, the more data you can store on it so go as big as you can here.

Install and Start XAMPP

Download the XAMPP Lite .EXE installer from here. Double-click on the file to extract it, and choose your flash drive's drive letter as the destination (not a subfolder.) A folder called xampplite will be created on your thumb drive.

(Note: I chose XAMPP Lite because it offers everything we need to run MediaWiki, and it's smaller in size than XAMPP. But XAMPP is updated more often than XAMPP Lite, and you can install add-ons with full-on XAMPP, so it may be a consideration if you want to do more than just run MediaWiki on your thumb drive.)

Once XAMPPLite is saved to your flash drive, to start it up, double-click on the xampp-control.exe file in the xampplitedirectory. That will launch XAMPP's Control Panel, which lets you start all the services you need.

To run MediaWiki, you need two services: Apache web server, and the MySql database server. Click the Start button next to each of those in the XAMPP Control Panel, as shown.

When you hit the Start button, your system's firewall may ask whether or not it should allow incoming and outgoing connections to the software. Allow it.

Now your portable web server is up and running. To see it in action, in your web browser, visit http://localhost/. Click on your language of choice—by default, XAMPP Lite's English homepage looks like this.

The first thing we want to do is set up a few passwords to secure your servers. Click on the "Security" link on the sidebar (by default, located at http://localhost/security/. You'll see that by default, all of XAMPP's settings are marked as insecure. Click on the link below the security table to "fix" the problems (by default, http://localhost/security/xamppsecurity.php.) On this next page, set your MySql database password for the root user. If you choose, you can set a password for visiting any web page as well, as shown.

To enable the new MySQL password, switch to the XAMPP Control Panel, stop MySql, and start it again.

Install and Configure MediaWiki

Now that your web and database server is up and running, it's time to install the MediaWiki wiki software. Download the latest version of MediaWiki from here (as of this writing, the file name is mediawiki-1.11.1.tar.gz.) Extract the files (first gunzip, then tar, the free 7-Zip utility can do this for you), and by default they'll be stored in a folder called mediawiki-1.11.1. Rename this folder simply wiki and move it to your thumb drive in XAMPP's xampplite\htdocs\ folder. When you're done, if your thumb drive's letter is G:\, the full path to the MediaWiki files would beG:\xampplite\htdocs\wiki\.

To configure MediaWiki, visit http://localhost/wiki/. Click on the link to configure your wiki. There you can keep all the default settings except:

  • You must enter the name of your wiki. Mine is "GinaWiki."
  • You must enter a wiki administrator name (by default, WikiSysop) and password.
  • Enter your database information. The database name can stay wikidb, but change the DB username to root and enter the password you set up above.

Scroll to the bottom of the page and click on the "Install MediaWiki!" button to save your settings. When the installation is complete, MediaWiki will prompt you to move the LocalSettings.config.php file up a directory on your thumb drive. Go ahead and do that. You're moving the file from
G:\xampplite\htdocs\wiki\config\LocalSettings.php
to
G:\xampplite\htdocs\wiki\LocalSettings.php.

Finally, visit http://localhost/wiki/ to see your fresh new MediaWiki installation in action, as shown below. Congratulations!

From here you can start editing and adding pages, creating user accounts and even uploading files to your new wiki.

But first, two helpful customizations will make your new wiki easier to use.

  • Make your wiki the default start page. When you visit your local server, you might want your wiki's home page to appear first instead of XAMPP's homepage. To do that, open the index.php file in XAMPP's htdocs directory in a text editor. Change the line that reads: header('Location: '.$uri.'/xampp/'); to header('Location: '.$uri.'/wiki/'); and save it. Now, when you visit http://localhost/, you'll go directly to your wiki.
  • Add a custom wiki logo. To add your own logo to the upper left hand side of your wiki install, create a 135x135 pixel image, name it mywikilogo.png, and save it to H:\xampplite\htdocs\wiki\skins\common\images where H: is your thumb drive's letter. Then, open the H:\xampplite\htdocs\wiki\LocalSettings.php file in a text editor and add the following line: $wgLogo = "/wiki/skins/common/images/mywikilogo.png"; Save the file, and refresh your wiki in the browser. You should now see your custom logo. (Note: the logo doesn't have to be a PNG file; substitute your image's extension, like JPG or GIF.)

Stopping and Starting Your Wiki

When you're finished using your wiki, invoke the XAMPP Control Panel running in your system tray. Click the Stop button next to Apache, then click the Stop button next to MySql. Once the servers have stopped, click the Exit button. You can now eject your thumb drive as usual. Remember: don't try to eject your thumb drive before stopping the services; doing so can blue screen your PC and possibly screw up your wiki and server installation.

To start up your wiki at a new computer, plug in your thumb drive, and double-click on the xampp-control.exe file to start the Control Panel. From there, start the Apache and MySql servers, then visit http://localhost/ to edit your wiki.

Why a personal Wikipedia?

A wiki is an incredible collaborative tool for groups of people, but it's also a great one-stop shop for your own personal "stuff I want to remember"—like ideas, drafts, lists, and bookmarks. If you haven't edited Wikipedia or just want to see what MediaWiki can do, here's a quick demonstration of what writing a novel draft would be like using the software and its specialWikitext markup.

More Portable Web Servers

XAMPP isn't the only portable web server on the block. Another free portable server package called Server2Go includes Perl 5.8. Thanks, Vijay!

What do you do with your key chain web server? Let us know in the comments.

Ref :-
Gina Trapani, the editor of Lifehacker, likes her web servers tiny and portable. Her weekly feature, Geek to Live, appears every Monday on Lifehacker. Subscribe to the Geek to Live feed to get new installments in your newsreader.

Tuesday, February 17, 2009

How to check free disk space on a linux server /how to check reaming space on hdd

The command df -h 

[patelm@xx Radio]$ df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      145G   10G  128G   8% /
/dev/hda1              99M   12M   82M  13% /boot
none                  500M     0  500M   0% /dev/shm

Monday, February 16, 2009

Microsoft DOS tree command

Allows the user to view a listing of files and folders in an easy to read listing.

Syntax

TREE Drive:\ Path /f /a

Drive:\PathDrive and directory containing disk for display of directory structure.
/fDisplays file names in each directory.
/aext characters used for linking lines, instead of graphic characters. /a is used with code pages that do not support graphic characters and to send output to printers that do not properly interpret graphic characters.

Examples

tree

List a tree listing of the current drive. Below is a basic example of what a directory may look like.

C:.
├───Common
├───Director
├───Flash
├───Shockwave 8
│ ├───DswMedia
│ ├───Prefs
│ └───Xtras
└───update

HOWTO for running VNCserver on Linux

These examples are specific to Red Hat Enterprise Linux, but should work on any type of Linux system.

Why use VNCserver?

In Linux, everything can be done from a shell. However, there may be a time when you need to access the machine as if you were at the console. 

Getting Started

You will need several things to get started:
  • root privledges
  • VNC client software (tightVNC, you can download it here.)
  • A good password!
As I mentioned above, this example is done with RHEL, which comes standard with VNCserver installed. To start the vncserver simply invoke the following commands:
[root@roswell etc]# service vncserver start Starting VNC server:                                       [  OK  ] [root@roswell etc]#  [root@roswell etc]# vncpasswd Password:  Verify:  [root@roswell etc]# [root@roswell etc]# vncserver  New 'roswell:1 (root)' desktop is roswell:1  Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/roswell:1.log  [root@roswell etc]# 
So what did we do there? First, we started the vncserver service. It may or may not have already been running on your system. Next we set a password to access the VNC desktop. When you set the password, you will not see any characters on the screen, and you must enter the password twice. You will only need to do this the very first time you run vncserver. The password will be saved in the Linux filesystem, and you can change it at any time by invoking thevncpasswd command again. Last, to activate the VNC desktop, we simply invoked the vncserver command. Notice the output; the desktop is named "roswell:1" which can also be replaced via the machines IP address. 

Connecting

Assuming you already installed TightVNC or another VNC client, enter the desktop name: 



You can replace the server name with an IP address if you are logging in from outside your LAN. Remember, if you are using NAT port 5900 must be forwarded to your VNCserver. 



Upon successful connection, you will be prompted for a password. You will then see a terminal screen that will allow you to execute commands: 



VNCserver in Runlevel 5 (KDE or Gnome)

If you are new to linux, running VNC server with a terminal isn't going to do you much good. You might want to have a menu-driven GUI like Windows. No problem. Follow these steps: 


First, we are going to assume that VNCserver is running under the root user, as shown with the example above. For this example, I will be editing my VNCserver to enter Gnome. You can specify a KDE desktop if you have KDE installed on your server. Make sure you are in the root directory.
[root@roswell ~]# ls -a .                                   cacti-0.8.6c.tar.gz  .gnome2_private     .lftp                  queue.dat          temp ..                                  client.cfg           .gnupg              machinedependent.dat  .recently-used      Templates .config                             FAHlog-Prev.txt      .gstreamer-0.8      .metacity             .rhn-applet.cache  .themes .cshrc                              FAHlog.txt           .gtkrc              .mozilla              .rhn-applet.conf   .thumbnails .bash_history                       Desktop              .fonts.cache-1      .gtkrc-1.2-gnome2     .rnd               .Trash .bash_logout                        .dmrc                .gconf              .ICEauthority         .mysql_history      scripts .bash_profile                       .eggcups             .gconfd             .icons                .nautilus          .sh_history .viminfo                            .bashrc              .bashdevl           .esd_auth             .gnome              php-4.11 .ssh                                .vnc                  cacti-0.8.6c       .gnome2                install.log [root@roswell ~]# cd .vnc [root@roswell .vnc]# ls passwd         roswell:1.pid  roswell:2.pid  roswell:3.pid  roswell:4.pid  roswell:5.pid             roswell.area51.lan:1.pid roswell:1.log  roswell:2.log  roswell:3.log  roswell:4.log  roswell:5.log  roswell.area51.lan:1.log  roswell.area51.lan:2.log xstartup [root@roswell .vnc]# vi xstartup 


Using vi (vim) to edit the xstartup file, make sure your file matches this one: 


#!/bin/sh  # Uncomment the following two lines for normal desktop:  unset SESSION_MANAGER  exec /etc/X11/xinit/xinitrc  [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & startx & 


Notice that the last line is "startx &" as this command will launch Gnome upon login via VNCserver. If you are using a KDE desktop, the line "startkde &" should replace the last line. 

Logging in, you will be presented with a Gnome or KDE desktop. 



Shown above is a Gnome desktop on Red Hat Enterprise Linux 4. 

Friday, February 13, 2009

FireFox AddOn For Twiki Editing

Follow the procedure to add the twiki edit plug-in to the firefox

  1. Open the firefox
  2. Open about:config in the URL
  3. Click on the "I will be careful, I promise !"
  4. Right click , when menu pops up select New >Boolean
  5. Enter name as extensions.checkUpdateSecurity
  6. Click OK
  7. select False as the value
  8. Click OK
  9. Close firefox
  10. Open firefox
  11. Save the twikiAddOn to your computer from the bottom of this page
  12. Open the plug-in using open file from file menu. or just drag and drop the saved plug-in in firefox
  13. Restart firefox
- Mihi Patel.

Saturday, February 7, 2009

Using webcam on linux \ video chatting \ yahoo video chatting

GYachE - can be used to install yahoo messenger. It includes all the features like voice chat, video chat... etc.

Resolving an odd dpkg error in Ubuntu \ dpkg: ../../src/packages.c:191: process_queue: Assertion `dependtry <= 4' failed

Usually this problem is due to installation crash.

in my case it was gxine player which got crashed while updating.

you can check which program is giving the problem by the following

mihir3445@mihir3445-laptop:~$ sudo dpkg -l | grep -v ^ii
Desired=Unknown/Install/
Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name Version Description
+++-==========================================-=======================================-============================================
rc amarok 2:1.4.10-0ubuntu3 versatile and easy to use audio player for K
rc amarok-common 2:1.4.10-0ubuntu3 architecture independent files for Amarok
rc bgchanger 0.9-1 Wallpaper Switcher
iF gxine 0.5.903-2ubuntu2 the xine video player, GTK+/Gnome user inter
rc libgd2-noxpm 2.0.36~rc1~dfsg-3ubuntu1 GD Graphics Library version 2 (without XPM s
rc libifp4 1.0.0.2-3 communicate with iRiver iFP audio devices
rc libnjb5 2.2.5-4.2ubuntu1 Creative Labs Nomad Jukebox library
rc libtunepimp5 0.5.3-7ubuntu3 MusicBrainz tagging library
rc libxalan2-java-gcj 2.7.1-2 XSL Transformations (XSLT) processor in Java
iU libxine1 1.1.15-0ubuntu3.1 the xine video/media player library, meta-pa
iU libxine1-all-plugins 1.1.15-0ubuntu3.1 the xine video/media player library, meta pa
iW libxine1-bin 1.1.15-0ubuntu3.1 the xine video/media player library, binary
iU libxine1-console 1.1.15-0ubuntu3.1 libaa/libcaca/framebuffer/directfb related p
iU libxine1-ffmpeg 1.1.15-0ubuntu3.1 MPEG-related plugins for libxine1
iU libxine1-gnome 1.1.15-0ubuntu3.1 GNOME-related plugins for libxine1
iU libxine1-misc-plugins 1.1.15-0ubuntu3.1 Input, audio output and post plugins for lib
iU libxine1-plugins 1.1.15-0ubuntu3.1 the xine video/media player library, meta pa
iU libxine1-x 1.1.15-0ubuntu3.1 X desktop video output plugins for libxine1
rc libxmmsclient-glib1 0.5DrLecter-2ubuntu1 XMMS2 - glib client library
rc linux-restricted-modules-2.6.27-7-generic 2.6.27-7.12 Non-free Linux kernel modules for version 2.
rc myspell-en-us 1:2.4.0-2ubuntu4 English_american dictionary for myspell


you can see iF,iU etc... which shows that gzine was not installed properly.

so, to fix this problem you just need to execute following command line argument.

sudo dpkg --purge remove gxine

which means remove gzine packet and uninstall the program.

then you can check if the following command gives you responce or not.

sudo dpkg --configure -a

it should work normally...

Hope this helps.

Leave your comments..........


- Mihir Patel.
















=============================================================================================
The post that i found useful on this topic is following
http://techxplorer.com/2006/05/21/resolving-an-odd-dpkg-error-in-ubuntu/
=============================================================================================
Since my last post about running the Ubuntu Dapper Drake Beta on a virtual machine using the VMware Server Beta, I've not experienced any major issue. Which is great. The only truly odd issue I've had recently is that I've been getting the following error from the dpkg program when I use apt-get or synaptic to install a package.

dpkg: ../../src/packages.c:191: process_queue: Assertion `dependtry <= 4' failed
.
E: Sub-process /usr/bin/dpkg exited unexpectedly

The problem was I didn't know which package this error applied to, simply because all of the packages appeared to be installed correctly. Any package that I installed after I noticed this error seemed to be installing fine, I was able to use them for example, and yet the error persisted. Not being one to sit by and let errors just happen I did some exploring.

After a lot of digging via Google and the Ubuntu Forums I was able to use this command to locate the offending package:

sudo dpkg -l | grep -v ^ii

The "dpkg -l" part of the command lists all of the installed packages in a table format. The first column of the table outlines the status of the package, for example if it is installed correctly etc. The second part of the command "grep -v ^ii" outputs any line that does not start with the letters ii. By passing the output of the "dpkg -l" command to the grep command I was able to get a list of all packages that were listed as not being correctly installed. That is, those packages that didn't have a status of "ii". I was then able to use this command to remove the offending package where [package-name] was the name of the package.

sudo dpkg --purge remove [package-name]

Now I don't get the odd error any more and it is resolved. While using synaptic and other GUI clients to install packages is great. Sometimes knowing a little about the underlying programs can be very useful. It is also worth noting that the Ubuntu Forums are truly invaluable.