Sunday, May 13, 2012

HTML Force Links To Open In New Tab


Sometimes, as a blog writer, it seems counter-productive for you to provide links to other websites and blogs that have similar or better content then your own; however, contrary to ones intuition, providing useful links from your site can build up an audience as well as a new post could.
In other words, sharing your resources with your audience will only benefit your blog or site. A thought crossed my mind after adding more links and resources to my blog. The thought was that when many people read content on the web clicking links to get more indepth information is inevitable, but most viewers do not intend to leave your page. So, I wanted the links on my site that appear in articles and posts to open in a new tab by default.
The goal was achievable because I know as a viewer of a website you can right click any link and select "Open in new tab". By using an attribute for the HTML anchor tag, <a>. Here's the original HTML code for a link to google (The first link would open and make you leave this page, but the 2nd link would open the page in a new tab.)

<a href="http://www.google.com/"> Go To Google </a>
Go To Google
<a href="http://www.google.com/" target="_blank"> Go To Google (new tab)</a>
Go To Google (new tab)

Thursday, May 10, 2012

Java: Strings Methods: Substring

Substring is a method/function used to select smaller strings in the String it was called on.

For example, "CatDog" is a string that contains two smaller strings, "Cat" and "Dog"
To break this "CatDog" string into the two seperate strings, "Cat" and "Dog" one would use the substring method.
Example #1:
String string1 = "CatDog";    //declaration and initialization of string1
System.out.println(string1.substring(2));    //prints out result of substring(2) 
After running the code above you it is easy to realize we have a problem. Your console should read "tDog" which means we have not split the string1 up as we had planned. The reason is because the parameter we assigned to be 2 should have been 3. Below is the code for what we truly wanted. Goes to show that print statements are a good way to test/debug your programs!
String string1 = "CatDog";    //declaration and initialization of string1
System.out.println(string1.substring(2));    //prints result of substring(2) 
The first and only parameter in example one specified the first character of the string to start the substring from and then because there was no second integer parameter the method returned that first letter and all the characters that followed it in the string.
Example #2:
String quote = "code the gnar";
String word = quote.substring(1); 
System.out.println("original value: "+quote);
System.out.println("final value: "+word);
It is important to realize that there are more than 1 ways of calling for a substring() on a string. In the following example you will see an example using the substring(int,int) syntax. See if you can figure out what the 1st and 2nd integer paremeters are doing!
Example #3:
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String letters = alphabet.substring(5,0); 
System.out.println("original value: "+alphabet);
System.out.println("final value: "+letters);
Click here to see the function of the 1st integer.
Starting index for the string

Click here to see the function of the 2nd integer.
How far after starting index to span

More On Java Strings

Friday, May 04, 2012

Rage Comic Compilation #2

This is another compilation of my favorite rage comics. To see the first set click here.

Some More Lovely Rages (list #2)

Source
The following rage comics may elicit tears. As seen above!