Amber Jain's weblog (OLD)

Visit my new weblog at http://amber-jain.blogspot.in/

Using kqemu in debian

leave a comment »

kqemu is not available in any of official debian repos. (Google “kqemu” if you dont know what kqemu is. Also kqemu on wikipedia).

So, if your machine doesnot supports KVM (like mine), you’ll most probably feel the need of kqemu. To install kqemu on debian (confirmed on lenny), follow these:

NOTE: Run all commands below as root.

apt-get install module-assistant
m-a prepare
m-a update
m-a a-i kqemu

After this, open /etc/modules in you text editor and append kqemu after last line (mind you, there should be no other text in that line) i.e. append this line to /etc/modules:

kqemu

Now, restart your system and launch an OS inside qemu *as root* (kqemu wont be loaded with qemu if you are not root).

That’s it🙂

Written by Amber Jain

July 1, 2010 at 11:20 PM

Error on debian lenny when updating Virtualbox 1.x to 3.x

with one comment

I’m running debian lenny that was setup from minimal netinst. I had installed virtualbox from lenny repos (http://packages.debian.org/lenny/virtualbox-ose). But then I thought of upgrading to newer version of virtualbox because virtualbox 1.x refused to capture my mouse pointer inside guest OS. So, I added lenny-backports repos (http://packages.debian.org/lenny-backports/) to my /etc/apt/sources.list and did ‘sudo apt-get install -t lenny-backports virtualbox). Then when I started virtualbox 3.x, and tried starting (/booting) any guest OS, I got this error:
Virtualbox error

When I was installing Virtuabox from lenny-backports, the ‘apt-get install’ output was:
http://codepad.org/bjDDof4p
Lines number 90,91,92 and 108, 109, 110, 111, 112 are worth noting in that paste.
(Note: If you want to check out log of output from ‘apt-get install’ on debian, goto /var/log/apt/ and open term.log in your text editor as root)

I then tried finding some help on #debian at irc.freenode.net.
User ‘qq-‘ there suggested that I try rebooting. When I rebooted, I got this message in debian boot messages scrollback:

Starting Virtualbox kernel modules. No suitable vboxnetflt module for running kernel found. Failed

After some discussion, users ‘qq-‘ and ‘jpinx-eeepc’ suggested that I try installing linux-image-2.6.32-bpo.5-686 (you can see mentions of this linux kernel version in the paste linked above). So, I did ‘sudo apt-get install -t lenny-backports linux-image-2.6.32-bpo.5-686’.
When I started Virtualbox this time……wooohooo NO ERRORS THIS TIME😀

So, in short, install the latest/stable/recommended linux kernel version if you get a similar error.

Written by Amber Jain

June 21, 2010 at 3:47 PM

Compile C code (that uses libraries) using gcc on Windows

with one comment

Ok. I know that you probably know how to compile code using gcc. You use something like following command:

gcc -Wall -g input_filename.c -o output_filename

OR

gcc -Wall -c -g input_filename.c
gcc -Wall -o output_filename input_filename.c

Right? Ok. RTFM for more details.

The above compile command is really easy and works on Linux, BSD, Unix, Windows etc. On Linux/BSD/Unix, compiling code that uses some library is not so difficult and (almost?) same across different distributions (Makefiles exist to ease the compile/build process). But on Windows, it’s a bit different. Personally, it took me more than half an hour and help of fine folks at #mingw (at irc.freenode.net) to understand how to compile a C program that uses some library.

In this post, I’ll take libcurl as an example to illustrate compiling a C program that uses some library. libcurl is the multiprotocol file transfer library.
For this post, we will try compiling and building (an executable) using following example code:

Source: http://curl.haxx.se/libcurl/c/simple.html


#include <stdio.h>
#include <curl/curl.h>


int main(void)
{
// Source: http://curl.haxx.se/libcurl/c/simple.html
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}

NOTE: Download and extract this to C:\ so that your directory structure should look like:
C:\libcurl-7.19.3-win32-ssl-msvc\lib\Release
More libcurl downloads are here.

Let me start with the command that is the ultimate purpose of this post (i.e. to compile C code on Windows that uses some library). Here:

gcc main.o -o test_binary -LC:\libcurl-7.19.3-win32-ssl-msvc\lib\Release -lcurllib

Here are details of various command line arguments (in order) in above command:

#1. gcc: The first command line argument, ‘gcc’, is the name of compiler.

#2. main.o: The second argument, ‘main.o’, is the name of object file input to compiler that was previously compiled from source code using:
gcc -Wall -c -g main.c

#3. -o: The third argument, ‘-o’, specifies that the argument immediately following this argument is the name of output binary executable, as per the needs of the programmer (or the person who is compiling the code). Also, see #4 that follows.

#4. test_binary: The fourth argument, ‘test_binary’, is the name of output binary executable, as per the needs of the programmer (or the person who is compiling the code). This is bind to ‘-o’ command line argument and should immediately follow it. Also, see #3 that precedes.

#5. -LC:\libcurl-7.19.3-win32-ssl-msvc\lib\Release: Now comes the real part (Pause here and remind yourself the actual purpose of this post). The fifth argument, ‘-L’, specifies that the string appended to -L flag/option is the directory that should be searched for library files specified by ‘-l’ flag (Also, see #6 that follows). Mind you, there is *no* space between the option flag (-L) and the library directory name.

#6. -lcurllib: The sixth argument, ‘-l’, tells linker that the string appended to -l option flag is the library that is to be searched for unresolved symbols when linking. The actual file will be something like either libmylib.a or mylib.lib or something similar (@experts: right?).

I must confess here that I’m still unable to use makefiles *on windows* to automate the process of compiling and building (though I tried only for less than 1 hour). Manual compiling is surely cumbersome, but who cares😀 I very rarely compile my code on Windows and so, I’ll get past this hurdle too sometime in future when I get some free time. And, maybe I’ll do a blogpost on it too.

That’s it. I guess that you get it. If you still have questions/problems, you can try following:
1. Get help from #mingw (irc.freenode.net).
2. RTFM. http://gcc.gnu.org/onlinedocs/
3. Stanford’s Unix Programming Tools contains some useful information (It’s really useful, even if it is for Unix. Read it.).

PS: In case you get ‘XYZ.dll not found’ error when running the executable, just find the right DLL(s) [on the internet] that are missing and put them in same directory that contains the binary executable. Easy, isn’t it?

🙂

Written by Amber Jain

May 18, 2010 at 7:10 PM

Amber Jain’s list of *free* books available online for free

with one comment

Quoting Stewart Brand:

Information wants to be free

I guess after reading the preceding quote, the intent of this blog post is clear.

I wrote a related blog-post sometime back: Links to *free* legal ‘readable stuff’ online.. This post is an extension of the idea behind that post.
I’ll post links to books (in no particular order) that are available online for free here. I’ll update this list whenever possible. If there are similar links/resources that your know of, post them in comments:

0. The C Book, second edition (by Mike Banahan, Declan Brady and Mark Doran)
This was originally published by Addison Wesley in 1991. This book is no longer in print though it can be read online for free.
The C book

1. Handbook of Applied Cryptography – fifth printing (by Alfred J. Menezes, Paul C. van Oorschot and Scott A. Vanstone)
Handbook of Applied Cryptography

2. Bruce Eckel’s Free Electronic Books/seminar etc:
http://www.mindviewinc.com/Books/downloads.html
http://mindview.net/CDs/ThinkingInC/beta3



See also: Links to *free* legal ‘readable stuff’ online.

Written by Amber Jain

May 14, 2010 at 6:40 PM

Links to *free* legal ‘readable stuff’ online.

with 2 comments

Quoting Stewart Brand:

Information wants to be free

Richard Stallman restated it as follows:

I believe that all generally useful information should be free. By ‘free’ I am not referring to price, but rather to the freedom to copy the information and to adapt it to one’s own uses… When information is generally useful, redistributing it makes humanity wealthier no matter who is distributing and no matter who is receiving.

I guess that preceding quotes pretty much clarify the intent of this blogpost.

In this post I’ll link all websites (in no particular order) that provide any number of ebooks/magazines/journals/thesis/dissertations etc. online for free. I’ll update this list whenever possible. If there are similar links/resources that your know of, post them in comments:

0. Amber Jain’s list of *free* books available online for free
This is my personal list of free books available online that may or may not be listed on pages linked below.
https://thinkminus.wordpress.com/2010/05/14/amber-jain%E2%80%99s-list-of-free-books-available-online-for-free/

1. FreeTechBooks.com:
This site lists free online computer science, engineering and programming books, textbooks and lecture notes, all of which are legally and freely available over the Internet.
http://www.freetechbooks.com/

2. Universal Digital Library (Million book project):
http://www.ulib.org/

3. List of digital library projects (wikipedia):
http://en.wikipedia.org/wiki/List_of_digital_library_projects

4. List of open-access journals (wikipedia):
http://en.wikipedia.org/wiki/List_of_journals_available_free_online

5. (US) Patent full text and full page image databases:
http://patft.uspto.gov/

6. ODLIS — Online Dictionary for Library and Information Science (by Joan M. Reitz):
http://lu.com/odlis/

7. Cambridge Dictionaries online:
http://dictionary.cambridge.org/

8. Digital library of India:
http://www.new.dli.ernet.in/
http://dli.iiit.ac.in/

9. Delnet database of digital libraries of the world:
http://164.100.247.21/basisbwdocs/digitallibrary.htm

10. Networked Digital Library of Thesis and Dissertations:
http://www.vtls.com/ndltd

11. Directory of open access journals (doaj):
http://www.doaj.org/

12. DELNET’s list of “Engineering and Technology E-journals”:
http://164.100.247.21/basisbwdocs/engjournals.htm

13. SARAI (South Asia Resource Access on the Internet):
http://www.columbia.edu/cu/lweb/indiv/southasia/cuvl/

14. 100 Useful Links for eBook Lovers by onlinecourses.org:
http://www.onlinecourses.org/2009/11/11/100-useful-links-for-ebook-lovers/

15. Project Gutenburg:
http://www.gutenberg.org/

16. Sugar on a Stick Ebooks list (mostly for children but *not* all):
http://wiki.sugarlabs.org/go/Sugar_on_a_Stick/E-Books

17. O’Reilly Open Books Project:
http://oreilly.com/openbook/
Searching google with search term “site:oreilly.com oreilly openbooks” (without quotes) lists almost all of them.

18. Cheat Sheets:
http://www.cheat-sheets.org/

19. Food for thought (University of Sussex’s Communication REsearch Group)
http://www.comms.scitech.susx.ac.uk/fft/

18. Medical-related free books/journals etc:
1. Free medical books: http://freebooks4doctors.com/
2. Full text medical journals: http://www.freemedicaljournals.com/

TEMPLATE
TEMPLATE



See also: Amber Jain’s list of *free* books available online for free

Written by Amber Jain

April 24, 2010 at 4:25 PM

3 idiots is not worth watching. Version 1.0

with 6 comments

Version 1.0

For those who don’t know, “3 idiots” is a Hindi movie (a bollywood superhit). Do a Google search.

Why?
Quoting myself:

“A movie is not worth watching and a book is not worth reading if it does not bring even a slightest change in the traditional customs/practices that it addresses or intends to eliminate”.

Such movies/books do only one good thing…make the persons involved with it richer.
I had not seen 3 idiots (and will probably never watch it) but from what I have heard/read in recent times, it addresses the “traditional Indian education model” which involves theoretical approach to studying (Correct me if I’m wrong). No doubt, cramming stuff had been ‘pillar’ of Indian education system and many criticize it, but then it should be responsibility of current Indian students (I suppose at least 90-95% of them are 3 idiots fans) to make sure that they study quality stuff to live up to name of “fan of 3 idiots”. And this is not happening. Take my college batchmates for example. In a semester, we get less than 25-30 hours for each subject. And in those 25 hours, we (fan of 3 idiots and the ones criticizing education system) are dictated at least 100 pages of theory (by our faculties) during lectures and we (99.99% of us) never ever stand up against this. We get into practical stuff for only less than 10 hours and I won’t vouch for quality of practical studies either. When the fuck are we studying? (mind you, I don’t count lecture notes like this as studying) What is the difference between those who are criticized in 3 idiots and us? Our faculties are told beforehand by our course coordinator that our batch needs elaborated and loooooong class notes (that are of worst quality in most cases). In short, traditional educations system supporters are wrong, but then we are not right either.

Whats should I do?
If they are not teaching the right thing the right way, do hard work yourself. Read good books yourself (Seriously speaking, read a 800 pages book 5-10 or more times if you need to…in the end, you will get it and it will be worth it). Learn to make proper use of internet. And protest/stand up against exiting customs in Indian education system whenever the need arises. Otherwise, what was the purpose of watching 3 idiots. Be a real Indian (student).

A practical real life example
A fact that I noticed in my college classes. The amount of enthusiasm shown and questions asked (by my class mates) during ‘Accounts and financial management’ were at least 5 times more than total number of questions asked in all computer related subjects. Many batch mates are planning to do a management etc PG degree as they don’t understand programming. Why the fuck you guys then joined a computer applications course in first place then? Goto a career counselor first.

And yes, not to forget, the situation is same in ALL other colleges (at least technical ones) across the whole country. I have friends in other parts of India with similar views (the most famous topic of talks among us is “yashwant kanetkar’s books + Borland Turbo C++ COMBO“)

Why is this happening?
Because the motto of Indian students (majority of them who enroll themselves in a professional course) is to secure a job (plus earn quick and cheap ‘money and fame’). “Hey! Impetus, Infosys, TCS etc are visiting our campus for placements…. and I have a professional degree MBA/MCA etc hurry let’s get a job!” stop the fuck now … you crap holes!!!

Okay…Other than all this, 3 idiots is fine. Isn’t it?
NO.
The lyrics of the song “Give me some sunshine” handle the life on ‘backfoot’. When it says “…ab kuch pal toh hamen jeene do” (i.e. Let us live some moments the way we wish to live them), it appears as if we are beggars. It should rather go like: “…ab kuch pal toh hum apne hisaab se jiyeenge” (Now we will live our life the way we want to). Manage rhyme scheme of the lyrics yourself. Maybe the world will call you ‘outcast’ (take me as a live example) but in the end it will be worth it. Stand against what is wrong at any cost. And yes, all outcast humans I had heard of are happy that they chose the other way (Take Steve Jobs or Linus Torvalds for example).
Quoting Sir Steve Jobs (Apple’s CEO) from his commencement speech (Link) at Stanford (Read above quote carefully until you understand it’s purpose here in this text):

“You can’t connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future.”

So you will never know whether your decisions will prove you right in future. But you have got to believe in your heart and intuition and choose the path of outcasts if needed. And in this era of internet (mind you, orkut/IM etc is not real internet), you can always get help from other experts. Google, IRC, forums, personal websites, weblogs exists for this purpose. Just make sure that the source is knowledgeable and trustworthy.

And yeah, the song “Aal Izz Well” in the movie uses wrong words too. It would be better if it’s lyrics were like “snafu snafu” (snafu == situation normal, all fucked up). snafu better describes the ‘suckfull’ Indian students who will continue to crap till they die.

Amber, you suck….you are stupid!
Oh yeah. True.
Joining facebook, orkut, myspace fanpages/groups; getting involved in all is well and give me some sunshine related convesations; talking about 3 idiots; blog posts etc tells that you never really understood the importance and meaning of message in 3 idiots. Do some hardwork yourself.
As one of IBM’s (?) ad campaign says: “Stop talking. Start doing”

If you are/were already doing the ‘right’ thing, drop me a mail. I’ll love to listen a few words from you. If loads of students do the right thing, I promise that I’ll watch 3 idiots then because it will be worth it then.

— The End —

I want to end this blog post in a good mood. Oh yes…Cartoon network is good. Tom and jerry comes to my rescue…
Tom and Jerry
🙂

Written by Amber Jain

January 9, 2010 at 2:32 PM

g++ warnings on OpenBSD: “strcpy() is almost always misused, please use strlcpy()” and “strcat() is almost always misused, please use strlcat()”

with 4 comments

strcpy() and strcat() related warnings on OpenBSD with gcc/g++

I have a box with OpenBSD 4.5 installed. When compiling c++ programs using g++, I get following warnings:

/usr/lib/libstdc++.so.47.0: warning: strcpy() is almost always misused, please use strlcpy()
/usr/lib/libstdc++.so.47.0: warning: strcat() is almost always misused, please use strlcat()
Well, “Unix Programming Tools” from Stanford’s website says:
“Getting used to compiles that produce “a few warnings” is a very bad habit”.

I asked the reason for these warnings on ##c++-basic on irc.freenode.net. The guys there suggested me some options (e.g. -Wno-deprecated, -Wno-deprecated-declarations)

Then somehow this thought strike my mind. What if this has something to do with ‘propolice’? OR What if this is OpenBSD related issue (?) OpenBSD strives hard to be secure. Although, not all OpenBSD packages go through rigorous security audit, but then gcc is something that is likely to be ‘modified’ to fit OpenBSD’s goals. So, I asked this on #openbsd (at freenode). Here’s the IRC log:

AmberJ> Why does gcc/g++ outputs 2 warnings: “strcpy() is almost always misused, please use strlcpy() [and the same with strcat]”….Is it because openbsd has propolice enabled?
….because I don’t seem to encounter those warnings on other OSes with propolice disabled
AmberJ: it’s a linking warning, you’ll only see it when you link something that uses strcpy() etc
oenone, But why those warnings pop up only on OpenBSD ?
AmberJ: because other OSes don’t have the warnings in their version of libc

I updated this info to ##c++-basic. IRC-log:

AmberJ> That’s it! I hope that is the answer to my original question
jps_77, SukhE metabol Leoneof` thanks all🙂
AmberJ: that was a retarded reply that you got in #openbsd
try in #gcc

I then tried at #gcc as suggested(at freenode). IRC log:

AmberJ> Why does gcc/g++ outputs 2 warnings: “strcpy() is almost always misused, please use strlcpy() [and the same with strcat]”….Is it because openbsd has propolice enabled?
I’m using gcc 3.3.5 (propolice)
Ofcourse, I’m using OpenBSD 4.5
AmberJ: that sounds a lot like OpenBSD broke it. (they invented those l forms)
noshadow, Someone at #openbsd mentioned: “Other OSes don’t hae similar warnings because other OSes don’t have the warnings in their version of libc”
AmberJ: yes, that’s a possible place where they could have put those uncessary warnings.
noshadow, ok ty🙂
though the warning is really the wrong way round. why strcpy is usefull often, strlcpy is always always misused…
ok

Ofcourse, you can feel the ‘anti-openbsd’ feeling in the air😉

In the end, the folks at ##c++-basic suggested me that I try to install a newer version of gcc i.e. 4.x (mind you, gcc/g++ 3.3.5-propolice is the version that is shipped with OpenBSD 4.5) and if this problem persists (Is this really a problem? Read this. I suppose the warning is apt.), they suggested that I try to compile gcc from source.

More soon.

🙂

Written by Amber Jain

January 9, 2010 at 1:24 PM