friends

Meta

Subscribe

I recently got a useful link which is syllabus of programming camp at IIIT-A. It is very useful for the beginners as well as for self learnt good programmers (because they know only the topics which are covered my the problems solved by them). There are some good references too which are nice. Here it is.

I was searching for such articles long time. During googling I found some of the functions and constants available in C/C++.
1>Constants:
* __LINE__ : integer contains line number
* __FILE__ : string contains name of file
* __DATE__, __TIME__ : you can understand by name
* __func__, __FUNCTION__ : name of function in inside which it is used
* __PRETY_FUNCTION__ : name + signature of function in C++, same as above two in C
* __STDC__ : variable defined when compiling in C
* __cplusplus : variable defined when compiling in C++
mathematics:-
* M_E : The base of natural logarithms.
* M_LOG2E : The logarithm to base 2 of M_E.
* M_LOG10E : The logarithm to base 10 of M_E.
* M_LN2 : The natural logarithm of 2.
* M_LN10 : The natural logarithm of 10.
* M_PI : Pi, the ratio of a circle’s circumference to its diameter.
* M_PI_2 : Pi divided by two.
* M_PI_4 : Pi divided by four.
* M_1_PI : The reciprocal of pi (1/pi)
* M_2_PI : Two times the reciprocal of pi.
* M_2_SQRTPI : Two times the reciprocal of the square root of pi.
* M_SQRT2 : The square root of two.
* M_SQRT1_2 : The reciprocal of the square root of two (also the square root of 1/2).
function I will post later If you can please contribute

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 :)

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

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

Before it i never heard the name polyglot!!!! I saw this on one of online event in IITM tech fest. Initially I faced difficulty but when I did one program rest were seems very easy to do. and I stood first in this competition. Polyglot is not a programming language but it is way of programming such that it runs on two or more compiler (different languages) simultaneously without making any change on it. “A polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independently of the programming language used to compile or interpret it.”

See it very interesting:
#include<stdio.h>
#define print(x) main(){printf(x);}
print("Pankaj\n")

it can runs in perl and C and prints Pankaj

There were saveral problems which I did successfully and here are these:

1>here are 3 cities A B and C. City A and B are connected with p roads. City B and C are connected with q roads. City C and A are connected with r roads. In how many different ways can one reach city C starting from city A? (0<p,q,r<10)

4>Consider a two-pan balance, you are asked to weigh a piece of wood
known to have some integral weight between 1 gram and n grams (3<n<999).
If the weights can go in either pan, what is the minimum number of integral weights you need to weigh the wood.

This one is very interesting it is in PHP,BASH,PERL,PYTHON and C (five language polyglot)

6>Polyglot program that will recognise its own
source code. The Program should output 1 if the input is its source code
itself and output 0 if the input is not its source code.
#include<stdio.h>/*
0 and length <<2;
"""
2
open FILE,__FILE__;$b=1;while(<FILE>){$a=<STDIN>;if($_ ne $a){$b=0;}}print $b;__END__
"""
import sys
def h():
f=open(sys.argv[0],"r")
for i in f:
x=raw_input();
if(cmp(i,x)==0):
return 0;
return 1;
print h()
#*/
#define X b;c;a=1;main(){FILE *f;f=fopen(__FILE__,"r");while((c=getc(f))!=EOF){b=getchar();if(c!=b)a=0;}printf("%d",a);}x
X=1;

on PERL,PYTHON and C

Here is a duine program in 5 languates:C,brainf**k,perl,ruby and python

At last I enjoyed this event a lot and had learnt different languages just in two days!!!NOTE:this post and attachments are only for my future reference
NOTE:FOR ALL PROGRAM input will be STDIN and output will be STDOUT
For more information click here Introduction to polyglot

If you will search in net by giving the name “prime1” you will see so many code which successfully solve this problem.Here is my submission for this problem in codechefvoid prime(int L,int U) {
int d=U-L+1;
bool flag[d];
memset(flag,true,sizeof (flag));//all true
for (int i=L%2;i<d;i+=2){ flag[i]=false;}//every position of even number false
for (int i=3;i<d;i+=2)
{
//if (flag[i]==true) continue;//given number is already set prime
int mod=L%i;
int t;
if(mod>0)t=i-mod;
else t=mod;
if(L/i==1||L/i==0)t+=i;
for(int j=t;j<d;j+=i){flag[j]=false;}
}

if (L<=1) flag[1-L]=false;
if (L<=2) {printf("2\n");}
for (int i=L%2?0:1;i<d;i+=2) if (flag[i]==true) printf("%d\n",L+i);

}
this function take the two number and print all the prime number betweem them.
EXPLANATION:
1.first set bol as true assuming that all number can be prime.
2.then set false for those which is divided by 2.
3.Now run for loop for all odd number and check if it is a prime if not proceed for next number else proceed for steps in for loop.
4.inside for loop leave first number because it is prime number and them set all other number which will divide by this prime number.
5.At last print all the prime number.:)

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

In the right pane, click UpperFilters.Note You may also see an UpperFilters.bak registry entry. You do not have to remove that entry. Click UpperFilters only. If you do not see the UpperFilters registry entry, you still might have to remove the LowerFilters registry entry. To do this, go to step 8.

On the Edit menu, click Delete.

When you are prompted to confirm the deletion, click Yes.

In the right pane, click LowerFilters.Note If you do not see the LowerFilters registry entry, unfortunately this content cannot help you any further. Go to the “Next Steps” section for information about how you can find more solutions or more help on the Microsoft Web site.

On the Edit menu, click Delete.

When you are prompted to confirm the deletion, click Yes.

Exit Registry Editor.

Restart the computer.

Microsoft Windows XP

Click Start, and then click Run.

In the Open box, type regedit, and then click OK.

In the navigation pane, locate and then click the following registry subkey:

In the right pane, click UpperFilters.Note You may also see an UpperFilters.bak registry entry. You do not have to remove that entry. Click UpperFilters only. If you do not see the UpperFilters registry entry, you still might have to remove the LowerFilters registry entry. To do this, go to step 7.

On the Edit menu, click Delete.

When you are prompted to confirm the deletion, click Yes.

In the right pane, click LowerFilters.Note If you do not see the LowerFilters registry entry, unfortunately this content cannot help you any further. Go to the “Next Steps” section for information about how you can find more solutions or more help on the Microsoft Web site.

Today when i was programming I saw one interesting thing, swapping of two numbers in one line!!!!

Previously I know how to swap two numbers usins bitwise operator but this is simple using ordinary operation…:)

a=(b=(a=b+a,a-b),a-b);

here is using bitwise operator.

a^=b^=a^=b;

Explanation:

1.For first expression if we seperate the expression it will like this-

First a=a+b will evaluate thusand then if we subtract b from a now it will give the original value of a and is assigned to b. So now b contain the value of a. In next after assigning a to b again subtract b from a i.e this time it will give the original value of b and is assigned to a. So the result is a contain the valuse of b and b contain the value of a i.e swapped.

ex: a=3;b=2;

a=a+b =>a=5;

b=a-b =>5-2 =>b=3 (original value of a)

a=a-b =>5-3 =>a=2(original value of b)

2. For second expression:

lets understand with an example. a=3 ,b=2;

if we convert it into binary form a=11,b=10;

so in first step a=a^b => 11(XOR)10 =>01(now value of a)

in next b=b^a => 10(XOR)01 => 11(now value of b and original value of a)