Tuesday 26 November 2013

Cyberroam Tricks Part 1

Most of the colleges or Offices have Cyberroam to restrict user from accessing certain websites. This can also be used to limit the speed of your Internet. I am in college and My college installed Cyberroam when I was in 2nd year of my Engineering. Every sem they introduce something to put limitation on us and everytime we had to find something to bypass that limitation.

I will mention all the limitation that our college has put on us and how to overcome that limitation.

1. The very first one was when we had to enter username and password provided by the college after regular interval which was very annoying. I got automatically solved. I don't know. I guess college professor found the option in cyberroam which was causing this. But there was a time when If we remove the LAN wire (cross cable) from laptop without logging out then It will not work on your laptop for certain amount of time. Then you will have to insert into someone's other laptop and then again insert it into your laptop and then It will work. If something like this happens to you then the very basic solution to this problem is to renew your IP address assigned to you. You can do this by executing the following commands in command prompt.

ipconfig /release

and then this command

ipconfig /renew

Now you will be able to see the cyberroam login page where you can login and use the internet. This happened with us a lot in a semester as in hostel the mostly the lan wire was damaged so even If we move the laptop a little the lan wire got removed from the laptop accidently and the internet would stop workign and I had to run these commands to make it run again.

2. The second problem I faced due to cyberroam was that I was unable to download anything from torrent. uTorrent didn't work. Then we found a solution to this problem also. Now the solution is very simple. Goto Options menu (ALT + O) in utorrent and then Preferences, then select Bittorrent in the list given on the left side. Now you will see a option named in Protocol Encyption in the right side. There will be 3 values. Select Forced. and click on OK. Now your utorrent will work even in cyberroam. Now the main problem was to get the torrent file. All the torrent websites were blocked so we were unable to download any utorrent file. One simple solution to me right now is to go to katmirror.com which is a copy of kat.ph which is not blocked here at my college. So I can download torrents from this website.


The solutions to cyberroam will continued in the next blog. I will provide more solution to the problem mentioned above by telling your how to use proxifier. So Stay tuned. Enjoy.!!!

Thursday 1 August 2013

Sync your fork and Original Resipository

I just started working for a organisation whose code is on Github. I cloned their repository and after making changes I tried to push changes to their repository But I couldn't. The reason was obvious. I cloned their repository. I don't have the permission to make changes in their repository.

Thats why you fork a repository. You can make any kind of changes in it. So I did that. But after I cloned it, I realised that the repository was too old. I hadn't merge the changes made in the original repository into my repository. I used to think that my fork automatically gets updated to the latest changes made in the original repository. Stupid thought? I know :P

Now you have to manually sync both of the repositories i.e. Your fork and the original one. I am writing this from this blog.

http://bradlyfeeley.com/2008/09/03/update-a-github-fork-from-the-original-repo/

I assume you have a local copy of your repository. Now issue the following commands

Now you need to add a remote branch to your repository which points to the original repository.

Issue the following command to do that

$ git remote add --track master mleung git://github.com/mleung/feather.git

Now here are 3 parameters i.e. master, mleung and git://github.com/mleung/feather.git

First one is the branch from which you want to merge. Most of the times it is master. In my case it was develop so I replaced it with develop. The next parameter is just a label. You can write whatever you want the name to be like repository_remote. And now the third parameter which is the link to the original repository. This command will add a remote branch to your repository. As you have noticed this command fetches nothing from the Internet. Now the next command is to do the same. Now before doing that you can also check if a remote branch was added from your above command using the following command

$ git remote

Now we can fetch the remote branch using

$ git fetch mleung

Now that you have fetched the changes and you have it in your repository. You can merge it which is the easiest thing to do. Now here specify the name of the remote branch that you have used above

$ get merge mleung/master

Now you successfully synced your local repository with the latest changes. Now you can push that changes in your remote repository with pride :P

$ git push

Happie Gitting :P

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.

http://www.vim.org/scripts/script.php?script_id=213

Download the cvim Zip file from the link and extract the contents to the .vim directory
$ tar zxvf cvim.zip .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
endif

" 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
"endif

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

" 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
endif
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.

http://ftp.iitm.ac.in/cran/ 

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 keyserver.ubuntu.com --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.

install.packages("RTextTools")

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
        </Directory>

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

Tuesday 29 January 2013

CGI C++ Photo Uploader

This project was given to me as an entrance test for GD. So I started off preparing for it from the very time when it was given to me. I faced many problems and I got to learn lots of things.

The very first problem was I was not familiar with CGI and I had never used CGI with C++.
So the first thing was to learn about CGI So I searched for CGI and collected some information about it. After this was to the turn to configure apache to support CGI. So I searched How to do it and started doing it Everything was already configured and CGI was working already.

Now I could start working with the project. CGI files are placed in /usr/lib/cgi-bin/ But you can change this directory and use your own directory by changing apache configuration in /etc/apache2/site-available//default file. Now I can start working on the project.

The very first problem that how to parse the POST, GET data and how to handle File Uploads with CGI. So After researching a little I found a library RUDECGI which allowed me to do that. It is a very simple library with lots of usefull function.

Installation procedure is pretty simple
./configure
make
sudo make install

How to use RUDECGI

Include file: rude/cgi.h

and use -lrudecgi while compiling to link the libraries. like this

g++ -o main main.cpp -lrudecgi

Initializing CGI object syntax: CGI cgi
There are many methods of the object but I have used only the following method in the program
cgi.value("")  This function to get value of get or post data.
cgi.isFile() Check if file was uploaded then
cgi.filename to get the name of the uploaded file

Now was the turn to learn about database. I was only familiar with MySQL So I thought of using some other DBMS this time. I had heard about SQLite and that it is very small and takes very small space and is even used by many mobile operating systems. So I thought about using it for my project

Sqlite header files can be installed by by executing the following commands in terminal

sudo apt-get install libsqlite3-dev sqlite3

to create a database you can use the following command

sqlite3 <database-name>

and then start entering your sql comands

or you can use sqlitebrowser

sudo apt-get install sqlitebrowser

After creating database, Now was the time to create connection to database through c++

sqlite3_open to open connection to the database
sqlite3_exec to execute sql commands which do not return anything such as INSERT, DELETE

To execute sql commands which return something we will use series of commands
sqlite3_prepare_v2() to prepare the sql statement if this return SQLITE_OK then you can proceed
sqlite3_step() to process all the rows

This was all about the database, the next problem that I faced took a lot of my time. Everything that you will put in the cgi-bin folder apache will consider it a cgi script and execute it. So you cannot store any of your javascript files,css files, and in my case photos. So I searched alot and people suggested to keep these files in document root folder for eg in /var/www as it is outside of cgi-bin folder so cgi will not execute it.

The other error I got was of C++ such as illegal conversion from const char* to char* etc which can be solved by using sstream.

All went well in the end and My task was complete and I got to learn lots of things in this week. :)) Happy Coding..