Getting the first letter of every word in a String using Java

This is a sample code on getting the first letter of every word in a String using Java. This may be helpful if you want to get the middle initial out of a middle name. If you have a middlename String with “de la Hoya” value and you want to have “dlH” then you use the code below

public class Test {
   public static String generateInitials ( String original ){
       String initial = "";
       String[] split = original.split(" ");

       for(String value : split){
            initial += value.substring(0,1);
        }

        return initial;
    }

    public static void main(String[] arg){
        System.out.println( generateInitials("de la Hoya") );
    }
}

Compiling and runnning the code will output dlH in your command line

Formatting USB drives using Slackware

So you have decided to format your USB flash drive because of those annoying viruses. Using Slackware, formatting can be done in just a couple of commands.

1. Plug your USB flash drive to your PC
2. If it is automatically mounted, the you must unmount it. (You need root privileges)
sudo su
3. Check the device of your USB, if it is automatically mounted, you can check it by using df command
df -h
You can see it at the buttom result, like for example /dev/sdc1—-419M—–4.0k——419M—–1%——-/media/disk
the first value /dev/sdc1 is your USB device
419M is the total space
4.0k is the used space
419M is the available space
1% is the total usage
/media/disk is where it is mounted

4. Supposing your USB drive is detected as /dev/sdc1 and you have of course 1 partition on it, unmount it by
umount /dev/sdc1

5. Use fdisk to alter the partition table if you want changes.
fdisk /dev/sdc
Use the fdisk help to navigate through the commands. Then type w if you are done. This will write/save the new partition table to your disk

6. Then you can format it. If you want your disk to be universally recognized, then use vfat 32. Before formatting make sure that your disk isn’t mounted, check it using
df -h

7. To format it for vfat 32, then
mkfs.vfat -F 32 /dev/sdc1
All data is erased, and your USB flash drive is now formatted

8. To check out other filesystems which can be used by mkfs
ls /sbin/mkfs\.

Compiling new kernel on Slackware 12.2

I have visited http://www.kernel.org to check the latest version of the Linux kernel. At this writing, version 2.6.29.3 was the latest. So I have downloaded it from here. I wanted to install and test the new features of this kernel. Here are the steps I made to compile and use it.

1. Acquire root privilege
sudo su

2. Download the kernel sources
fetch http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.29.3.tar.bz2

3. copy the sources to /usr/src
cp ./linux-2.6.29.3.tar.bz2 /usr/src

4. extract the sources
cd /usr/src/; tar xvjf linux-2.6.29.3.tar.bz2

5. go inside the new linux kernel source directory
cd ./linux-2.6.29.3

6. Clean the directory
make clean

7. Make the configuration file or have an old one loaded
make menuconfig

8. If you want to load your old kernel’s config file, scroll at the buttom of the screen and choose Load an alternative Configuration File
and type the location of your old configuration file
/boot/config-huge-2.6.27.7

9. When the config is loaded, check other kernel settings you might want to change, and enable or disable a module by selecting it from the list. The configuration file you have just loaded works since it was the one included in your distro, so if you want new features then scroll and select it from the list.

10. After selecting the features you wanted to compile or added as a module, go to the exit at the buttom of the page, then click ok to exit the menuconfig.

11. Make the kernel
make

12. Install the kernel
make install

12. Make the kernel image
make bzImage

13. Make and install the modules
make modules && make modules_install

14. copy the new image to /boot
cp ./arch/i386/boot/bzImage /boot/vmlinuz-2.6.29.3-CUSTOM
and your config to /boot
cp .config /boot/config-2.6.29.3-CUSTOM

15. Create an initial ramdisk. (change the ext3 to whatever file system you use and the device file in which your root partition resides. In my case, my / is on device /dev/sda5)
mkinitrd -c -k vmlinuz-2.6.29.3-CUSTOM -m jbd:ext3 -f ext3 -r /dev/sda5

16. After the mkinitrd command, it will generate /boot/initrd.gz. If you want, you can change your initrd.gz name.
mv /boot/initrd.gz /boot/initd-2.6.29.3-CUSTOM.gz

17. Edit your /etc/lilo.conf and add new entries at the buttom. Don’t remove the old settings so you would have a fallback.
Add these lines. Change the root value to the device for your / partition. You can also change the label.
image = /boot/vmlinuz-2.6.29.3-CUSTOM
initrd = /boot/initrd-2.6.29.3-CUSTOM.gz
root = /dev/sda5
label = Linux-2.6.29.3
read-only

18. After saving your lilo.conf, install it.
lilo

19. Restart your computer
reboot

Then on the bootsplash screen, select your new kernel and If you're lucky, it will work!

FreeBSD 7.2-Release dbus error on fresh install

Just downloaded FreeBSD 7.2-RELEASE amd64 at http://www.freebsd.org/where.html. I was so excited to install it, since 7.1 wont install on my AMD Phenom X3 8650 machine. OK, so the usual text-based installation went smooth. I chosed the GNOME packages since I have read that it includes GNOME 2.26. I also had the ports collection installed. After installation, I have to first login at the console. I have edited my .xinitrc to point it to start GNOME using gdm.

When I executed startx at the command prompt, I had this error that has something to do with dbus thing. So I have searched the FreeBSD forums for answers. I then created a thread so as for the Gurus to help. Then after sometime, I learned that the dbus should be enabled before gdm. Here is what I did.

Edit your /etc/rc.conf using your favorite editor and add the following lines to fix the dbus thing and automatically start GNOME after rebooting your computer

dbus_enable="YES"
hald_enable="YES"
gdm_enable="YES"

Restart your PC
shutdown -r now