First business: Bad Experience

Here I want to share the first and the only business I got into ever. I lost money. Lot of it (for me!). It was a sunny sunday morning when I read about making money sitting from home and I instantly ordered the education kit for the same. Among the many money making ideas were following :-

1 reading advertisements
2 reading mails
3 writing advertisements (similar to one that I read)
4 Publishing free ebooks (for making money) and earning through ads
5 affiliate

option 5 works. I did not try it since I do not have that much readership. alas.

I tried 1, 2 and 3. option 3 required me to advertise as well using Google Adwords. Initial signup with it gave $50 credit into the account for free. They took my credit card information. Way it works is that once your $50 is used up, they start charging your card. I did not know this.

I forgot about the Google thing, kept checking my account where money had to come and was happy to see that it actually was working. After one and half months, I got a call from my credit card bank that I need to pay a huge sum of money for the transactions made that was sixty thousand bucks in my currency. I was Shocked. I had to pay anyways. I was now depressed and doubtful for any payments as well. I immediately did the payments to the credit cars, cancelled the google account and cancelled the credit card as well. Few days later I got several cheques. So that was not fraud. My earnings were a total of Twenty four thousand bucks. A total loss of Thirty Six thousand.

A lot of learnings from this case :-

> Understand the business. Read the T&C
> keep track of accounts where you share your credit card information. This is cost.
> Advetisement is not expense, it is an investment.
> I did not get a single penny from reading ads and emails. They pay little per unit and hence accrution rate is dead slow. Can’t say in general but some companies are simply fraud.

Bad experience but I learned a lot of things.

Advertisements

WCHAN in ‘ps -l’

on Linux/x86, ps -l command gives a long listing. Field WCHAN in the listing caught my interest.

-bash-2.05b# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR    SZ WCHAN  TTY          TIME CMD
4 S     0    21597 21595  0  76   0    –           1096 wait4  pts/2    00:00:00 bash
4 R     0   21677 21597  0  80   0    –            794    –      pts/2    00:00:00 ps

looking at the man page, I could find out what it displays –

WCHAN    address of the kernel function where the process is sleeping (use wchan if   you want the kernel function name). Running tasks will display a dash (’-’) in this column.

‘ps -l’ uses System.Map file for reading the symbols.

Rails: getting multiple selected values from selection box

I got stuck for last half an hour at ‘getting the values of multiple selected items in a muliple selection box’ using Ruby/Rails. Got it after hard ‘googling’ and got the solution here.

When trying to get multiple selected values from a <SELECT> tag into @params, call your parameter something with [] on the end. That way rails knows it’s multiple.

So instead of

<select name="job[techs]" size="5" multiple="multiple">

Use:

<select name="job[techs][]" size="5" multiple="multiple">

Thanks google and Ruby/Rails community !

killer sign extension

Yesterday, I got to know clearly why you should not ignore compiler warnings without very strong reasons. Our price was a panic. what can be worse ?

Problem – missing prototype of a function.
Have you gone crazy ? How can that cause a panic ?

My function had actual signature like this

char * func(char *, char *)

but since the function declaration is missing, its assumed prototype is like

int func(char *, char *)

‘char *’ is an address and hence on a 64 bit machine it is 64 bit. ‘int’ on the other hand is 32 bit on the machine. A downcasting happens on the return in this function. so a 64 bit address is typecasted to int. Then the return value i.e. 32 bit is assigned to a char * which _may_ lead to sign extension and hence higher 32 bits are filled with 0xff bytes. This leads to an invalid kernel address and hence panic !

but what are the scenarios when this address may get sign extended ?

Not sure. Maneesh, gave a wonderful test program for understanding the sign extension. Following is the program with comments !

/* Experience Signed extension:
* Having signed bit ON (char *s below) in original pointer, will
* lead to add all 1s in signed extension (typecasting from int to
* pointer), and hence result in different address in following example.
* While having signed bit OFF (char *s1), will lead to add only 0s in
* the signed extension (casting from int to pointer), and hence no change
* in the address.
*
* compile the program with +DD64 option in cc
* (for 64 bit), so that sizeof pointer becomes 8 bytes, and sizeof int remains 4.
* */

#include <stdio.h>

main()
{
char *s=0x80000000;
char *s1=0x70000000;
char *s2;
char *s3;

s2=(char *)(int)s;
printf(“%p , %p\n”,s,s2);

s3 = (char *)(int)s1;
printf(“%p , %p\n”,s1,s3);
}

So sign extension may be killer. Take care while playing with 64bits especially if you are in habit of playing with 32bits.

How do I fix it ?

Never ignore warnings by compiler. Take care while writing code.