Saturday, October 27, 2007

Really Nothing

Hmm... well a long time... nothing to write? Huh .. no .. its just plain laziness.
will try to post something in next week ..

Blogged with Flock

Friday, October 19, 2007

new blog

started a new blog, showing off my techie knowledge http://super-techie.blogspot.com

Blogged with Flock

cookbook

have a look at http://pleac.sourceforge.net/, thinking/working hard to contribute (Java & C++)  

Blogged with Flock

Lock "Stock"

after getting bugged by the internet speed, response time of nseindia.com & bseindia.com, java in firefox and the pain in maintaining a portfolio, i decided to build my own portfolio manager, here are the specs
1. Database: Postgresql
2. Programming Languages: Python(to populate database in 15minutes interval, using ystockquote module), JSP
3. TOMCAT (Obviously)

currently i have finished the database part, i think it's working fine. i am now in the process of building the front end, so i am going to use eclipse-europa-jee for that, wish me luck.
i'll keep posting about my progress and the details

Blogged with Flock

Wednesday, October 10, 2007

How do i Flush!!

Most programs i write suffer from either stdout or stdin not getting empty when it is supposed to (when using Eclipse CDT, explicit flush id required for me to print anything).
while i can flush stdout using fflush(stdout);, i cant do the same thing with stdin, this was creating a major headache for me, and i came across a site which gave a code snippet to clear the buffer
   int ch;
  while( (ch = fgetc(fp)) != EOF && ch != '\n' )
   /* null body */;


Blogged with Flock

Where is my Pointer

being a TA, its my job to help the students when they encounter any problem in implementation or tools used for their projects, when Joseph said that  his program is receiving SIGSEGV, i thought it must be some simple problem either the index of array is not proper or memory not allocated, so i started to debug and Voila! the program works just fine giving correct output.
we all were wondering what is wrong, and eclipse(CDT) was the first target, but debugging in eclipse also worked fine, and now we decided to go manual line by line checking so few things are observed
  • they wanted a 2D array for which they know that the column size is two and row size should be dynamically allocated
  • Array of pointers were used
so i said to them, "fine, but i think we should convert those array of pointers to double pointers", and they agreed, so the next run gave the same SIGSEGV error.
now its time for more digging, so i prefer to user -Wall option to clean and make my code perfect, there i noticed one warning, function returns reference to local pointer, voila got it... so changed the function a bit, instead of returning a pointer we passed a pointer to the function and worked on it, and the result SUCCESS.
it shouldn't have taken much time for me to find out, being an OS student, we always deal with functions(system calls) which take pointer as an argument instead of returning them, so there must be something wrong/bad in returning the reference to local pointer, the memory gets lost!!!. but why not in debugging, the only reason that came to my mind is when debugging the memory areas used by the program is locked till it is freed or the program ends.

Blogged with Flock

Wednesday, October 03, 2007

SciTE, Compile and Run

Lately SciTE is becoming my favorite text editor, (VIm rules always), i find the menu options Tools->Compile,Tools -> Go useful for beginners who are new to Linux/Programming,  but i found that even though it compiles properly, it does not execute it(i.e. run  ), Why?

few minutes of digging gave me these results
First: umask for files is 022, i.e. files created by user will be read/write for the user and read only for group and others
Second: compilers will know that they are creating executables and set executable bit when they produce .o/a.out files
Third: if "." is in your path, then the executables are searched in current directory as well

Now the solution:
SciTE uses gcc -c <filename.c> -o filename.o to compile a file, and filename.o to execute, i got the error "bash - access denied", i opened a terminal and tried to execute it by myself, still an error,
why?
when we compile with -c filename.c, we ask the compiler to just compile and don't link it, i.e. it creates an object file and not executable object file, so if you run, it'll produce the access denied error message.
so open cpp properties and remove that -c option, add "./" before executable i.e. ./filename.o

Now the more interesting points:
  1. SciTE reads config files when it loads, so any change you make you'll have to restart it
  2. also all but user config files should be edited as root
Disclaimer:- i dont know the impact of removing -c option, it might be useful in large or multi file programs, so please consult your manual for exact details.

Blogged with Flock

Stupid Me, System.currentTimeMills()

for(int j=0;j<100;j++)
{
    java.util.Random rnd = new java.util.Random(System.currentTimeMillis());
    for(int i=0;i<100;i++)
    {
        System.out.print(rnd.nextInt(10)+"");
    }
    System.out.println();
}

please don't expect the above program to give 100 different sets of 100 random numbers, there will be repetitions like anything. why?
First: for a particular seed a Random number generator should give same set of numbers, when ever it is run,
Second: our computers are fast enough to finish execution in micro seconds

so the generation of 100 numbers takes few micro seconds and the System.currentTimeMills() has resolution in milliseconds so, a week of stupid searching and debugging, here is a post.

how to fix it:-
use new Random(); forget about seed, this produces 100 different sets of 100 random numbers.

Blogged with Flock

Monday, October 01, 2007

Hello world!

class HelloWorld {
public static void main(String[] a)
{
System.out.println("this is my new blog, here i'll be posting things that i encounter while dealing with computers and programming. ");
}
}