26 Aug 2010

Another Day, Another StackTack Issue

I came across a couple of problems with the StackTack jQuery plug-in today.  I tried to use it with a more advanced Blogger template, but it would require a significant effort to rework the StackTack style sheet.  As I just don’t have the necessary time to update the style sheet at the moment, I reverted to basic blue styled Blogger template.  I then also noticed that StackTack was not displaying the question in IE8, and that there was a script error:

I looked at the relevant section of the (minimized) StackTack plug-in code and found that it was breaking on this IF statement:

if(e.indexOf(classTokens[0].toLowerCase())>-1){ ... }

Where e is a variable consisting of  an array of strings.  A quick Google took me to a StackOverflow question that indicated that Internet Explorer (including version 8) does not support the method indexOf onarrays.

The answer also indicated that adding a reference to the Prototype JavaScript library could resolve the issue. So I modified the includes statements in the header to be as follows:

   1:  <script src='http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js' type='text/javascript'/>
   2:  <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'/>
   3:  <script src='http://app.stacktack.com/jquery.stacktack.min.js' type='text/javascript'/>

This allowed the plug-in to correctly work in IE8.  I created a new issue against the plug-in on BitBucket.  You can view screenshots of my blog on browsershots.org – a great tool for web developers.

23 Aug 2010

Send Outlook Email Via PowerShell

Just to complete the topic of sending emails via PowerShell, [Lies, I still have to blog about the Send-MailMessage cmdlet.] I thought I would include a quick look at sending emails from Outlook via PowerShell.  Again, this script could be replaced by using the PowerShell cmdlet, Send-MailMessage

The script below is based on a script submitted to TechNet by Kent Finkle:

   1:  param 
   2:  (        
   3:      [string]$email = $(read-host "Enter a recipient email"),
   4:      [string]$subject = $(read-host "Enter the subject header"), 
   5:      [string]$body = $(read-host "Enter the email text (optional)")
   6:  )   
   7:   
   8:  # Functions
   9:   
  10:  function Send-Email
  11:  (
  12:      [string]$recipientEmail = $(Throw "At least one recipient email is required!"), 
  13:      [string]$subject = $(Throw "An email subject header is required!"), 
  14:      [string]$body
  15:  )
  16:  {
  17:      $outlook = New-Object -comObject  Outlook.Application 
  18:      $mail = $outlook.CreateItem(0) 
  19:      $mail.Recipients.Add($recipientEmail) 
  20:      $mail.Subject = $subject 
  21:      $mail.Body = $body   # For HTML encoded emails 
  22:      # $mail.HTMLBody = "<HTML><HEAD>Text<B>BOLD</B>  <span style='color:#E36C0A'>Color Text</span></HEAD></HTML>"   
  23:      # To send an attachment 
  24:      # $mail.Attachments.Add("C:\Temp\Test.txt")    
  25:      $mail.Send() 
  26:      Write-Host "Email sent!"
  27:  }   
  28:   
  29:  # Main Script Body
  30:   
  31:  Write-Host "Starting Send-MailViaOutlook Script."   
  32:  # Send email using Outlook
  33:  Send-Email -recipientEmail $email -subject $subject -body $body     
  34:  Write-Host "Closing Send-MailViaOutlook Script."   
  35:   
  36:  # End of Script Body

Download the script from here.  If you have any comments, I would appreciate all feedback.  Thanks.

Also, just to note that the code for this post was highlighted (badly!) using the Neat Highlighter website. Unfortunately, the code snippet produced by the Neat Highlighter website was so poor that I couldn’t use it, and I have updated this post to use a snippet generated by the Insert Code for Windows Live Writer plugin. I also tried to use the Code Formatter Plugin, as recommended by Scott Hanselman, but it constantly froze Windows Live Writer. Also, I discovered how to use the <strike> HTML tag!

New Look for Blog

You will have noticed a new look to the blog.  I’ve finally got around to updating the template to make use of two column layout.  The old site looked very cluttered and did not present code snippets very well. I have updated past posts containing code snippets and images to make use of the increased width of the content column. This template is a default Google Designer template. 

Let me know what you think. 

17 Aug 2010

StackTack

I came across StackTack over the weekend, a great jQuery plugin used to display questions and answers from StackOverflow and the other sites in the Stack trilogy.  It is intended for bloggers and writers who want to post Stack questions in their blogs or articles and have them kept up to date.

I immediately updated my last article on sending GMail via PowerShell to make use of the plugin, but noticed that there was an issue filtering the answers to display a single question that is not the accepted answer.  I have raised an issue against the project on BitBucket; we will wait and see what the response is. 

Regardless of this minor bug, StackApp is a great way to link to the amazing content on the StackOverflow site.  I’m certainly going to keep an eye on the other StackApps that are being built.

16 Aug 2010

Sending Gmail via PowerShell

[Update: I have updated this blog to display the StackOverflow question using the new StackTack jQuery plugin.]

In a previous post, I looked at reducing the number of mouse clicks and key strokes required to send an email and other common tasks using Launchy.  The solution involved using Outlook, as this was for my work PC.  I started thinking about doing the same on my home laptop, where I don’t have Outlook installed.  I remembered a blog article from Scott Hansleman on using the command line email tool Blat, and thought I could do something similar using a PowerShell script send email via Gmail.

Just to note, the script below is only valid for PowerShell V1; in PowerShell V2, there is a cmdlet available to do this, Send-MailMessage. I’ll look at this using this cmdlet in my next blog post.

A quick search of StackOverflow found the following:

My script is based on the answer submitted by user Christian:

Using the script above, and the previously mentioned way of calling PowerShell scripts from Launchy, I can quickly generate emails with a minimal number of keystrokes.

Download the script from here.  If you have any comments, I would appreciate all feedback.  Thanks.

Also, just to note that the code for this post was highlighted using the BlogTrog website.

3 Aug 2010

The Weekly Links…

…are no more!! I have recently started using the social bookmarking site Delicious to manage all of my links.  You can see all of my shared bookmarks at http://delicious.com/andyparkhill. Some of you may have already seen my various tweets tagged #bookmark – these are automatically generated by Delicious.  There is also integration with my blog’s RSS feed, with a daily roundup of all links that I have added being posted.  And just to be sure, I’ve added a Links page to display my Delicious tag cloud!

All of my bookmarks in future will be shared via this service.  I will also be going back and adding links from the various weekly links posts.  This is part of a change in direction for the blog. I don’t want to just aggregate other’s people posts, I want to start generating my own unique content. At the minute, I’ve plenty of ideas to work on, and I’m working on freeing up more time to implement them.