Sunday, 30 June 2013

Keyup event not responding to preventDefault()

I was working on jQuery's autocomplete/ Bootstrap typeahead kind of thing for phpBB.
It is basically used to provide user with suggestion/options when user enters something in the input or textarea
Now the default behaviour that you will see of the following keys is as follows:

For Arrow Up
If some option was already selected, then select the option just above it.
If no option was selected previously then select the very last option.

For Arrow Down
If some option was already selected, then select the option just below the current option
If no option was selected then select the first option

For Enter button
Now when enter button is pressed, check if any option was selected by the user. If yes then, insert that options value in the input

Now here we have to supress default actions of these above buttons. As if users presses Upper button the cursor moves to the first position i.e. before the text so to suppress this action you will have to use
Event.preventDefault function. Now If you use this function inside keyup then this might not work as the event that you are trying to start has already happened. So instead of using keyup you will have to do use keydown as the event of the keydown happens before event of keyup. So the preventDefault was not working. Now you can suppress these actions using the preventDeafult

Happie Coding!! :)

Friday, 7 June 2013

Setting up vim for C/C++

This post if about the changes that I make in the configuration of vim to use it as an editor for C/C++ Programs. Now first of all make a file named .vimrc in your home directory

$ touch .vimrc
And also make a directory named .vim in the very same folder i.e. your home directory

$ mkdir .vim
Now here is the link of the things that you have to put in the .vim directory.

Download the cvim Zip file from the link and extract the contents to the .vim directory
$ tar zxvf .vim/
Now copy paste the following in the .vimrc file

" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
  syntax on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)

" My Style
"set columns=70
set textwidth=70
set ruler
set nu
set shiftwidth=4
set autoindent
set smartindent
filetype plugin on
let g:C_SourceCodeExtensions = 'h cc cp cxx cpp CPP c++ C i ii Makefile'
set expandtab           " set tab to spaces
set tabstop=4           " set tab size = 4
set colorcolumn=70      " set column color to indicate not to extend 
                        " more than 72 chars

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
And now you are all set and done. Happy Coding.

Sunday, 2 June 2013

Came Across The R Project, Installing RTextTools

While I was searching Text Classification Machine Learning library for C++ I came across The R project. It is basically a library for statistics related programming which Machine Learning is all about.

So I found a library called RTextTools which uses R Project. I haven't yet used RTextTools so cannot comment about that. So I had to install RTextTools.

To install RTextTools, I will first have to install The R. Here I found all the instruction on how to install The R Project on Ubuntu. So the very first step given is to add the repository in your sources.list file
You will have to add the following line to your sources.list file which is present in /etc/apt/sources.list

deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu quantal/

Now replace <my.favorite.cran.mirror> according to your location. I live in India so I choose this. 

Take care of the duplicate http://. Now before updating your apt packages cache you will have to add the key of the repository which can be added using the following command which is also mentioned in the file I have mentioned above. 

sudo apt-key adv --keyserver --recv-keys E084DAB9

Now you can issue the following command

$ sudo apt-get update

and then 

$sudo apt-get install r-base

After installing the above package, you can install the rtexttools by issuing the following commands

$ sudo R

The above command will take you to R console 

Now here you can issue the following command to install it.


Now this will install RTextTools. I will soon be posting on how to use RTextTools and its various function which Currently I also don't know. :)

Saturday, 1 June 2013

Save dialog coming up while executing main.cgi

Every time I re-install my operating system I have to setup every damn thing again. Anyways! I am writing here the problem that I faced while setting up my cgi-bin folder. After installing apache server, CGI will work fine in /usr/lib/cgi-bin folder. But I was setting up the cgi-bin folder in my home directory as I had to install a software named BAKAPLAN made by one of my friends.

If you check the BAKAPLAN github page that I have mentioned above you will find the basic instruction on how to setup cgi-bin folder in public_html folder. I followed all the instruction written in there. Still when I tried to execute my own CGIPhotoAlbum, instead of executing it, It showed me dialog box to save the file. The executable file that I was trying to run had name "main.cgi". I don't know the reason behind this. May be because I was using an extension .cgi. Maybe I had not given the appropriate permissions to the files in the cgi-bin folder.

So the first thing I did was to give permission the folder. I issued the following command.

chmod -R 755 public_html/

Execute this command when you are in your home directory. "$ cd ~"

So next thing that I thought of was to tell the apache server that .cgi is also a cgi script. This reason kindof not making any sense but just for sake my some part of brain add the following line in /etc/apache2/sites-available/default or edit if it is already there

<Directory "/home/*/public_html/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                SetHandler cgi-script
                AddHandler cgi-script .cgi
                Order allow,deny
                Allow from all

Notice the AddHandler line. That is what I added. This solved my problem. Hope it does yours too. :)