Thursday, May 6, 2010

How to calculate tax

The following code is to calculate tax amount we will pay for tax year 2010.





#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


typedef struct {
double min;
double max;
double taxPct;
} Bracket_t;


typedef enum {
single,
married_jointly,
married_separately,
head_of_household
} FilingStatus_t;




// married filing separately
Bracket_t BracketTable2008[] = {
{0.0, 8025.0, .10},
{8025.0,32550.0, .15},
{32550.0,65725.0, .25},
{65725.0,100150.0, .28},
{100150.0,178850.0, .33},
{178850.0,-1.0, .35},
{-1.0,-1.0,0.0}
};




Bracket_t BracketTable2010[] = {
{0.0, 16750.0, .10},
{16750.0,68000.0, .15},
{68000.0,137300.0, .25},
{137300.0,209250.0, .28},
{209250.0,373650.0, .33},
{373650.0,-1.0, .35},
{-1.0,-1.0,0.0}
};


double TaxCalc(double agi, Bracket_t *brYear)
{
int i;
double totalTax, tax, income;




if (!brYear)
return -0.0;
i = 0;
tax = 0.0;
totalTax = 0.0;
income = agi;
printf("agi = %9.2lf\n", income);
while (brYear[i].min > -1.0) {
if ((brYear[i].max > -1.0) && (income > brYear[i].max)) 
{
tax = (brYear[i].max - brYear[i].min) * brYear[i].taxPct;
}
else
{
tax = (income - brYear[i].min) * brYear[i].taxPct;
totalTax += tax;
printf("end of tax; bracket=%4.2lf, tax = %9.2lf\n", brYear[i].taxPct, tax);
break;
}
totalTax += tax;
printf("%d) tax = %9.2lf (%4.2lf), taxable income = %9.2lf\n", i, tax, brYear[i].taxPct, income);
i++;
}
printf("%d) taxable income = %9.2lf => tax = %9.2lf\n", i, income, totalTax);
return totalTax;




}




int main(const int argc, const char *argv[])
{
double agi, tax;
Bracket_t *tbl;


if (argc > 1)
{
printf("You entered %s\n", argv[1]);
agi = strtod(argv[1], NULL);
tbl = BracketTable2010;
}
else {
                // demo only for tax year 2008
tbl = BracketTable2008;
agi = 1e5;
}
tax = TaxCalc(agi, tbl);


printf("Final tax amount = %9.2lf (%4.2lf%%)\n", tax, tax/agi * 100.0);
}

Example:
$ ./tax 100000
You entered 100000
agi = 100000.00
0) tax =   1675.00 (0.10), taxable income = 100000.00
1) tax =   7687.50 (0.15), taxable income = 100000.00
end of tax; bracket=0.25, tax =   8000.00
2) taxable income = 100000.00 => tax =  17362.50
Final tax amount =  17362.50 (17.36%)

The income we enter is the AGI (Adjusted Gross Income), which is our total gross income minus all the deductions.

Sunday, March 28, 2010

To add a new user into Samba server

Have you ever had problem accessing a remote Linux machine from your windows, but Windows (XP/etc.) keeps asking for password (in other word, our account is always denied)? If you have, most likely is that our Linux server doesn't have the credentials to allow such username.  This occurs if we don't use PDC.

When you check the log (/var/log/samba/log.*), you would find something like this:


[2010/03/28 23:26:35,  1] smbd/service.c:676(make_connection_snum)
  create_connection_server_info failed: NT_STATUS_ACCESS_DENIED


The following simple command will create a new user in Samba server (e.g, "newuser" should match with the user in the Linux machine managed by PAM module).


mnt$ sudo smbpasswd -a -U newuser
New SMB password:
Retype new SMB password:
Added user newuser.

Now, from Windows explorer, we can just type "\\linuxserver\newuser".  It will then ask for password.  Use the password we entered above.

Tuesday, February 9, 2010

2010 Technologies for PC

Year 2010 or early 2011 will be interesting for PC buyers who are thinking to buy a new computer.  First of all, The USB 3.0 (SuperSpeed USB) will be available on many PC motherboards late this year.  Another thing is a series of new microprocessors from Intel which intergrate GPU in their dice.

Tuesday, February 2, 2010

iPad, iSlate, Kindle or what?

Apple iPad was introduced by its CEO, Steve Jobs, last week.  Despite its slickness and coolness, it still runs LED LCD screen.  The new HP Tablet to-be-released will also be running LCD.  Kindle from Amazon is in different direction.  It uses a like-book screen from E Ink ( a spun off of MIT-lab company), but it only is black-and-white (though can display different grades of grey) and too slow for most of computing works today, except for reading e-books.

There is a new startup founded by Mary Lou Epsen (does OLPC [One Laptop Per Child] project click you?) that goes to a little bit different.  Their claim the new LCD screen they are producing is a marriage between both worlds: the fast-response and colorful of LCD with reflection-light and power-saving of E-ink.

Looking at their website (http://www.pixelqi.com/about_us), most of their executives and board members hold Ph.D, either in optics, electrical engineering or physics.  Quite impressive.  The product they're making is called "Pixel Qi".

I was wondering why iPad doesn't use their screen for iPad? too expensive? I am eager to see a computer company to use their product for a power-efficient next generation tablet PC (I am no fan of Netbook.  I agreed with Mr. Jobs in his presentation that Netbook is just a slow smaller-than-laptop PC running memory-hungry Windows XP or not-that-popular Linux).

I was thinking to get this iPad, but after reading an article about this Pixel-Qi on Popular Science magazine, I am thinking to just wait and see how people's responses surface later on and will decide later.

If you're in the market ready to throw some money for a new netbook, be patient and wait for the getting-hotter market of tablet computers to select the best of the breed.