Month: February 2007

Working with PHP and Excel

Working with PHP and Excel

Introductions –

PHP got libraries through which we can create or access the excel data. There are two possible ways of creating or accessing the excel data in PHP

1) PHP – Excel library provided by PEAR.
2) PHP using Excel COM component functions and libraries.

** In PHP – Excel libraries, Spreadsheet_Excel_Reader is the class through which we can read the data from excel file. Online documentation is available on following url … http://pear.php.net/package/Spreadsheet_Excel_Reader

Spreadsheet_Excel_Writer is the class to write the data in a excel file. Online documentation is available on following url … http://pear.php.net/package/Spreadsheet_Excel_Writer

** Using Excel – COM components we can create, read the data from excel file easily. Here is
The small code which uses COM components to read the excel data….

<?php

$exlObj = new COM(“Excel.Application”) or Die (“Did not connect”);
$exlObj->Workbooks->Open(“test.xls”);
$exlBook = $exlObj->ActiveWorkBook;
$exlSheets = $exlBook->Sheets;
$exlSheet = $exlBook->WorkSheets(1);
echo $exlSheets->Count;
echo $sheetName = $exlSheet->Name;
$cell = $exlSheet->Cells(1, 1);
echo $cell->Value;

?>

Using both libraries writing excel with all formatting is available. And comparatively PHP-Excel COM components function provides a lot of functionalities to work with excel sheet on the fly.

I have tried to modify the existing excel sheet but it is not happened with both PEAR excel library and Excel COM libraries. I think it is not possible to modify the excel on the fly with out disturbing any color combinations. If any one got the solution looking for their comments….

Thank you,
Santhosh Tirunahari

OpenMoko – open source mobile platform

OpenMoko – open source mobile platform

Introduction –

OpenMoko is the Free and Open Source Mobile Platform. The entire OpenMoko system and application software are built using Free and Open Source Software (FOSS). On the system side,openmoko OpenMoko uses software with a tireless history of success and stability, such as the Linux kernel, the GNU C library, the X window system, and the GTK+ toolkit etc… Open source is not a new concept but for the mobile world this is an entirely new concept. OpenMoko is just taking things mobile. For mobile developers OpenMoko is the best place to start. Since OpenMoko runs libraries and components commonly found on the computer….

Neo 1973
is the first free and open source mobile by OpenMoko. The Neo Base kit contains everything the mobile application developer needs to enjoy the benefits of the first free phone.

openmoko-neo

Neo 1973 – Hardware specifications –

  • 2.8″ VGA TFT color display
  • Touchscreen, usable with stylus or fingers
  • 266MHz Samsung System on a Chip (SOC)
  • USB 1.1, switchable between Client and Host (unpowered)
  • Integrated AGPS
  • 2.5G GSM – tri band (900/1800/1900), voice, CSD, GPRS
  • Bluetooth 2.0
  • Micro SD slot
  • High Quality audio codec

Cheers,
Arun Bagul

Ubuntu – GRUB splash image as background for GRUB menu

Ubuntu – GRUB splash image as background for GRUB menu

Introduction –

Why Ubuntu does not provide GRUB splash image as background for GRUB selection menu?. Really I don’t know but, today we will learn how to do it.

root@arunbagul:~# apt-get install grub-splashimages
Reading package lists… Done
Building dependency tree

….
root@arunbagul:~#

Once you install “grub-splashimages” you will get grub splash image installed on your Ubuntu system in “/boot/grub/splashimages” directory.

root@arunbagul:/boot/grub/splashimages# update-grub
Searching for GRUB installation directory … found: /boot/grub
Searching for default file … found: /boot/grub/default
Testing for an existing GRUB menu.lst file … found: /boot/grub/menu.lst
Searching for splash image … none found, skipping …

…….
Updating /boot/grub/menu.lst … done

root@arunbagul:/boot/grub/splashimages#

update-grub is a program used to generate the menu.lst file used by the grub bootloader. It works by looking in /boot for all files which start with “vmlinuz-“. They will be treated as kernels, and grub menu entries will be created for each. It will also create the initial menu.lst if none exists, after prompting the user. It will also add initrd lines for ramdisk images found with the same version as kernels found. e.g. /boot/vmlinuz-2.4.5 and /boot/initrd-2.4.5 will cause a line of “initrd=/boot/initrd-2.4.5 or similar to be added for the kernel entry in the menu.lst. After update-grub has been run for the first time, the user is required to edit the generated menu.lst.
Cheers,
Arun Bagul

How to configure Local DNS caching!

How to configure Local DNS caching!

Introductions –

DNS server resolves domain names into IP addresses. So when you request “yahoo.com” for example, the DNS server finds out the address for the domain, and sends your request the right way.

You can run a DNS cache on your system This will speed up the process of looking up domain names while browsing. The difference is about 35-55ms. dnsmasq is the tool, we will be using for caching nameserver lookups

** How to install dnsmasq –

root@arunbagul:~# apt-get   install  dnsmasq
Reading package lists… Done
Building dependency tree

….
root@arunbagul:~#

** How to configure dnsmasq –

The configuration file for dnsmasq is /etc/dnsmasq.conf. you can specify customized setting in this file…

root@arunbagul:~# vi /etc/dnsmasq.conf
root@arunbagul:~#

Now uncomment the following line in /etc/dnsmasq.conf file. So that dnsmasq will listen on local loop ie 127.0.0.1 address.

listen-address=127.0.0.1

Now edit /etc/dhcp3/dhclient.conf and make sure that it looks  as shown below…

root@arunbagul:~# cat /etc/dhcp3/dhclient.conf

prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, host-name,
netbios-name-servers, netbios-scope;

….
root@arunbagul:~#

How it dnsmasq works? –

If you are using DHCP connection ,then whenever you get a new dhcp lease, the dhcp3 client will updates the /etc/resolv.conf file on your system with the right values for the DNS servers to use. Adding the “prepend” option as we did above ensures that “nameserver 127.0.0.1” will appear on the top of the list of DNS servers. So in the future, whenever your system want to resolve a domain name, it will forward that request to local dnsmasq. dnsmasq maintains it’s own cache. If the details for the domain name are already in you cache, well and good, dnsmasq will serve it up and make the process real fast. If it is not in the cache, then dnsmasq will look at the /etc/resolv.conf file and use the nameservers listed below the line “nameserver 127.0.0.1″…

Check your /etc/resolv.conf file –

root@arunbagul:~# cat /etc/resolv.conf
search indiangnu.org
nameserver 192.168.1.10
nameserver 192.168.1.11
root@arunbagul:~#

where is “nameserver 127.0.0.1” entry? This is because. Since dhcp haven’t renewed your lease after editing the /etc/dhcp3/dhclient.conf file. Let us add that in manually. see below

root@arunbagul:~# cat /etc/resolv.conf
search indiangnu.org
nameserver 127.0.0.1
nameserver 192.168.1.10
nameserver 192.168.1.11
root@arunbagul:~#

** Now is to start dnsmasq so that the changes we made to the configuration file take effect-

root@arunbagul:~# /etc/init.d/dnsmasq
Usage: /etc/init.d/dnsmasq {start|stop|restart|force-reload}
root@arunbagul:~#

root@arunbagul:~# /etc/init.d/dnsmasq start
Starting DNS forwarder and DHCP server: dnsmasq.
root@arunbagul:~#

Yes!! we are running our local DNS cache. If you want to measure your speed improvement then dig to some domain and find out how fast is Local DNS cache!

root@arunbagul:~# dig yahoo.com
root@arunbagul:~#

command(1) dnsmasq – is a lightweight DHCP and caching DNS server. Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. It loads the contents of /etc/hosts so that local hostnames which do not appear in the global DNS can be resolved and also answers DNS queries for DHCP configured hosts. The dnsmasq DHCP server supports static address assignments, multiple networks & DHCP-relay.

Options

-h, –no-hosts
Don’t read the hostnames in /etc/hosts.

-H, –addn-hosts=<file>
Additional hosts file. Read the specified file as well as /etc/hosts.

-E, –expand-hosts
Add the domain to simple names (without a period) in /etc/hosts in the same way as for DHCP-derived names.

-T, –local-ttl=<time>
When replying with information from /etc/hosts or the DHCP leases file dnsmasq by default sets the time-to-live field to zero, meaning that
the requestor should not itself cache the information. This is the correct thing to do in almost all situations.

-k, –keep-in-foreground
Do not go into the background at startup but otherwise run as normal. This is intended for use when dnsmasq is run under daemontools or
launchd.

-d, –no-daemon
Debug mode: don’t fork to the background, don’t write a pid file, don’t change user id, generate a complete cache dump on receipt on
SIGUSR1, log to stderr as well as syslog, don’t fork new processes to handle TCP queries.

-q, –log-queries
Log the results of DNS queries handled by dnsmasq. Enable a full cache dump on receipt of SIGUSR1.

-x, –pid-file=<path>
Specify an alternate path for dnsmasq to record its process-id in. Normally /var/run/dnsmasq.pid.

-u, –user=<username>
Specify the userid to which dnsmasq will change after startup. Dnsmasq must normally be started as root, but it will drop root privileges
after startup by changing id to another user. Normally this user is “nobody” but that can be over-ridden with this switch.

-g, –group=<groupname>
Specify the group which dnsmasq will run as. The defaults to “dip”, if available, to facilitate access to /etc/ppp/resolv.conf which is not
normally world readable.

-v, –version
Print the version number.

-p, –port=<port>
Listen on <port> instead of the standard DNS port (53). Useful mainly for debugging.

Cheers,
Arun Bagul