One issue that I always come across when creating a shell script is referencing files dynamically based on the location of the shell script. A hack I often used was to pass the script’s path to the script on execution because the readlink command was not available to me. However recently I have revisited this issue and have found a solution for obtaining the absolute path of the executing shell script without readlink. For your convenience both scripts are found below.

Absolute Path using readlink

#!/bin/sh
PATH= $(dirname $(readlink -f $0))
echo ${PATH}

Absolute Path without using readlink

#!/bin/sh
ORIGINAL_PATH=`pwd`
cd "`dirname ${0}`"
 
PATH=`pwd`
cd "${ORIGINAL_PATH}"
 
echo ${PATH}
, , , , ,

One of the main maintenance issues with running a Java application from a shell script is keeping your classpath up-to-date with the new and updated jars. To make things more difficult you can’t specify a folder as the classpath as it doesn’t include the jars in it only .class files. However through the use of a basic for loop we are able to dynamically generate the classpath.

CP=
for i in `ls ./lib/*.jar`
do
  CP=${CP}:${i}
done
, , , , , ,

When it comes to Search Engine Optimization (SEO) you will find numerous tips & tricks on how to increase your page ranking. When it is all said and done the most important thing you can do is write unique and informative content. Regardless of the Keyword Stuffing or shear number of articles, the best way to get search traffic to your site is to write an article/post that is purposeful and informative to it’s target audience. To help get you on your way to increasing your own page rank below are some tips on writing a good article.

1: Write with a Purpose

When writing you need to have a reason for doing so. Don’t simply feel you need you need to write an article every day or on a regular schedule. Only write an article when you have a specific information you want to get across. For example lets say you just learned ruby and have decided to write an article on it. To make a good article or set of articles decide what about ruby you want to write on. Do you want to write a beginner’s guide to using ruby? Is it a comparison of ruby vs php or another programming language? If you write your article for a specific purpose there is a greater change of someone reading the article as well as it benefiting, or answering their questions.

2: Write for your target Audience

Knowing your audience helps to define the contents of your article. If you are writing a topic for individuals knowledgeable on the subject vs beginners then your content is going to be different. For example a How to article for beginners may need additional details on each step including references to special techniques while an advanced article can be slimmer with point by point instructions that gloss over the explanations of how and why.

3: Don’t be afraid to get personal or be opinionated

This is your article, yes you are trying to get a point across but never the less it is yours. Include your own opinions say if you agree or disagree with a subject. The one caveat is to remain on task, don’t go rambling on for 2 paragraphs on a side topic that doesn’t match the purpose of your writing.

4: Keep your writing organized and easy to read

No mater how good the information is in your writing if the reader can’t follow it or understand it then it is bad. Keep your writing organized by each topic smoothly transitioning into the next. Also keep your language appropriate to the target audience so they can follow along with out having to look up words or wonder what you are trying to say.

5: Titles are important

The title of an article is supposed to give the reader an overall glimpse of what they can find or will learn in the article. Be sure to keep them brief but also informative. Some writers find it easier to write the title after an article, while some find it is easier to write it first then jump into the article. Whichever works for you just remember that article and page titles are used in calculating your page rank and also are viewable to searchers on Search Engines.

6: Understanding how to use Keywords

Keywords are an important part of any article, by including them in your writing you are helping to associate your article to specific searches. However this does not mean you need to force keywords into your article. After you write your first draft simply review and you should find that main keywords already are present simply revise and add in any others when they are appropriate and flow seamlessly within your article. If your keywords don’t seem to fit then leave them out or add them into the keywords META tag.

Wrapping it all up

The most important rule to increasing your page rank is to write good informative content for your website. Don’t be fooled into thinking that SEO techniques will push your site’s traffic to number 1 in its category. Instead focus on writing purposeful content for your audience and the rest will take care of itself.

, , , ,

Have you ever stumbled across a project and just think to yourself why does this class exist, or more specifically why did they use this design pattern? Recently I happened across one of those projects, in it the project used a Factory class that’s purpose was to instantiate and return a single class. In essence the developers knew what the Factory pattern was and utilized it without having any purpose to do so. Instead they created additional worthless code. This use of a programming pattern without the need of the pattern is known as Cargo Cult Programming

Cargo Cult Programming

The Cargo Cult Programming anti-pattern is the use of patterns, structures, or code in a project because you either always do or simply because you don’t know what it is doing but are copying it from another project or programmer. This style of programming causes unnecessary abstraction, code bloat and increases the difficulty of maintaining the project over its life span.

Want to be a better programmer? Then understand your code, don’t blindly copy/paste or use a pattern just because you can. Take your time and think is this needed, does it provide a useful functionality or enhancement to my project? or does it simply add additional code and size to the project. Don’t fall pray to becoming a Cargo Cult Programmer

Resources

, , , ,

For some reason I have the utmost trouble remembering how to do a single line or inline if else statement. This article is mainly for myself so hopefully I will remember the next time I want to do an inline if else statement.

The usual format for performing an if else statement is:

if( $val1 > $val2 ) {
    // code executed if true
} else {
    // code executed if false
}

If you are trying to set a variable to a value depending on a condition then it is often the case that an inline if else statement will be sufficient and easier to read. This is done by the use of ?. The full format is (condition) ? (true output) : (false output) or as an example:

$val = ($var1 > $var2) ? $var1 : $var2;
, , , , ,