Tuesday, October 12, 2010

To test Prime Number

#include <stdio.h>


typedef enum {
    FALSE = 0,
    TRUE = 1
} BOOL;

char *boolstr[] = {"FALSE", "TRUE"};

BOOL is_even(unsigned int k)
{
    if (k % 2) return FALSE;
    return TRUE;
}

BOOL is_prime(unsigned long k, unsigned long *divisor)
{
    unsigned long testnum,testlimit;
    BOOL ret = FALSE;

    if (k == 1) return FALSE; // 1 is neigher prime neither composite
    if (k == 2) return TRUE;
    if (is_even(k)) return FALSE; // even numbers are never prime, except 2
    testlimit = k;
    testnum = 3;
    while (testnum < testlimit) {
        //printf("highest prime divisor=%lu\n",*divisor);
        if ( (k % testnum) == 0)
        {
            *divisor = testnum;
            printf("div=%lu\n", *divisor);
            return FALSE; //return TRUE;
            // k is not prime as it is divisable by l

        }
        testlimit = k/testnum;
        testnum += 2;

    }
    return TRUE;
}


int main()
{
    unsigned long k,divisor;

    divisor=1;
    printf("Enter an integer: ");
    scanf("%lu", &k);
    printf("k=%lu is even? %s\n", k, boolstr[is_even(k)]);
    if (is_prime(k, &divisor))
    {
        printf("k=%lu is prime? %s\n", k, boolstr[TRUE]);
    }
    else
    {
        printf("%lu is NOT prime\n", k);
        //printf("highest prime divisor = %lu\n", divisor);
    }
}

Tuesday, October 5, 2010

3D Entertainment

While 3D televisions are more available in the stores, their price is still high and not many people are getting into it.  Perhaps because there is still few BD 3Dd movies.  But now 3D camcoders are going into the market.  We will see if this change how people buy LCD TVs.

Today, when I went to Costco, the 42" 120 Hz LED 3D TV is already below $2000.

Monday, October 4, 2010

Power consumption and Cost saving of Using Ooma (revised)

After awhile, I observed that this Ooma + router consume less power when the temperature is lower.  In the previous blog, I said the average power when its idling is 27 W @ 25 C, but in the early morning when temperature is lower (at about 20 C), the idling power is only 14 W and 17 W when the handset is off-hook.

Sunday, October 3, 2010

Power consumption and Cost saving of Using Ooma

Devices measured:


  1. Ooma hub
  2. Linksys WRT54g wireless router
  3. Traditional wired phoneset connected to Ooma


Power-meter: Kill-A-Watt EZ

Result:

  • System idle: 27 watt
  • Phone is off hook (dial tone): 30 Watt
  • Phone is dialing: 30 Watt
  • During talk: 30 Watt
  • Check voice mail tru the hub: 28 Watt


How much the electricity cost we pay monthly?
For Northern California, PGE has a chart describing the rate.  The average KWH rate for residential seasonal schedule E-8 is $0.22832 (this is just an average, the actual calculation depends on the tier/how much we consume electricity above its baseline).  So, the maximum KWH for Oma in a day is: 30 Watt * 24 hours = 720 WH = 0.72 KWH.  In a month (30 days) = 21.6 KWH or it costs = $4.32

If we don't subscribe to Ooma premier service, there is no additional cost, so it is the actual monthly cost we pay.  If we subscribe to annual Ooma premier service which $119.99/year, we end up paying: $119.99/12 + $4.32 =  $14.32 (rounded up) per month.

As a comparison, when I subscribed to AT&T landline local service (local unlimited), I paid (total, including all the fees and taxes) $27.15.  This did not include caller-ID and all other features.  It was just bare minimum.  With Ooma premier, besides we get caller-ID, we also get two lines, call forwarding (or simultaneous ringing to another number), broadband voice mail (with MP3 file can be sent to email we specified), and other features.  AT&T could have charged those features for additional $15 or more.

Now, how much we save by using Ooma?  OK, first we need to take to the account the broadband portion used for Ooma.  For example, I pay AT&T U-Verse 10 Mbps/1 Mbps (downstream/upstream) $45 a month.  In average, Ooma uses a fractional bandwidth, which is about 256 Kbps.  The max fraction of cost (hypothetically) is then = 0.256/10 * $45/month = $1.152, or about $1.2/month.  Assume we use Ooma premier, the total monthly cost is then $14.32 + 1.2 = $15.52/month.  The saving is = $27.15 - $15.52 =  $11.63/month.


The price of Ooma hub (including one Ooma scout) is $219.99 (at www.ooma.com) +sales tax (which is 9.25% in my area) or $240.34.  The number of months to recover the cost using the amount of money we save above is then $240.34/$11.63 = 20.66 months, or say 21 months (1.75 years).  After that, the saving we collect is going to our pocket.  If you decide not to use Ooma more than 1.75 years, you won't save any.

Note: the calculation above does not include power consumption of Ooma scout, but I surely is smaller than the hub's.

Wednesday, September 29, 2010

ReadyNAS Duo Internals

This very cool NAS Box runs a version of Linux (I think Debian):

nas-D0-E9-23:/c/home/admin# uname -a
Linux nas-D0-E9-23 2.6.17.8ReadyNAS #1 Tue Jun 9 13:59:28 PDT 2009 padre unknown

nas-D0-E9-23:/c/home/admin# cat /proc/cpuinfo
cpu : Infrant Technologics, Inc. - neon version: 0
fpu : Softfpu
ncpus probed : 1
ncpus active : 1
BogoMips : 186.36
MMU : version: 0
LP : HW.FW version: 0.1
FPGA : fpga000000-0 Configuration: 0
AHB arbitraion : 7
CPU id : 0
Switch : 0
ASIC : IT3107

nas-D0-E9-23:/c/home/admin# lspci
0000:00:17.0 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 62)
0000:00:17.1 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 62)
0000:00:17.2 USB Controller: VIA Technologies, Inc. USB 2.0 (rev 65)

nas-D0-E9-23:/proc# fdisk -l /dev/hdc

Disk /dev/hdc: 999.9 GB, 999991611392 bytes
255 heads, 63 sectors/track, 121575 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/hdc1 1 255 2048000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/hdc2 255 287 256000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/hdc3 287 121575 974242116 5 Extended
/dev/hdc5 287 121575 974242115+ 8e Linux LVM

Compared to my HP desktop machine, this NAS Box is away slower:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz
stepping        : 11
cpu MHz         : 1600.000
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 4
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dt
s acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good aper
fmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexpriori
ty
bogomips        : 12479.54
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

Despite the fact, I love this new toy!

Sunday, September 26, 2010

Useful status line in vi

:set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]