Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.

icon.linkedin.jpgicon.twitter.jpg

  • Subscribe to this RSS Feed
  • Redirecting All Web Requests to the WWW. DNS Entry for Your Web Site
    11/20/2011 10:14PM

    If you would like to redirect all non 'www' requests for pages on your site to the 'www' dns entry add the following to your .htaccess file in the document root of your site:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

  • Enabling Parsing and Processing of PHP code in Files With .html Extensions for GoDaddy.com Hosting Accounts
    11/20/2011 9:43PM

    There are times when a web master will want to have the default file extension for a given website stay consistent regardless of how the files are preprocessed on the server-side or what server-side scripting language is being used.

    To set up your GoDaddy.com 4GH, Linux hosted account to parse PHP code in .html files, do the following:

    1. Log in to your account.
    2. Go to the control panel for the web site in question.
    3. In the control panel click on the 'Settings' sub-section.
    4. Click on the 'File Extensions Management' icon/link.
    5. Click on the 'Custom Extensions' link in the left-hand column.
    6. Click on 'New Extension' in the upper right of the page.
    7. Enter '.html' for the extension, and select 'PHP 5.x.x' from the drop-down.
    8. Click 'OK'
    Once you click the 'OK' button you can now add PHP code to your .html files.
  • Cloned VMware CentOS6 Server and "device eth0 does not seem to be present, delaying initialization" Error
    11/17/2011 3:31PM
    Recently, I cloned a vmware install of CentOS6 and after firing up the clone and trying to start networking received the error: "device eth0 does not seem to be present, delaying initialization"

    It turns out that the NIC on the cloned machine was being renamed and registered to eth1.

    To list the current ethn devices:

    # ls /sys/class/net
    eth1 lo

    There is a device manager, udev, which stores the settings from the NIC of the vm prior to the cloning process.  When you clone a vm it also changes the mac address of the NIC and as a result the vm sees it as a new NIC and assigns it to /dev/eth1.

    As a result, we now have to edit the udev config file as well as the ifcfg-eth0 file to get the newly update virtual NIC card to operate on the eth0 device.

    First, edit: /etc/udev/rules.d/70-persistent-net.rules

    # This file was automatically generated by the /lib/udev/write_net_rules
    # program, run by the persistent-net-generator.rules rules file.
    #
    # You can modify it, as long as you keep each rule on a single
    # line, and change only the value of the NAME= key.

    # PCI device 0x15ad:0x07b0 (vmxnet3) (custom name provided by external tool)
    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:bc:00:45", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

    # PCI device 0x15ad:0x07b0 (vmxnet3)
    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:bc:00:46", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"


    Delete the first SUBSYSTEM entry in the file.

    Update the 'eth1' attribute in the remaining entry to 'eth0'

    Edit /etc/sysconfig/network-scripts/ifcfg-eth0

    . Change the HWADDR to match the new mac address listed in the newly edited 70-persistent-net.rules file.

    reboot.
  • Java: Capitalize the First Letter in a String
    11/14/2011 1:15PM

    A seemingly trivial task, but worth jotting down for future reference.

    String sourceString = "this is some string";
    String convertedString = String.format("%s%s", Character.toUpperCase(sourceString.charAt(0)), sourceString.substring(1));

  • Java: How To Use RandomAccessFile and FileChannel to Write to a Specific Location in a File
    10/06/2011 11:32AM

    If there is ever a need to write bytes to a specific location to an existing file, here is an example of how to use the RandomAccessFile and FileChannel Java classes to do so:

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;

    /**
     * Will write bytes to the beginning of an existing file.
     *
     * @author Ryan Chapin
     */
    public class RandomAccessFileTest {

        public static void main(String[] args) {

            // Generate input string and the ByteBuffer for it
            String stringToInsert = "This is a string to insert into a file.";
            byte[] answerByteArray = stringToInsert.getBytes();
            ByteBuffer byteBuffer = ByteBuffer.wrap(answerByteArray);

            File fileToModify = new File("/path/to/file");

            RandomAccessFile randomAccessFile = null;
            try {
                randomAccessFile = new RandomAccessFile(fileToModify, "rw");
            } catch (FileNotFoundException e1) {
                // TODO error handling and logging
            }

            FileChannel outputFileChannel = randomAccessFile.getChannel();

            // Move to the beginning of the file and write out the contents
            // of the byteBuffer.
            try {
                outputFileChannel.position(0);

                while(byteBuffer.hasRemaining()) {
                    outputFileChannel.write(byteBuffer);
                }
            } catch (IOException e) {
                // TODO error handling and logging
            }

            try {
                outputFileChannel.close();
            } catch (IOException e) {
                // TODO error handling and logging
            }

            try {
                randomAccessFile.close();
            } catch (IOException e) {
                // TODO error handling and logging
            }
        }
    }

Advanced Search

Categories

Archives