jQuery Basics Tutorial

July 10th, 2010 -- No Comments

jQuery is an upcoming/hot thing right now when it comes to web development. To me jQuery is slowly taking over flash. There are lots of things I can do in jQuery that I would have programmed in flash for. Before you kill the messenger there are things out there that flash can do that jQuery can’t. So let me post the source code for the tutorial and below that you can watch in video as I explain.

<html>
	<head>
    	<title>jQuery Basics Tutorial</title>
        <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
        <script type="text/javascript">
        	$(document).ready(function() {
        		$('#employees tbody tr:odd').addClass('alternaterow');
        		$('#employees tbody tr:odd').removeClass('alternaterow');
 
        		$('#hideButton').click(function() {
        			$('#employees').hide();
        		});
 
        		$('#toggleButton').click(function() {
        			$('#employees').toggle();
        		})
        	});
        </script>
        <style type="text/css">
        	.alternaterow
        	{
        		background-color: #ccc;
        	}
        </style>
    </head>
    <body>
        <input type="button" id="hideButton" value="Hide Table" />
        <input type="button" id="toggleButton" value="Hide / Show" />
        <table id="employees">
        	<tr>
            	<td>
                	John
                </td>
                <td>
                	Smith
                </td>
                <td>
                	Developer
                </td>
            </tr>
            <tr>
            	<td>
                	Greg
                </td>
                <td>
                	Smith
                </td>
                <td>
                	Owner
                </td>
            </tr>
            <tr>
            	<td>
                	Michelle
                </td>
                <td>
                	Smith
                </td>
                <td>
                	Web Developer
                </td>
            </tr>
            <tr>
            	<td>
                	Scott
                </td>
                <td>
                	Smith
                </td>
                <td>
                	IT Administrator
                </td>
            </tr>
            <tr>
            	<td>
                	Michelle
                </td>
                <td>
                	Smith
                </td>
                <td>
                	Web Developer
                </td>
            </tr>
        </table>
    </body>
</html>

Categories: Tutorials, jQuery

Selenium Automation with TestNG

May 27th, 2010 -- No Comments

I wanted to start off with a simple tutorial that shows you how to write some simple automation scripts. Basically you write Selenium scripts that will test/verify information on a webpage. Example would be lets say you have a webstore that has a shopping cart. You might want to write automation that goes thru purchasing something to make sure it is working. So here is the video and below that I will have the script as well.



package com.jcwebconcepts.tutorials.basics;
 
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
 
public class SimpleBrowserTests {
	private String appURL = "http://www.jcwebconcepts.net";
 
	@Test
	public void openMyBlog() {
		FirefoxDriver driver = new FirefoxDriver();
		driver.get(appURL);
	}
 
	@Test
	public void searchGoogle() {
		FirefoxDriver driver = new FirefoxDriver();
		driver.get("http://www.google.com");
		driver.findElementByName("q").sendKeys("Apple");
		driver.findElementByName("btnG").click();
	}
}
Categories: Selenium, Tutorials

Setting up Eclipse

April 27th, 2010 -- No Comments

I wanted to talk about how to setup your Eclipse IDE to work with Selenium, Maven, and TestNG. For those who do not know what those are you can click on the link to learn more. I will be making some more posts/tutorials on how to use these items. Eclipse can run on Mac, Linux, and or Windows. You need to have Java installed and if you want to work with SVN then you need the command line SVN client.

From the video below here is the list of the sites that you will need to add to Eclipse:

  • Maven = http://m2eclipse.sonatype.org/sites/m2e
  • TestNG = http://beust.com/eclipse
  • Subclipse = http://subclipse.tigris.org/update_1.6.x

Here is the video. Below video I will paste the code that you want to add to the pom.xml

Here is the code that is remaining

<build>
  		<testResources>
  		</testResources>
  		<plugins>
			<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <systemProperties>
                        <property>
                            <name>app.env</name>
                            <value>${app.env}</value>
                        </property>
                    </systemProperties>
					<excludes>
						<exclude>**/TestUtilities.java</exclude>
					</excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <skip>true</skip>
                    <failsOnError>true</failsOnError>
                    <consoleOutput>true</consoleOutput>
                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                </configuration>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
  	</build>
  	<dependencies>
        <dependency>
			<groupId>net.sf.jacob-project</groupId>
			<artifactId>jacob</artifactId>
			<version>1.14.3</version>
		</dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>2.5.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>2.5.3</version>
        </dependency> 
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>oracle</groupId>
            <artifactId>oracle</artifactId>
            <version>14</version>
            <scope>test</scope>
        </dependency>
        <dependency>
        	<groupId>org.testng</groupId>
        	<artifactId>testng</artifactId>
        	<version>5.11</version>
        	<classifier>jdk15</classifier>
        	<scope>test</scope>
        </dependency>
        <dependency>
        	<groupId>org.seleniumhq.selenium</groupId>
        	<artifactId>selenium</artifactId>
        	<version>2.0a2</version>
        </dependency>
        <dependency>
        	<groupId>org.seleniumhq.selenium</groupId>
        	<artifactId>selenium-server</artifactId>
        	<version>2.0a2</version>
        </dependency>
    </dependencies>

Java Hello World

April 1st, 2010 -- No Comments

Well I have decided to jump back into Java programming due to some recent events. I went out and bought Sams Teach Yourself Java in 24 Hours to help me in this journey. So to help me grasp the material I wanted to create blog posts/tutorials to help me and to help others who might be on this same goal.

….

Oh and the two things that you will not see the void main for is applets and servlets. Here is the source code of the file I created

class HelloWorld
{
	public static void main(String[] args)
	{
		String sayHello = "Hello, World!";
		String myName = "John Costanzo";
		int myAge = 28;
		boolean theTruth = false;
 
		System.out.println(sayHello + " My name is " + myName);
		System.out.println("Is my age " + myAge + "?\nThe answer is " + theTruth);
	}
}
Categories: Java, Tutorials

Hosts File

March 25th, 2010 -- No Comments

As a web developer one of the tools that I love to use is built right into the operating system. I have come across some jobs where the coder has coded everything in absolute paths. Let me show you an example of an absolute path and a relative path.

….

Absolute Path
<a href="http://www.jcwebconcepts.com/index.php">Home</a>
 
Relative Path
<a href="index.php">Home</a>

As you can see there is a little difference. So now you may ask why is this an issue. Well if you are like me and like to test stuff on a local server first, then you will run into some issues. If your page calls an file it will call it from the remote server and not the local one. There are other examples but I will spare you of them. Lets get to this hosts file.

The hosts file exists in modern day operating systems. You can find it in Linux, Mac, Unix, and or Windows. Let me show you where these files exist.

Linux (Most distros)/Unix
/etc/hosts
 
Mac
/etc/hosts
 
Windows
C:\Windows\system32\drivers\etc\hosts

Here is an example of what a host file looks like

Linux Host File

So now let me show you some magic. So now on your testing box I would add a new entry. It can be added anywhere you want. So add this line

127.0.0.1     http://www.jcwebconcepts.net
127.0.0.1     http://jcwebconcepts.net
127.0.0.1     www.jcwebconcepts.net
127.0.0.1     jcwebconcepts.net

Of course you could substitute with any domain. So now when you test your files/scripts and the point to the absolute path you will pointing to your local box. Of course when you are done I like to comment that out. Just in case I forget that I have that and I want to look at the remote site. Now if you want to see the test environment on another computer the line you add to the host file will be different. First get your IP of the test box. Mine is 192.168.2.120

192.168.2.120     http://www.jcwebconcepts.net
192.168.2.120     http://jcwebconcepts.net
192.168.2.120     www.jcwebconcepts.net
192.168.2.120     jcwebconcepts.net

So you can start to see the things you can do with the hosts file that can help you. Instead of recoding all those absolute paths to relative you can edit the hosts file and test it that way.

Here is a video that explains some of this

Ubuntu Web Server Part 2

January 30th, 2010 -- No Comments

Since posting my tutorial on running a web server on Ubuntu 9.10, I have had some questions on some of the next steps. So in this tutorial I want to discuss what you want to do to get your web server on the internet. I want to discuss on how to set it that a standard user can edit files in the web directory.


Categories: Linux / BSD, Servers, Tutorials

Using Expect

January 7th, 2010 -- No Comments

Are you running a Linux or Unix server that there are process you need to automate? Is there a daily process that are just a waist of your time but not to your server? There is a nice application called Expect that can help you with this. This application can handle several protocols. Some are ssh, telnet, ftp, passwd, fsck, rlogin, tip, etc… This application does not need a server it is just a client. The client is installed where your script will run from. The nice thing about expect is the file can be executed on a webpage as well. So let me show you an example script:

#!/usr/bin/expect
 
###Usage: call the file with a username.
 
spawn ssh -i /var/employee/includes/id_rsa root@10.10.1.12
expect "The authenticity of host '10.10.1.12 (10.10.1.12)' can't be established.
RSA key fingerprint is 47:4a:6a:ce:65:99:e2:93:2b:7t:a9:48:19:64:f6:28.
Are you sure you want to continue connecting (yes/no)?"
send "Yes\r"
expect "root@10.10.1.12's password:"
send "iamthegreatone\r"
expect "#"
send "cd /home\r"
expect "#"
send "rm -Rf $argv\r"
expect "#"
send "cp -a default/ $argv\r"
expect "#"
send "chown -R $argv:513 $argv\r"
expect "#"
send "exit\r"
expect eof

This script is executed by running the following:

root@john-server:~# expect thefilename.exp john

This is a script I use at work to reset my users profiles when they mess them up. As you can see then when you run the file you must pass an argument. So in this case you ssh into the server that has the user directories pass the name of the directory. So this script will remove the current users directory and cp the default profile directory to theirs. It will then set the right permissions for the user. Note: The group 513 may be different from server to server.

Now you do not need to use ssh or anything like that. So if you want to have the script live in the same box you can remove the SSH information. Hope this helps and give it a try it is a nice tool.

Python Basics

December 23rd, 2009 -- 1 Comment

If you have been reading previous blog posts, I have been using a monitoring tool called Zenoss. Under the hood there is a lot of Python stuff. So I decided to start learning Python. Python can run on Mac, Linux, Unix, and Windows. Let me show you some basic on what you can do in python.

#!/usr/bin/python
 
firstName = "John"
lastName = "Costanzo"
 
# Lets just print out one variable
print firstName
 
# Now lets complete my name
print firstName, lastName
 
# Lets just print something random without a variable
print "The sun is warm. The grass is green"
 
# Now I will print some variables followed by some text
print firstName, lastName, "Is the owner of this blog."

For more information on Python you can visit this site.

VIM Tutorial

December 10th, 2009 -- No Comments

When I first started working with Linux one of the tools I disregarded was VIM. I felt it to be too confusing and believed it was not worth it at all. I was so use too notepad, nano, pico, etc… Then a programmer finally convinced me one day to make a switch. I am so glad I did.

So the first thing you have to get use to is that there are two modes to be in. One is command mode and the other is in insert mode. When in command mode you can save or do other things like find and replace. In insert mode you do like you normally do. You type away. I know it sounds confusing now but wait and I will show you what I mean.

VIM can be found in Mac, Linux, Unix, and or Windows. To start a file you bring up your terminal or if in Windows you open the application in your start menu. In the terminal you will type

vim whateverfilename

In the Windows work you go to file -> new I believe. Sorry not much in the Windows side of things.

Command Mode

Ok so lets get into some of the things you can do in command mode. So lets say you have to edit a document for work and you have to change the word Bob with the word John. hit ESC to make sure you are in command mode and hit the following:

:% s/Bob/John/g

The g at the end will make sure it goes thru the whole document. To search for some text is not that hard to do. So lets say we want to find all instance of the word happy. You will do the following:

/happy

When you find the first result you can hit n on your keyboard to go to the next instance that it finds the work happy. If there is none it will tell you that there is none. Now I am sure you are asking how do I search for multiple words? Well let me show you how to search for Happy Birthday

/Happy Birthday

As you can see you I did the same thing as above. VIM knew that you were looking for multiple words. Before you ask if there is a term in the document called Birthday of Happy, it will not bring that up as a result. The next thing I want to show you is if you need to get to line 10000 in a file all you have to do is the following:

:10000

Yep that is it. To wrap up this first tutorial on VIM I will show you how to quit without saving, saving but not exiting, and saving and exit. Here they are in order.

:q!

The q stands for quit. If you forget the ! you would be prompted about saving before quiting

:w

The w tells VIM that you want to save the changes

:wq

As you see we combined the w and the q to save the changes then quit. Now before you ask, if you would do :qw that would fail. Cause vim reads the commands from left to right. Well I think that is enough for now. If you have any questions about vim please post a comment.

Below is a video on what I basically explained above.

Versions Working with Repositories

November 2nd, 2009 -- No Comments

Well the other day I created a video showing you an overview of Versions, but I did not get into any details. So I create a video showing you how to add a working repository. I also got into adding a repository that is hosted somewhere else as well. The last thing I got into was setting up a local repository. I hope that this is a helpful video.

Categories: Mac OS, Tutorials