Adding social media icons to the Mystique theme

If you are using WordPress and the Mystique theme, such as this site, then the following instructions will help you with adding additional social icons above the menu bar.

Creating the images
The number of image files you need to create depends on the number of icons you wish to have. You can combine three icons per image file and use CSS to pull the desired icon from the file to display.

For example, below are the two image files used by this site. Since I only have six icons, I can make them all fit into two files. This is important because the browser only has to download two images to display these six icons. Each HTTP request back to the server can slow down a website. Using CSS to display the images also helps by allowing the browser to cache the images and reduce text in the HTML file.

These images were created in Photoshop using a transparent background. You can download various free social media icons. Search the internet and find some that you like that are 64 x 64 pixels. To create the tilted look, rotate the icon 30° and then resize so the height is 64 pixels. The total width of the image should be 64 x the number of icons, but remember to only store three per image file.

Changes to the CSS
Inside the Mystique theme, open the style.css file. Around 100 lines down into the file, you will see some code similar this:

#header .nav-extra
{width:64px;height:36px;display:block;position:absolute;bottom:18px;z-index:10;}
#header .nav-extra span
{display:none;}
#header .nav-extra.rss
{background:transparent url(images/nav-icons.png) no-repeat right top;right:20px;}
#header a.twitter
{background:transparent url(images/nav-icons.png) no-repeat left top;right:85px;}

Just below this block of CSS is where we will add our additions, which will be very similar to the last line of CSS implementing the twitter class on the “a” tag.

Add the following CSS to use the same image files and icons that I have used. You can change the name following the “a.” to anything you wish, but it should be something descriptive.

#header a.facebook
{background:transparent url(images/nav-icons.png) no-repeat center top;right:147px;}
#header a.myspace
{background:transparent url(images/nav-icons2.png) no-repeat right top;right:209px;}
#header a.flickr
{background:transparent url(images/nav-icons2.png) no-repeat center top;right:273px;}
#header a.linkedin
{background:transparent url(images/nav-icons2.png) no-repeat left top;right:338px;}

Here I have added additional icons for Facebook, MySpace, Flickr, and LinkedIn.

To reference the correct icon, using the background: CSS property, you can call the image file (nav-icons.png and nav-icons2.png). Using the top right, left and center keywords, you can select the icon file to use from the image. In the above example, the nav-icons.png file has three icons…by selecting the center one, I’m pulling out the Facebook icon from the first image above.

The “right” property positions the icon however many pixels from the right side of the screen. You can adjust this number to increase or reduce the amount of space between the icons.

Changes to the header
The last thing we need to do is add the HTML code to the header template. This will tell your browser to display the icons. Open the header.php file within the mystique theme, then look for the following block of code around line 55.

if ($twituser): ?>
  <a href="http://www.twitter.com/<?php echo $twituser; ?>" class="nav-extra twitter"
    title="<?php _e("Follow me on Twitter!","mystique"); ?>">
    <span><?php _e("Follow me on Twitter!","mystique"); ?></span>
  </a>
<?php endif; ?>

Next, we’ll add in our new icon HTML below the HTML shown above.

<a href="http://www.facebook.com/YOURPROFILE" class="nav-extra facebook"
  title="<?php _e("My Facebook Profile.", "mystique"); ?>">
  <span><?php _e("My Facebook Profile.", "mystique"); ?></span>
</a>

<a href="http://www.myspace.com/YOURPROFILE" class="nav-extra myspace"
  title="<?php _e("My MySpace Profile.", "mystique"); ?>">
  <span><?php _e("My MySpace Profile.", "mystique"); ?></span>
</a>

<a href="http://www.flickr.com/photos/YOURPROFILE/" class="nav-extra flickr"
  title="<?php _e("My Flickr Photos.", "mystique"); ?>">
  <span><?php _e("My Flickr Photos.", "mystique"); ?></span>
</a>

<a href="http://www.linkedin.com/in/YOURPROFILE" class="nav-extra linkedin"
  title="<?php _e("My LinkedIn Profile.", "mystique"); ?>">
  <span><?php _e("My LinkedIn Profile.", "mystique"); ?></span>
</a>

Make sure that you replace YOURPROFILE with the correct link information to your profile for these social media sites.

One thing that is important to notice is the CLASS attribute. There are two classes added to each “a” tag: nav-extra and the name of whatever social media icon you are displaying. This name must match the name specified in the CSS above that follows the “a.”.

The PS3 Media Server

If you have a Playstation 3, or even an Xbox 360, you should take a look at the PS3 Media Server. I have tried using Windows Media Center to serve video content, and while it does work, the video formats seem very limited. The PS3 Media Server seems to support just about any type of video that I would want to use; such as MPG, MP4, MKV, M2TS, and VOB.

I was most impressed by how backing up a movie DVD at 100% quality (around 7 GB), I was still able to stream to my PS3 and the video quality looked as if the DVD were playing in the PS3. In testing, I was able to play Blu-Ray video as well, although the video did jump around a bit on some clips; it could have been a bad backup. Both my computer and the PS3 were wired on a 1GB network.

There are some problems:

  • Seeking does not work the best, specifically from the Xbox 360.
  • DVDs are typically split into roughly 1GB VOB files. If there are many of these, it may be difficult to find the desired VOB that contains the movie. Usually, the movie is the largest one. You can use the command below to combine the VOBs into one file…which then can be renamed to something.mpg.
copy /b file1.vob + file2.vob + file3.vob new.vob

So, if you would like to keep your DVD collection in good condition and have the space to store your movies on your computer, give the PS3 Media Server a try. You can backup your DVDs to your computer using a tool like DVDShrink, then play them over your network. No more searching for the disc to watch a movie.

Disclaimer: You should only backup media that you own. Do not illegally copy movies or music.

You can download the PS3 Media Server from google.

Some bad news

Today I found out that a good friend’s father passed away yesterday. He was a very intelligent and respected man in the town where I grew up and went to school. I had spent many a day hanging out at his house with his son through high school and after. The world is a little darker without the bright shining light that was Ed Crow. He will be missed…

Clearing the Client Version from the Lotus Notes Directory

With the latest version of Lotus Notes (8.5.1), you can now view the version of your clients by looking in the People -> by Client Version view. One problem with this, however, is that your users will show each client they have logged in as. Over the years, you may accumulate many versions for each user.

During an upgrade, you may wish to see what users are using the previous version of client against the ones who have the new version installed. But first, we’ll need to clean up the directory so we don’t see all this old version history.

To clean up these fields, you need to write an agent that will empty them for each selected person. This will allow you to run the clean up agent on only the users you wish to run it on.

Writing the agent
Open up the pubnames.ntf template file in your Notes Designer. You’ll need to go to Code and double-click on Agents to see the current agents for the template.

We’ll create a new agent and give it a name. Below is the code for the agent. Copy and paste it in the Designer.

Option Public
Option Declare

Sub Initialize()

  'Declare.
  Dim s As New NotesSession
  Dim db  As NotesDatabase
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument

  'Initialize.
  Set db = s.Currentdatabase
  Set dc  = db.Unprocesseddocuments
  Set doc = dc.Getfirstdocument()

  While(Not(doc Is Nothing))

    If (doc.Form(0) = "Person") Then

      Call doc.Removeitem("ClntBld")
      Call doc.Removeitem("ClntDate")
      Call doc.Removeitem("ClntDgst")
      Call doc.Removeitem("ClntMachine")
      Call doc.Removeitem("ClntPltfrm")
      Call doc.Save(False, False, False)

    End If

    Set doc = dc.Getnextdocument(doc)

  Wend

End Sub

Now, after you refresh your names.nsf file, you can go to the Action menu and find your agent. Running the agent will only process those Person documents that you have selected.

Scheduling A Task In A Web Application On A Windows Server

When writting web applications, there may be times when you would like to perform some task automatically at the same time or every X number of hours. Web applications only execute their code when a request is made from a client’s browser. Because of this, scheduled tasks within the web application will not work.

There are a few different options:

  1. Build a separate Windows Service application that can connect to the assemblies your web application uses to execute the scheduled task.
  2. Build a separate Windows application that communicates with a web service that your web application also uses to perform the scheduled task.
  3. Use the Windows Scheduler to call the URL of the action to perform the task.

The first option might sound good at first, but creating a separate program that talks to your web application’s library files is a bad idea. Maintenance will become a problem as you change your web application. Since the code is in two places, unit testing will not tell you that the class library you just changed has now broken your scheduled tasks in your windows service. 

The second option is slightly better, but you still may have issues with changing your class library.

The third option is the one that I will show you how to configure. We will setup a VBS script that will perform a call to any web address we pass to it. Then, we’ll setup a batch file that calls the VBS script and passes in one or more URLs to execute. And finally, we’ll go through using the Windows Scheduler to create the scheduled task when the batch file should execute.

The primary advantage to this method is that you get to keep all of your code together in your web application. You simply setup an action that performs whatever task you wish to schedule and make sure that action is callable from an anonymous user.

WebRequest.vbs
You may copy the following code and paste into a text file. Then, rename the file to WebRequest.vbs. The script basically takes an argument that is passed into it as the URL. The HTTP object is setup and then the URL is called using a GET request. Then, the returned status is checked to see if the request was successful or not.

url = WScript.Arguments.Item(0)
'WScript.echo url

set WshShell = WScript.CreateObject("WScript.Shell")
set http = CreateObject("Microsoft.XmlHttp")

http.open "GET", url, FALSE
http.send ""

if (http.Status = 200) then

    WScript.echo "Request successful."

else

    WScript.echo "Error: " & http.Status

end if

set WshShell = nothing
set http = nothing

The Batch File
Calling the WebRequest.vbs file from a batch file is very easy. Simply create a new text file, calling it whatever you’d like, and paste in the following line of text. Rename the file to .BAT when finished.

cscript WebRequest.vbs "http://www.domain.com/controller/action"

Scheduling The Task
From your Windows server, open the Control Panel and then open the Scheduled Tasks item. Next, click on Add Scheduled Task. Choose any application to schedule.  This will be changed later on. Configure how often you wish the schedule to run and enter a user name and password to run the schedule as. This users should have access to running the web browser from the server.

After your new scheduled task has been created, open it. In the Run text box, type in the full path to your batch file. Then, in the Start In text box, type in the full path without the batch file name. You can also adjust your scheduled time from within here. Click OK to save the changes and your scheduled task should be ready.

You can test the Windows Scheduler by setting the scheduled time to a minute or two in the future and then waiting for it to execute. If you just wish to test your action, or manually run it, you can simply run the batch file.

MVC and n-layer architecture

When I write a program, no matter which tool I use, one problem I face is how to design the application. No matter if you use Java, PHP, or Visual Basic; if you design the application badly, you will have problems later when you try to fix bugs or enhance the product to the next version.

The MVC design pattern
MVC stands for Model, View, Controller. This is a very common design pattern used in programming today. When someone uses a MVC application, they make a request to a controller. The controller then talks to the model, which consists of business logic, to perform the action requested. The controller then processes the information from the model and sends it to the appropriate view.

By using the MVC design pattern, you will separate your business logic from your presentation HTML. This makes your application more easily maintainable because a bug can be fixed in the business logic without all that HTML display code getting in the way. Also, when multiple developers are working on a project, the developers who write HTML and CSS can work independently of the core programmers.

N-Layer Architecture
N-Layer, or multi-layer, applications are designed using layers that handle a single responsibility. Many applications use three layers; Presentation, Business Logic, and Data-Access. This is similar to the n-tier architecture, but the primary difference is tiers represent physical hardware, while layers represent software.

In the three-layer approach; the Presentation layer would consist of the user interface, the Business Logic would consist of objects that process Business Rules, and the Data-Access layer would talk directly to the data source. This design usually works well.

Putting them together
One of the things I found a little confusing about MVC at first was what exactly is the model? After much research and testing, I finally found something that makes sense to me.

MVC Multi-Layer Diagram

MVC Multi-Layer Diagram

 The diagram above is the general layout that I use when developing a MVC application. Here is a brief description of the various components of the diagram:

  • Model – In this diagram, the model would consist of the Services, Repositories, and DatabaseConnection layers along with Domain Objects.
  • View - The view is the presentation or design elements of the application; such as HTML or CSS.
  • Controller – The controller is the layer that drives the application. It processes requests from the user and sends them to the model and then returns the processed information to the view.
  • Services – This layer handles requests from the controller. This is the layer that contains the business rules on how the application should function.
  • Repositories - This layer performs CRUD (Create, Read, Update, and Delete) operations on the database.
  • DatabaseConnection - This layer is further abstraction between the data source and the repository. It is not required, but I typically use it when I need to work with multiple databases. The DatabaseConnection layer was built to generalize between three different database drivers and use common methods to work with each.
  • Data-Access layer- This layer would consist of the Repositories, DatabaseConnection, SQL Data Source and Other Data Sources.
  • Other Data Sources – This could include a XML file, other database, or even a web service.
  • Domain Objects – This is not necessarily a layer, just a collection of objects used to make it easier to work with the data from the data source. Notice that all of the other layers need to be able to work with these objects. An example of a Domain object might be an Employee class that stores information about an employee and is populated from a data source in the Repository. The Employee object can then be passed from each layer back to the view where it is displayed to the user.

This is just a brief overview of MVC with the n-layer approach.

Installing ASP.NET MVC

Here are the steps to install into Visual Studio 2008:

  1. Download ASP.NET MVC 1.0 from Microsoft’s website. Make sure to download the MSI file and the source code if you would like to see how it works.
  2. Install the AspNetMVC1.msi file.
  3. Open Visual Studio 2008 and go to:
    1. File -> New -> Project
    2. Under Project Types, select Web under either Visual Basic or C#
    3. Under Templates, select ASP.NET MVC Web Application
    4. Give your application a name and change its location if you wish

That’s it! Upon creating a new web application, the default MVC application will open.

Note:
ASP.NET MVC should also work using the free development tool from Microsoft, Visual Web Designer 2008.

Why you should use ASP.NET MVC

If you’re like me, you like to have control over how your websites look and the HTML returned to the browser. ASP.NET MVC gives you that control by letting you keep your HTML separate from the core application code. If you learn to use tools like CSS and JavaScript, you can use them in the exact same way you would if you were working with a static web page. There are no generated IDs or missing/custom HTML attributes. While it does give you some helpers to generate HTML, you do not have to use them if you don’t want to.

ASP.NET MVC is very extensible and flexible. Nearly any component of the framework can be swapped out for your own version, if you so choose to delve into the inner workings.

ASP.NET MVC was built with Unit Testing in mind. If you’re not using Unit Testing, you should definitely start researching how it can improve your code reliability.

So, why should you use ASP.NET MVC?

  • Based on the MVC pattern.
  • Allows you to use Standards such as XHTML and CSS.
  • Separation of concerns allows for more maintainable code.
  • Gives you help when you need it and gets out of your way when you want control.
  • Unit Testing is built in and easy to do.
  • Fully supported by Microsoft.
  • You can download the code for the ASP.NET MVC Framework and see how it works.

If you know HTML, CSS, or JavaScript and you are familiar with ASP, then you should definitely look into ASP.NET MVC.

A Fresh Look

Just added a new theme to the website to give it a fresh new look for the year.

2010 New Year’s Resolutions

Here are a few resolutions for this year:

  • Lose weight
  • Read 12 books
  • Finish some website projects
  • Finish home improvement projects
  • Use this site more