RSS Entries RSS
RSS Subscribe by Email

Archive for Tips and Tricks

Essential Linux Commands

Getting started on Linux can be challenging.  Largely because the first time user won’t have any idea how to track down potential problems.  The following commands are essential to get additional information about your system when something goes wrong:

  • uname -mr - Shows what kernel version and processor you are running on
  • sudo fdisk -l - Can help you figure out how things are mounted
  • dmesg - Useful for tracking down problems during boot
  • tail -f /var/log/messages - Now run the process giving you problems and you might see helpful error messages

If you’ve got other suggestions, please feel free to comment below.  Thanks!

Buy Me a Beer

Comments

Open Windows Explorer to New Default Directory

To get Windows Explorer to open to a default directory, you can create a new shortcut and modify the path. For example, the following shortcut path will open a directory of documents on a shared drive using Explorer instead of the normal window:

%SystemRoot%\explorer.exe /e,S:\Documents

Buy Me a Beer

Comments

Change the NetBeans Default JDK

A client sent me some code today to update. He was using the NetBeans, so I downloaded the IDE and fired it up to open the project he’d sent me. Unfortunately, the project wouldn’t compile because he’d written the code in Java 6 while NetBeans was using Java 5. I couldn’t find a NetBeans menu to update the setting, but rather found that the fix is to add the following in NetBean’s etc/netbeans.conf file:

# Default location of JDK, can be overridden by using –jdkhome <dir>:
netbeans_jdkhome=”C:\Program Files\Java\jdk1.6.0_05″

Buy Me a Beer

Comments

Intro to URL Rewriting with Apache’s .htaccess

I have created an .htaccess file to do URL rewriting for every site I’ve ever created. If you’re not familiar with URL rewriting, it is used to modify a URL or redirect the user before the requested resource is fetched. One of its major uses is to make URLs human readable. That means your users can visit a pretty URL like http://www.tabworldonline.com/guitar/A/ and have it interpreted by the server as http://www.tabworldonline.com/artists.php?instrument=guitar&letter=A.

Most of the time, this file can be relatively simple. I would always recommend using one for URL canonicalization, which is a fancy term for making sure you have one unique URL for each page. For example, lumidant.com redirects to www.lumidant.com. This is beneficial for SEO because you want to ensure that search engines don’t split your ranking points between pages that are actually one and the same.

The code below is the .htaccess file from this site. The declarations in the file are regular expressions, which you might need to get a quick refresher on if you’re not familiar with. A few other things to be aware of include the fact that [NC] stands for no case and means that the text is not case-sensitive, [R=301] tells the server to do a 301 redirect, and [L] tells the server it can quit there and and not bother processing the rest of the file.

<IfModule mod_rewrite.c>

  RewriteEngine on

  # rewrite all lumidant.com requests to the lumidant subdirectory
  RewriteCond %{HTTP_HOST} ^(www\.)?lumidant\.com$
  # this is needed to stop infinite looping
  RewriteCond %{REQUEST_URI} !^/lumidant/.*$
  # don't redirect these directories to the lumidant subdirectory
  RewriteCond %{REQUEST_URI} !^/pinknews/.*$
  RewriteRule ^(.*)$ /lumidant/$1

  # if you're asking for a directory and there is no trailing slash then add one
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteCond %{REQUEST_URI} !^.*/$
  RewriteRule ^/lumidant/(.*)$ http://www\.lumidant\.com%{REQUEST_URI}/ [R=301,L]

  # add a www if there's not one
  RewriteCond %{HTTP_HOST} ^lumidant\.com$ [NC]
  RewriteCond %{REQUEST_URI} !^/blog.*$
  RewriteRule ^lumidant/(.*)$ http://www\.lumidant\.com/$1 [R=301,L]

</IfModule>

This blog is currently hosted with BlueHost. For accounts with multiple domains, BlueHost places the add-on domains in subdirectories of the main domain. This can be confusing to maintain, so I moved all of the lumidant code to a subdirectory as well and then updated the .htaccess file to make this organization transparent to the end user.

The last few lines add a www to all non-www pages. While I could have placed this at the beginning of the file, the file would be executed again after the redirect causing possibly another redirect to be executed if a trailing slash needed to be added. Keep in mind while organizing the file that you’d like to minimize the number of redirects for many reasons including response times, reducing server load, and optimizing for search engines.

URL rewriting can be tricky at first, especially if you’re not familiar with regular expressions. If you’re working with redirections, then it may help to check the HTTP headers of your request to see what intermediate redirects are occurring.

Finally, if you’re not using Apache there are other alternatives to .htaccess. For example, I have used the UrlRewriteFilter in the past for Java web apps.

Buy Me a Beer

Comments

Suppressing Compile Warnings with Java Annotations

If you’ve used Java 1.5 Generics much then you’re probably familiar with the following compile warning: “Type safety: The expression of type List needs unchecked conversion to conform to List<String>” or similar. It turns out there’s a rather simple solution with annotations to ignore this problem:

@SuppressWarnings(”unchecked”)

A couple other possible uses of the annotation that might be of interest are:

@SuppressWarnings(”deprecation”)
@SuppressWarnings(”serial”)

These are compiler specific, so you may want to check out the full Eclipse list, which is a bit lengthier than Sun’s 7 options (all, deprecation, unchecked, fallthrough, path, serial, and finally).

Also, multiple statements can be combined into one as follows:

@SuppressWarnings({”unchecked”, “deprecation”})

Buy Me a Beer

Comments

Adding Links for Navigation to the WordPress Pages List

The category titled “Pages” on the right-hand side of this blog is an area where WordPress will allow a user to create wiki pages. However, I wanted to include some navigational links in that area as well, which isn’t immediately available through the WordPress admin screens.

The solution I found was to create a new blogroll category and use it for navigational links. First off, I modified the call to wp_list_pages by adding the argument “title_li=0″, which tells WordPress not to wrap it in <ul> tags, but to instead only output the <li> tags. Then I wrapped the call with my own <ul> tags. Finally, I called wp_list_bookmarks in order to display the category I had created, which had an id of 34. I again used the “title_li=0″ parameter and also had to add “categorize=0″, so that this parameter would not be ignored:

	<li id="pages">
		<h2><?php _e('Pages'); ?></h2>
		<ul>
			<?php wp_list_bookmarks('categorize=0&title_li=0&category=34'); ?>
			<?php wp_list_pages('title_li=0'); ?>
		</ul>
	</li>

Buy Me a Beer

Comments

hCard Microformat Example

What exactly is an hCard? It’s a format which specifies that some information on a web page is an online business card. The address for Lumidant in the page footer is an hCard. This means when someone with the Operator Firefox extension visits this page they will have the opportunity to do a one-click import of Lumidant’s address and URL into their contact book. And that can’t hurt business. Come Firefox 3, this functionality will be available without extensions. Creating an hCard was pretty simple. All I had to do was add specific class names to my HTML elements:

        <div id="address" class="vcard">
          <a class="fn org url" href="http://www.lumidant.com" title="Lumidant | Cleveland Web Design and Development">
            Lumidant LLC
          </a>
          ·
          <span class="adr">
            <span class="street-address">1220 West Sixth Street</span> |
            <span class="extended-address">Suite 506</span> |
            <span class="locality">Cleveland</span>,
            <span class="region">OH</span>
            <span class="postal-code">44113</span>
          </span>
          · <a href="blog/">Blog</a>
        </div>

Buy Me a Beer

Comments

Screenshots of Scrolling Web Pages

Have you ever wanted to take a screenshot of a web page that won’t fit on a single page?  I wanted to do that for a client today and found a handy utility that will do it for you.  TechSmith’s SnagIt makes the process far easier that taking multiple screenshots and stitching the panorama together in your favorite photo editor.  Unfortunately, it is not free, but there is a 30-day free trial.  If you’re a mac user there is a program called Paparazzi that
is free and will do the same thing.

Buy Me a Beer

Comments

Opening Photoshop .psd Files without Photoshop

A client sent me a Photoshop .psd file today containing a mock-up of a site he’s interested in having me design. Unfortunately, at the time I received the email, I was on a computer which did not have Photoshop installed, so I had no way to read or view the file. I downloaded GIMP (GNU Image Manipulation Program) and it worked perfectly. The only con with GIMP is that it’s not exactly lightweight if you just want to view a single .psd file, but I don’t mind having it installed as I may find other opportunities to use it.

In other unrelated software news, I heard today that a game called Guitar Rising is in development, which is basically a Guitar Hero knockoff except that you can plug in a real guitar!

Buy Me a Beer

Comments