Life of student

All about Programming , C++ ,Fedora

  • Blog Stats

    • 17,925 hits
  • Categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email. I too can\'t see who had subscribed my blog :(

    Join 11 other subscribers

Archive for the ‘Linux’ Category

Auto mount drives in linux

Posted by pankaj4u4m on November 28, 2009

I was just searching for how to enable the mounting the drives at start up because I didn’t find authorization menu in Fedora 12.

I found one solution and it is working for my system

open terminal and do following commands:

[codegambler@localhost /]$ su

[root@localhost /]#vi /etc/selinux/config'

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted

change the hi-lighted line as given;

[root@localhost /]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

now add following lines:
su -c 'mount -t ntfs-3g /dev/sda2 /media/windows -O uid=500,rw,fmask=0000,dmask=0000'
su -c 'mount -t ntfs-3g /dev/sda3 /media/srudy_fun -O uid=500,rw,fmask=0000,dmask=0000'

it is for my system


Now whenever you will restart your system you no need to mount again:
Happy fedora :)

Posted in Fedora, Linux | 1 Comment »

wow what the powerful editor is this VIM

Posted by pankaj4u4m on November 11, 2009

vim is a powerful editor in linux operation system and i found some of very usefull tips in vim from net.
1>if you want to add some of line while opening some specific file then you can do by adding following lines in you .vimrc file
first of all create a .vimrc file like:
[codegambler@localhost ~]$ vi ~/.vimrc
then add these lines in it (this is for c/cpp header)
autocmd BufNewFile *.c r ~/.vim/mainheader
autocmd BufNewFile *.cpp r ~/.vim/mainheader

another use of autocmd is set default setting for filetype like

autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType python setlocal expandtab shiftwidth=4 softtabstop=4

also by using

autocmd FileType cpp source ~/.vim/cpp.vim

autocmd FileType py source ~/.vim/py.vim

one usefull command to indent lines in c/c++ file(one of the prefered setting )
add

autocmd FileType cpp setlocal expandtab shiftwidth=4 softtabstop=4 cindent number

to your .vimrc file

you can make a file
[codegambler@localhost ~]$ vi ~/.vim/mainheader
and add like this

#include
#include
int main()
{
}
code. when you will create any c/cpp file this default code will automatically insert
2> using calculator inside your vim
if you want to do some basic calculation like +,-,*,% then this will automatically do for you

just add these lines in your .vimrc file

inoremap <C-B> <C-O>yiW<End>=<C-R>=<C-R>0<CR>

next time when you will type
2+2

now press ctrl+b …. and it will replace it with ..

2+2=4

what a amazing feature is;

3> like most editor you want to undo your some of code to previous version. you can do it by using command

: earlier 10

this will take you back to before 10 modification

:earlier 10s

this will take you 10s back into your code

:later 5 will forward the undo code

what a nice command
be happy and free to code you program in vim 🙂

i found these tips in this site ajay somani’s blog. which i found useful to me.
some other tips also whic are not in that site are here

1> encrypt you file inside vi
just create your file like
[codegambler@localhost ~]$ vi -x myufile

now you enter your pass* . now whenever you will open your file it will decrypt the content and whenever you close it it will again encrypt and save it..

if you know any good tips which can help to learn vim better please add it here… you are always welcome
HAPPY CODING 🙂

Posted in Fedora, Linux, vim | Leave a Comment »

How to change MAC address in Linux

Posted by pankaj4u4m on October 10, 2009

How to change MAC address in Linux First find the physical MAC address of your machine by running the following command :

$ ifconfig -a | grep HWaddr

eth0 Link encap:Ethernet HWaddr 00:80:48:BA:d1:20

Next, login as root in Linux and enter the following commands –

# ifconfig eth0 down

# ifconfig eth0 hw ether 00:80:48:BA:d1:30

# ifconfig eth0 up

# ifconfig eth0 |grep HWaddr

NOTE:This change in MAC address is only temporary. Once you reboot your machine, the operating system reflects the physical MAC address burnt in your network card and not the MAC address you set.

Posted in Fedora, Linux | Leave a Comment »

Fedora camp in SASTRA

Posted by pankaj4u4m on August 23, 2009

This was first time happening in my college SASTRA that there was any fedora camp.

The camp was organized by me (Pankaj kumar), Nishanti, Anurag Jain, Sanjeev Gopinath,and J.Dwarak.The response was very good and all became happy when we distributed fedora 11 dvds and stickers.

The session was started at 11.00 am by Nishanti (the host of the event) who described the agenda for the event and the Dwarak started his seminar on OPEN SOURCE and LINUX. He told what OPENSOURCE is and connected it to the corporate world. After that I came and explained about FEDORA , Fedora subprojects, and then features of fedora. Anurag told the installation of fedora and demonstrated some software. Sanjeev took FEDORA ELECTRONIC LAB and he explained how one can design electronic board using fedora electronic lab. While he was explaining I designed basic AND gate in DIGITAL DESIGNER and simulate that. I felt very excited while doing that.Then  Sanjeev  explained C/C++ and JAVA coding which was complied by me. Anurag gave very important links to the audience which is very helpfull after first time fedora installation. At the end of Sanjeev’s session we demonstrated GNOME Desktop features and COMPIZ, audience were very excited to see these all. At the end we distributed fedora 11 DVDs and stickers and then we end the session at 1.30pm . At the end of session we had party for organizers 🙂 . The presentations can be downloaded from these links

Event wiki
Fedora11_installation
Fedora-11-Intro-and-subprojects

Posted in Fedora, Linux, Uncategorized | 4 Comments »

My second year OS assignment DEAD LOCK DETECTION

Posted by pankaj4u4m on August 9, 2009

// Author:pankaj
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <list>
#include <stack>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <sstream>
#include <deque>
#include <set>
#include <map>
#include <numeric>
#include <functional>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define REP(i,a,b) for (i=(a);i<(b);i++)
#define REPR(i,a,b) for (i=(a);i>=(b);i--)
#define SET(A,p) memset(A,p,sizeof(A))
#define CPY(A,B) memcpy(A,B,sizeof(A))
#define ALL(A) A.begin(), A.end()
#define EACH(i,A) for(typeof(A.begin()) i=A.begin();i!=A.end();i++)
#define pb push_back
#define sz size()
#define cl clear()
#define fi first()
#define se second

typedef long long int ill;
typedef unsigned long long int ull;
typedef vector <int> VI;
typedef vector <double> VD;
typedef pair <int, int>IP;
typedef vector<IP> VP;

class proc
{
public:
int allocated[100],max[100],used[100],need[100];

};
void dead()                   //if dead lock detected program exit
{
cout<<"Deadlocak detected";
exit(1);
}
int main(int argc, char** argv)
{

proc p[100];
int n,m,temp=0,flag[100]={0};int resource[100],free[100];
cout<<"\nEnter the no total number of resource:";
cin>>n;
cout<<"\nEnter resources for:\n";
FOR(i,0,n)
{
cout<<"\n "<<i+1<<" :";
cin>>resource[i];

}
cout<<"\nEnter the number of process:";
cin>>m;
cout<<"\nEnter the resources for each processes";
cout<<"\n   allocated     maximux_required";
FOR(i,0,m)
{
cout<<"\np "<<i+1<<" :";
FOR(j,0,n)
{
cin>>p[i].allocated[j];
}
FOR(j,0,n)
{
cin>>p[i].max[j];
}
FOR(j,0,n)
{
p[i].need[j]=p[i].max[j]-p[i].allocated[j];

}
}
FOR(j,0,n)
{
free[j]=resource[j];

}
FOR(i,0,n)
{
if(free[i]<0){
dead();}
}
FOR(i,0,m)
{
FOR(j,0,n)
{
if(free[j]>=p[i].need[j]&&flag[i]==0)
{
flag[i]=1;
}
else if(free[j]<p[i].need[j])

{
flag[i]=0;break;
}

}
if(flag[i]==1)
{
cout<<"P"<<i+1<<" ";
flag[i]=2;
FOR(j,0,n)
{
free[j]+=p[i].max[j];

}
i=-1;

}
}
FOR(i,0,m)
{
if(flag[i]==0)
dead();
}

return (EXIT_SUCCESS);
}

Posted in c++, dead lock, Fedora, Linux, Programming | Leave a Comment »

Now see *.chm in linux without converting into any formate

Posted by pankaj4u4m on July 26, 2009

Now you can see any *.chm extention file in linux also. You need to install a small package chmsee and you will able to see .chm file in linux.I installed it in mynew Fedora 11.. 🙂

Posted in Fedora, Linux | Leave a Comment »