Sunday, January 20, 2013

[Copied]Using Spell Checking in Vim


Mark Twain has been quoted as saying that he respected a person who could spell a word more than one way. Unfortunately, Twain's enthusiasm for creative spelling isn't widely shared today, at least in the professional world. If you need a little help in the spelling department, but prefer the old school way of editing text, you can turn to Vim's spelling support.
Support for spell checking was added in Vim 7. Before that, a few scripts were available to hack spell checking support into Vim — or you could do what I did and use ispell or aspell, but inline spell checking is much nicer.
If you're new to Vim and/or using Vim in text mode, it's not obvious that Vim even supports spell checking. But it does, and it's easy to use once you turn it on. You'll need to be in command mode and switch to last line mode, then run this:
:set spell spelllang=en_us
You might not want to be that specific, or you might want a different region. The "en_us" specifies English, U.S. style. You might want to use "en_ca" instead, if you're in Canada, or "en_gb" for Great Britain, or "en_au" for Australia. And, of course, this works for other languages as well.
If you're using Vim to write code and prose, you might want to turn spell checking on only in the local buffer. To do that, use:
:setlocal spell spelllang=en_us
Once you've set this, Vim will highlight misspelled words. If you're using Vim in text mode, you should see the entire word highlighted, or if you're using Gvim, you should see a squiggly underline for any word that is misspelled.
Vim does more than just highlight misspelled words, it actually categorizes misspelled words, it also highlights rare words, words that aren't capitalized (but should be), and words that have the wrong spelling for the specified region. For example, I've set Vim to check for U.S. spelling (spelllang=en_us), so it should highlight words that are spelled correctly in another region but might be considered incorrect for the local region.
Vim uses different colors for each type of word. This may vary depending on the colors you have set up in your terminal or how you have Gvim set up, but on my system I see misspelled words highlighted with red, an orange for rare words, blue for words that aren't capitalized, and so on.
Getting tired of seeing the highlighting? You may want to turn spell checking off if you're working with code or something like that. Use the nospell directive to turn this off:
:set nospell

Using Spellchecking

Spell checking wouldn't be very useful if you didn't have any help correcting the misspelled words, or a way to tell the program that the word is actually correct. Let's start with correcting words.
To move to a misspelled word, use ]s and [s. The ]s command will move the cursor to the next misspelled word, the [s command will move the cursor back through the buffer to previous misspelled words.
Once the cursor is on the word, use z=, and Vim will suggest a list of alternatives that it thinks may be correct. For instance, if I highlight autocompletion and then use z=, I see something like figure 1:
Figure 1: Word suggestions in Vim
Figure 1: Word suggestions in Vim

Just hit Enter if none of the suggestions work, or enter the number for the correct word.
What if Vim is wrong, and the word is correct? Use the zg command and Vim will add it to its dictionary. Simple as pie. You can also mark words as incorrect using zw.
If you don't want to keep telling Vim explicitly every time you restart to turn on spelling, just add the following to your .vimrc:
set spell spelllang=en_us
Substitute the appropriate region, of course.
Vim's combination of syntax highlighting, autocompletion (using CTRL-p and CTRL-n), abbreviations and mappings, and spell-checking makes it a killer editor to write in. Even when I need to share materials with clients in ODF or Word format, I usually write first in Vim with HTML and then copy and paste into OpenOffice.org, which usually handles the formatting just fine.
Have some writing tips with Vim you'd like to share? Something you'd like to know how to do in Vim? Speak up in the comments!

Source Link: https://www.linux.com/learn/tutorials/357267:using-spell-checking-in-vim

PS, you need to have a ~/.vim/spell directory for the command "zg" to work. Vim uses this directory to store the spelling dictionary.

Comnand: mkdir -p ~/.vim/spell

Wednesday, December 12, 2012

[SOLVED]Ruby Popen3.open3 system command got stuck

Problem:

In Ruby, Open3.popen3 is a good way to execute a system command and get the output of the command. Following is the a piece of code that does this.


Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread|
      err = stderr.gets
      out = stdout.gets
      [stdin, stdout, stderr].each{|stream| stream.send('close')}
      exit_status = wait_thread.value
end

It works well when your command throws some error to stderr. However, it got stuck forever if your command executes successfully without any error message, BECAUSE err=stderr.gets GOT STUCK.

Solution:

READ stdout FRIST

Monday, December 10, 2012

[SOLVED]Trouble-Shooting on Ruby on Rails Installation

1. Install ruby1.9.1 on Ubuntu
    Dependent on your OS version, you will have a default ruby version, which is usually outdated.
    Solution:
                  sudo apt-get install ruby1.9.1
                  sudo update-alternatives --config ruby
                  Select the number which corresponds to your newly installed ruby1.9.1 and enter
                  ruby -v, to see your current ruby version

2. Update rubygems
    On Debian Linux, "sudo gem update --system" is not allowed.
    Solution:
                  sudo gem install rubygems-update
         sudo update_rubygems
         sudo update-alternatives --config gem
                  Select the number which corresponds to your newly updated gem and enter
                  gem -v, to see your current gem version

3. Missing sqlite3, coffee-rails or some other gems
    Solution:
                 bundle install

4. rake db:create - Could not find a JavaScript runtime
    Solution:
                  sudo apt-get install nodejs
    Alternative solution(not work on Ubuntu 11.10):
                  Add following lines to Gemfile in your newly created app directory
                  "gem 'therubyracer'"
                  "gem ' libv8'"
                  Run "bundle install"

5. Installation of mysql2
    Solution:
                  sudo apt-get install libmysqlclient-dev
                  sudo gem install mysql2 -v '0.3.11'
                  Add following line to Gemfile
                  "gem 'mysql2'"

Tutorials

MySQL Python Tutorial
Ruby on Rails Tutorial
Install Ruby on Rails Using RVM

Tuesday, November 6, 2012

[SOLVED]insmod error "No such file or directory"

Problem: Getting an error message "No such file or directory" when trying to install a kernel module while the module is present.
Reason: Missing GPL license in your kernel module
Solution: Adding
              MODULE_LICENSE("GPL")
              to your kernel module

Tuesday, October 23, 2012

What is su doing?

su is a small *nix program that switches to another user and spawns a shell running as that user. What su is exactly doing is:

1. fork()
2. For the child process
    2.1 set_uid to the user given as an argument. If none, set_uid to root
    2.2 execv() a shell, whatever the default/specified shell it is
3. For the parent process
    3.1 wait for the child process

Notes:

  • set_uid will fail if su is not running as root
  • To make su run as root, the su binary must be owned by root and with the set_uid bit set

[Copied]Setting the SUID/SGID bits

SetUID bit, the executable which has the SUID set runs with the ownership of the program owner. That is, if you own an executable, and another person issues the executable, then it runs with your permission and not his. The default is that a program runs with the ownership of the person executing the binary.

The SGID bit is the same as of SUID, only the case is that it runs with the permission of the group. Another use is it can be set on folders,making files or folders created inside the SGID set folder to have a common group ownership.

Note : Making SUID and SGID programs completely safe is very difficult (or maybe impossible) thus in case you are a system administrator it is best to consult some professionals before giving access rights to root owned applications by setting the SUID bit. As a home user (where you are both the normal user and the superuser) the SUID bit helps you do a lot of things easily without having to log in as the superuser every now and then

Setting SUID bits on the file:
Suppose I got the executable called "killprocess" and I need to set the suid bit on this file, go to command prompt and issue command: chmod u+s killprocess

Now check permission on the file with command ls -l killprocess, observe "s" that has been added for suid bit

-rwsr-xr-x 1 root root 6 Jun  7 12:16 killprocess

Setting GUID bits on the file:
go to command prompt and issue command: chmod g+s killprocess
This will set the GUID bit on the same file, check the permission on this file using command: ls -l killprocess
 
-rwsr-sr-x 1 root root 6 Jun  7 12:16 killprocess

Read more: http://linuxpoison.blogspot.com/2009/06/setting-suidsgid-bits.html#ixzz2AA1giWxi


Copyright of Nikesh Jauhari
Source Link: http://linuxpoison.blogspot.com/2009/06/setting-suidsgid-bits.html