Hi, welcome to my canvas for development, design, and pure randomness. Chances are that you stumbled onto this fancy shpancy blog looking for information. Hope you found it! If not, did you know that I tend to post free templates, logo designs, and code here? Take a look, and enjoy your day.

Consume a wordpress rss feed in C#

July 9, 2010

I couldn’t find a simple example of consuming a WordPress Blog Feed in C#. So I decided to write out my own:

Here is an example to get you started. I wrote it in three parts:

A Class that Consumes a Feed (FeedReader)
An Object representing a Feed Item (FeedViewModel).
A quick Unit Test (FeedReaderTests)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FeedExample
{

	public class FeedReader
	{
		public static IList<FeedViewModel> GetBlogFeed(string feedUrl, int feedCount)
		{
			var doc = XDocument.Load(feedUrl); //1

			var feeds = doc.Descendants("item").Select(x => //2
					new FeedViewModel
					{
						Title = x.Element("title").Value, //3
						PublishedDate = DateTime.Parse(x.Element("pubDate").Value),
						Url = x.Element("link").Value
					} //4
					).OrderByDescending(x=> x.PublishedDate) //5
					.Take(feedCount); //6

			return feeds.ToList();
		}
	}

	[TestClass]
	public class FeedReaderTests
	{
		[TestMethod]
		public void FeedReader_Works()
		{
			var feeds = FeedReader.GetBlogFeed("http://cowfarm.net/feed",1); 

			Assert.IsNotNull(feeds); //7
		}
	}

	public class FeedViewModel
	{
		public string Title { get; set; }
		public string Url { get; set; }
		public DateTime PublishedDate { get; set; }
	}

}

Here is what is being accomplished here:

//1. Load feed via a feedUrl

//2. Get all the "items" in the feed.

//3. Get title, pubDate, and link elements.

//4. Put them into an object (FeedViewModel).

//5. Order them by the pubDate (FeedViewModel.PublishedDate).

//6. Only get the amount specified, the top (1, 2, 3, etc.) via feedCount.

//7. Convert the feeds to a List and return them.

//8. Test that you got something back.

Here is a quick hierarchy of a really bare feed:

- item
-- title
-- link
-- comments
-- pubDate
-- dc:creator
-- category
-- guid
-- description
-- content:encoded

Remember, the code above is for demonstration, make sure you handle and dispose your objects properly!

What do you think?

CSS Syntax Highlighting for SCSS

July 7, 2010

I wrote a quick little extension for Visual Studio 2010, which allows you to View SCSS with CSS 2.1 Syntax Highlighting and Intellisense. It can also be easily uninstalled through the Extension Manager.

I basically took the values in my Registry (See Below) and duplicated them for SCSS.

Css Package Key

Css Package Editor Key

Extension Source:

[$RootKey$\Languages\File Extensions\.scss]
@="{A764E898-518D-11d2-9A89-00C04F79EFC3}"

[$RootKey$\Editors\{A764E89A-518D-11d2-9A89-00C04F79EFC3}\Extensions]
"scss"=dword:00000040

READ BEFORE INSTALL!:

You must “Exclude [files] from Project” [SCSS] after install, then “View hidden files” and “Include files in Project” to make this work on existing files.


Run the installer as an Administrator.

Remove any entries for “scss” from: Tools, Text Editor, File Extension.

Download Extension:


Download


What do you think?

In other news, QTAgent32.exe Virus?

June 23, 2010

Microsoft, has officially re-released a self aware Dell Hardware destroying Virus in Visual Studio 2010. This virus will effect your computer if you start running Unit Tests, it is currently masquerading around as what appears to be a QuickTimeAgent32 process, to divert the blame on Apple.

Over time it will slowly make your hardware less functional and will make you want to crawl under your desk, or go after your computer with a baseball bat.

The current fix is to not run Unit Tests, or if you really have to, you can use ReSharper:

ReSharper -> Unit Tests -> Run All Tests from Solution.

Yes, this is a joke, well the virus part anyway!

What do you think?

Firefox, ajax caching issue

June 22, 2010

For anyone who has an application built on one hundred Ajax requests every five seconds.

jQuery:

$(function () {
     $.ajaxSetup({ cache: false });
});

I’d like to believe that does something, like slow down the pain :| .

What do you think?

ViEmu, is it worth it?

June 11, 2010

viemu
For the past couple of weeks I have been exploring the ViEmu Beta4 plugin for Visual Studio 2010. I decided to do this because of what some of my co-workers told me: “Without vi I would parish”, “It increases productivity drastically”, and “it’s totally worth your money.”

The price tag on the latest ViEmu for VisualStudio is $99 dollars. ViEmu Store

Vi

For those of you who don’t know what Vi (Visual in) is, it is actually a really old Unix Application developed somewhere in 1976 by Billy Joy for mode editing text. Meaning you have several modes for working with text, for example insert mode is for inserting text and normal mode for navigating.

Vim

Vim or Vi IMproved is just as it says, a better version of Vi. It introduced a new visual mode, syntax highlighting and more commands. Let’s just say it’s more code friendly.

Is it really, really, as good as they say?

First, I want to say Ctrl and Ctrl + Shift, these commands come with the operating system for free and work in all text fields, and are really close to each other. You don’t need a separate application/plugin to use them.

I use Ctrl (, ) to navigate words, in viemu/vi you would use the w and b keys.

I use Ctrl + C and Ctrl + V to copy and paste, in viemu/vi you would use the y key (yank).

To insert text I start typing, in viemu/vi I would click i (insert), type, and to stop Esc.

So lets stop for a second. Every command without vi is seems to be derived from Ctrl or Shift.

Shift + (, ) select character.

Shift + (End, Home) an entire line.

Shift + Ctrl (End,Home) everything after before this line.

So basicly, for the majority of these BASIC commands in vi you are saving a key stroke or two. You should note though, that you are also losing the ability to be in insert mode at all times, something that is very important when you are constantly typing.

Vi has a better mechanism for find and replace, kind of. It is directly in the text editor and its fairly easy to use via the short cut keys like f, v, c, p, etc. However, you still tend to jump in and out of different modes. I personally find that find and replace is just as easy, though I don’t have a strong argument, since I tend to not use a lot of regex (regular expressions).

So “Without vi I would parish” no just learn the built in commands for the operating system. You can still be a fast typer/navigator without a third party tool. In the long run VI will out run you but at the rate most developers switch environments and IDEs, a proprietary solution just doesn’t work.

“It increases productivity drastically” no it increases it a bit, it also decreases it a bit as well. Whether your a guru in vi or not, there are usually more simple cases for text editing then their are convoluted. Vi wins convoluted re-factoring hands down, but when you gotta type none stop and go back to previous words, sentences, blocks of code it doesn’t matter.

“It’s totally worth your money” this is kind of a funny argument. Somehow people associated working FAST with productivity and performance. I usually judge it by quality and assertiveness. So in the long run you can out type anyone; however, the ending result might not be as splendid as you think.

In the end, you can read the tortoise and the hare all you want but the tortoise will always win. So, for now I’ll pocket my $99 dollars, and maybe when there is a good Vi editor for $10 dollars I’ll fold. Verdict: Wait on it, its only good for one IDE and shouldn’t cost so much. :|

PS: For those with a Macintosh you would use option to jump words and control to jump to the beginning of lines with arrow keys. This method also doesn’t pick up whitespace, and is also more intelligent then Windows.

What do you think?

Older Posts »