A C# PrettyJson Extension Method [Gist]

I wrote this for my .JSON module:

Here is the gist page, if it doesn't show up here.

It seems to work pretty well and it's pretty simple, as long as it receives valid JSON.

Introducing .JSON, 500 lines of dynamically typed JSON goodness

image

Ever wish you could work with JSON in .NET as you normally do with regular old objects? Well, now you can:

string url = "https://github.com/api/v2/repos/show/kamranayub";
dynamic[] repos = JsonService.GetFrom(url).repositories;

return View(repos.OrderByDescending(r => r.watchers);

Enter .JSON, a single file that holds 2 classes you can use to manipulate JSON in a dynamic way, either from web services, strings, or objects.

dynamic json = Json.Parse("{'foo':'bar','baz':['a','b','c']}");

string foo = json.foo;
string[] = json.baz;

Inspired by Massive, I decided this would be a useful tool for the community, seeing as all the existing JSON libraries for .NET are not exactly what I'd want when dealing with JSON data.

I wanted several things from this:

  • Ease of use
  • LINQ
  • Dynamically typed
  • GET, POST, and authentication support
  • One file
  • Minimal dependencies (there's one for using Microsoft's built-in serialization/deserialization of JSON but it's GAC'd at least).

I am happy to say that as it stands, I've accomplished all of them. If you spot bugs, open an issue or patch it. I plan to refactor it a little to support a Fluent interface, but other than that, it pretty much just works.

Happy JSON'ing!

You calling me fake, boy-o? [Spam]

I saw this comment on my Code Canyon item today (editorialized):

You stole this from so-and-so's book, it's almost exactly the template they provide, blah blah, more false accusations.

I offer you, accusation-spewing fiend, some proof that I own this code:

image

Is their template laid out exactly like this? Doubtful considering I made it.

image

Yep, looks like my code alright…

image

Hey look, API documentation for everything I made?

I don't know what template you were looking at, but I'll give you $1000 that it doesn't have any of those functions. All of these helpers have been functions I've made in the past during my years as a programmer. Hell, I probably can dig up a lot more.

Anyway, I don't need to prove myself to you. It's not fake, I worked on it for about a week, and I should really update it, thanks for reminding me. It's just a template that helps people get up and running a bit faster during development, the helpers are a useful add-on.

If you don't like it, use Sharp Architecture. It's probably more up-to-date now, anyway! I have been considering taking my template off Code Canyon anyway in favor of creating a new, free template on GitHub and keeping just packaged snippets to being sold. Mine is woefully out-of-date with best practices (LINQ to SQL??? No DI containers??? The horror!).

Good day to you, sir.

Making jQuery Play Nice with XML [Project]

tl;dr I've made a plugin for jQuery that makes it easy to work with XML natively in jQuery. Get the code from my GitHub.

I've been working on a project that has required me to parse and manipulate XML on the client-side. Since I was using jQuery on the project, it made sense to leverage its cross-platforminess and easy coding style to manipulate the XML.

Unfortunately, jQuery hasn't really buried its claws very deep in the XML realm because if you've tried doing anything with XML you've probably run into issues. If you don't care about IE, you'll probably have less issues, but in my case, I had to support IE and even with vanilla jQuery, some things still don't work in other browsers.

In plain old Javascript, you can manipulate XML in IE using ActiveX and the MSXML object. However, it's IE-specific and it lacks the ease of use of jQuery. I wanted a way to leverage jQuery and also support multiple browsers.

So, I've created a helper function (plugin, really?) that helps jQuery deal with the XML and any nuances it has (such as text vs. CDATA nodes, etc.).

You use it just like you normally would with jQuery with one exception:

var $xml = $.xml("<your_xml_string />");

You have to use the function I created to instantiate it.

Other than that, I've tried to make it as seamless as possible, though I have yet to test every use case. I got it far enough that it works for my project, even doing some advanced selectors and manipulation. Webkit has a bug with the appending but I'm hopeful when I sit down and look at it it'll be an easy fix. I seem to have fixed the Webkit bugs.

There are two XML-specific functions you can use when dealing with my plugin as well:

// 1. .cdata()

// Get CDATA, which will return non-encoded data
$xml.find("mynode").cdata();

// .html() has been redirected to use CDATA on XML documents
$xml.find("mynode").html();

// To set CDATA, use the cdata function
$xml.find("mynode").cdata("<strong>html</strong>");

// 2. .xml()

// Use .xml() to get the outer XML of the element
var wholeDocument = $xml.xml();

var nodeXml = $xml.find("mynode").xml();

I've posted it on GitHub for a reason. I don't exactly plan to add anything extra unless it has a bug I directly deal with in my project (after all, I made it to get the job done). However, you can totally make it better if you feel like it and I'll merge your changes to the trunk. Fork it, pull it, whatever, I welcome any additions and help.

Site Updates and Bug Fixes (1/30/2011) [News]

I made some updates today to the site.

Features

  • Added Gravatar support for comments. Incredibly easy to do and really makes them pop!

    image
  • Added RSS for comments on blog posts so you can keep track of responses (instead of .aspx for the post, use .rss, or subscribe using the browser functionality or the link above the comments)

    image

    image

Bug Fixes

  • URL parsing in comments fixed (case sensitivitity issue)
  • Converted UTC dates for posts back into local (server) time
  • Some blog API fixes

I have set up Web Deploy on Arvixe and it really makes it easy to push these kinds of updates out.

It's About Time I Let You Fix My Bugs [Social Coding]

Over the past months, I have gotten some feedback on some of my projects that there are bugs, feature requests, etc. etc. and while I am a busy person, some of it is that I am just lazy :)

image

So, that's why I am leaving it up to you if you want! You can pull my GitHub repos to your local computer and patch them. If you push them to your fork, I may even pull them into the main branch if your patches are awesome.

I've added:

  • jQuery RTE
  • Image Grid Creator
  • Just Another Carousel

I am also thinking about releasing my WPF Black Jack application for anyone to fix. It's like 6 years old now but still pretty neat.

Happy New Year! Intrepid Studios Has Been Re-designed [Rejoice]

image

Remember way back when I posted about the upcoming redesign? It’s here! I figured it was a good time to spend a couple days and finish up the last few modifications to the site.

One of the big features I added was RSS support for many different types of things like projects, releases, tags, blog posts, designs, etc. You can keep up-to-date pretty easily now.

I don’t want to spoil anything for you, so just have a look around!

Other than this redesign, I hope to work more on my Code Canyon projects and release some new material. I may also play with some Android application development.

If you’ve been wondering what I’ve been up to, I currently work full-time at General Mills as a programmer analyst. I won’t be taking on any huge projects because of that, but if you have a small one, feel free to pass it by me.

Debug Your .NET Web Project With IIS Express [Tips & Tricks]

Update: IIS Express has been officially released as a standalone installation.

For those of us too impatient to wait for Visual Studio SP1 to natively support IIS Express, I've done some digging and found a way to [fairly] easily setup a debugging environment for IIS Express and VS 2010 (should work for VS 2008 also, though!). This assumes you are at least an intermediate user of .NET/IIS and Visual Studio.

Prerequisites

  1. Download and install IIS Express.
  2. Be using Visual Studio 2010 or 2008 and a web project to debug.

Steps to Setup IIS Express

It's actually quite simple to setup IIS express. Once IIS Express is done installing, go to "My Documents\IISExpress8\config".

image

Right-click "applicationhost.config" and open in your favorite text editor.

Go to line 145. Notice the <sites> element. This is where we can configure our website for IIS Express. Copy the site that is already there and add another entry below it.

Remove the "autoStart" attribute for the first site.

image

This should be self-explanatory, but in case it isn't, we are setting up a root site in IIS:

  • "name" is what you want the website name to be. This can be whatever you want.
  • "id" is just the ID of the site for IIS Express. Increment it.
  • "physicalPath" is the directory your site files are located in, i.e. the root folder of the website. Mine is below:

    image
  • "bindingInformation" is where you set the host name and port you want the site to run in. This can be whatever you need it to be, perhaps if you have a static port set on your VS project.
  • "applicationPool" is the app pool to run under. This is important! If your site is .NET 4, you can use "Clr4IntegratedAppPool". If you are .NET 3.5 or below, you must use "Clr2IntegratedAppPool". Otherwise you will get config errors.

Let's test it out! Save the config file and close it.

Go to Run… and type in the following command:

"C:\Program Files (x86)\Microsoft WebMatrix\iisexpress.exe" /site:{YOUR_SITE_NAME}

Replace "{YOUR_SITE_NAME}" with the name you gave the site in the config file above. If you are on 32-bit windows, omit the " (x86)" part after Program Files.

Side Note: You can get a list of command-line switches by going into Command Prompt and typing in "iisexpress /?". You'll notice you can also directly launch any site by physical path and desired port.

Now open your browser and browse to the URL of your site! Voila, it should work (or not, in my case… but that's because this isn't my dev machine):

image

You might want to create a shortcut on your desktop to the run command I had you type in earlier. It will make it a lot easier to start IIS Express when you're developing.

Note: Now that you've set up this web site, you could manage it from the WebMatrix GUI if you prefer that method for more advanced settings.

Setting up Visual Studio 2010/2008

Go ahead and open up your solution in Visual Studio.

Right-click on your web project and go to Properties, then the Web tab. Click the "Start URL:" radio button and put in the path to your site:

SnipImage

Then below it, click the "Use Custom Web Server:" radio button and again put the path to the URL:

SnipImage (2)

Next, and this is important, uncheck everything below it. Visual Studio will try to attach to the non-existent IIS server otherwise and not let you debug. We're sort "tricking" it into using IIS Express.

Save and close the project's properties. Now hit Alt-F8 to open up Macro Explorer. Right-click on the My Macros –> Module 1 node and click "Add Macro."

macro_explorer

Use the following macro:

SnipImage (3)

Source:

Public Sub AttachToIISExpress()
    For Each process As EnvDTE.Process In DTE.Debugger.LocalProcesses
        If (process.Name.IndexOf("iisexpress.exe") <> -1) Then
            process.Attach()
        End If
    Next
End Sub

 

That is it. The process to follow is:

  1. Start IIS Express using the run command/shortcut above.
  2. Hit F5 to start debugging. Visual Studio will enter debug mode and start the site in a browser window.
  3. Next, run the macro we created to attach to the IISExpress server.
  4. Voila, you now can debug not only your solution's code but also any scripts loaded by the browser!

SnipImage (4)

Setting up a Keyboard Shortcut

If you're like me, right-clicking and running the macro is too much work! So let's create a keyboard shortcut, shall we? How about 'F4'?

Go to Tools –> Customize… then click the "Commands" tab. Select "Debug" in the "Menu bar:" drop-down.

SnipImage (5)

Click "Add Command…" and click "Macros" in the left-hand list. Click the IISExpress macro.

SnipImage (6)

Now just rearrange the list to your liking. You can click the newly added command and then click Modify Selection –> Rename.

Click Close and close the customize dialog.

Go to Tools –> Options. Click Keyboard in the left-hand list. Start typing "view.prop" to find the Properties Window keyboard shortcut (already assigned to F4). Hit Remove to get rid of the F4 shortcut.

SnipImage (7)

Now type in "iis" to filter down to the IIS macro. In the shortcut keys box, hit F4, then Assign.

SnipImage (8)

All done! Now instead of right-clicking the macro every time, you only need to hit F4 after you hit F5.

Closing Comments

Remember that this is just a temporary workaround until Scott and his ninja team release a hotfix for Visual Studio to enable native IIS Express integration. I needed this functionality this weekend while working on a project (due to how Cassini handled URL requests and because attaching to IIS 7 for debugging was not working for me).

I hope this helps some other fellow curious developers. As always, leave a comment if you have a suggestion to streamline this even more (I attempted to wrap the whole debug process into one macro with no success… maybe someone smarter than me can!).

You Say Goodbye WebHost4Life, I Say Hello Arvixe

image Well, I guess I'm the one saying goodbye to Webhost4life. Yes, they had a decent run but all in all their service is not as good as I thought it was. Bar not being able to use the new control panel for months the site was slow and I was itching to convert the new Intrepid Studios to .NET 4.

I made the decision to switch to Arvixe after I couldn't get sub-domains to work on the new Webhost4life platform for the life of me. Their control panel was just abominably slow and didn't allow the control I needed.

I googled "top rated asp.net web hosts" and Arvixe was one of the top on the list. I searched other rating sites just to be safe. While their site was nothing much to look at in terms of design, their feature list was quite impressive (ahem, multiple MSSQL databases? Score!). It took me about 5 minutes to setup my account, another 5 to backup and restore my database to their server without a hitch, and not very long to transfer all my existing files over via FTP. I set up my mail accounts (and I use POP3, so I didn't worry about losing any mail) and pointed my domain's DNS name records to their server. All done in the span of a couple hours.

I must say, I am pretty pleased with the experience. Not only that, my site is way faster… and will be even better once I release the new site (it's coming soon!).

No host is perfect and I'm having some trouble setting up password protected folders but for now I use Forms authentication so it's not too big of a deal.

MinneWebCon 2010 – Informal User Testing

I just finished up with attending this year's MinneWebCon. I was excited because it was my first time being apart of a presentation at such a large event and I hope it's not the last. Our topic was about informal user testing and how that helps drive design and creating a usable application. The main speaker was my old supervisor, Zach Johnson, and then those of us who currently work at Student Unions & Activities: Ken Loomis, Ethan Poole, and me.

Presentation

New Version of Intrepid Studios En Route [Stay Tuned]

We are our own worst critics and I am no exception to that. Since I last released this initial version of Intrepid Studios a year or two ago, I've always been unhappy with a few parts of the site and some of the design in general. This last week, I've been motivated to change that and fix things around here. More »

Jumpstart Your .NET Web Application Development - $12 [Marketplace]

I've been exploring the CodeCanyon marketplace for a little while now and I am pretty impressed. It's an opportunity to monetize some ideas I've had and to gain some portfolio work and possibly more customers. I've been a proponent of free software (I provide some on this site) so I won't be selling everything I make, but I think it's nice to put some product out there as a web designer.

image

I've just released my Web Application Template package for .NET web applications (and it's only $12). It's basically what I would prefer to start with every time I work on a new web site… in effect, a "Web App in a Box."

It supports .NET 3.5 and .NET 4 and offers a slew of features (ELMAH integration, compression/minification of CSS and JS, etc), the to-do list ever growing. You can be sure I'll keep it updated because I will be using it myself! I'm already using it for a new version of Intrepid Studios (not a total redesign, more enhancement-like).

I was sick and tired of all my projects using different file/folder/solution layouts and having to duplicate code across them all the time. I wanted a way to easily get started without spending time configuring everything. While I was working on it, I thought it would be useful for other developers. Will it really save you six hours? Well, it took me a solid 6+ hours of development time to set it up… and then some. Six is a safe bet, possibly more if you aren't that familiar with some of the components I integrated.

As always, let me know if there are bugs and improvements you think of.

You can also check out my previous CodeCanyon release, Google Picasa Gallery + API.

Making UrlRewritingNet Ignore URLs [Fix]

I recently updated the Intrepid Studios site back-end to include ELMAH, the error reporting module. ELMAH is great and works great, except that it doesn't play nice with UrlRewritingNet.

There is a StackOverflow discussion about this with a workaround that ended up not using UrlRewritingNet at all unfortunately. In addition, there's a detailed post about doing some voodoo and mixing potions to get UrlRewritingNet to work. Note that you can simply remove the defaultPage attribute on the urlrewritingnet config section to solve this, but it may cause other unintended consequences.

I thought to myself, there's gotta be a better way! And there is (well, it's a hack so I suppose it is not entirely the best, but it is the simplest so far). I simply added in a few lines of code to the UrlRewritingNet source code to allow you to ignore URLs. Without knowing much about how the component works, this is an easy "patch."

Download the Modified Binaries

For those that don't care how I did it, I have uploaded the modified binaries you'll need to replace in your application. See below for an explanation of how to use it.

Getting the Source

Head over to the Downloads section of UrlRewritingNet to get the source code.

Extract the files to a directory of your choice.

I opened and converted the solution with VS 2010, but you can use anything you wish.

Modifying the Files

We will modify 3 files. Follow along below.

In WebRewriteOption.cs, add another value to the enumeration like so:

[Flags] 
public enum RewriteOption
{
    Application = 0x00,
    Domain = 0x01,
    None = 0x02 // KR: Ignore the URL
}

In WebUrlRewriteModule.cs, around line 212, add the following underneath if (rewrite.IsRewrite(requestUrl)):

//KR: ignore url
if (rewrite.Rewrite == RewriteOption.None)
{
    rewritten = true; // sure, we totally "rewrote" it, heh.
    break;
}

In urlrewritingnet.xsd, change the xs:simpleType for RewriteOption to be:

<xs:simpleType name="RewriteOption">
  <xs:restriction base="xs:NMTOKEN">      
    <xs:enumeration value="Application" />
    <xs:enumeration value="Domain" />
    <xs:enumeration value="None" /> <!-- KR Ignore URL -->
  </xs:restriction>
</xs:simpleType>

Finally, in the same file, change the use="required" attribute of destinationUrl to be optional, like so:

<xs:attribute name="destinationUrl" type="xs:string" use="optional" />

Build the solution in Debug/Release and copy over the new DLLs to your project. Voila, all done! Now all you need to do to NOT rewrite a URL is the following:

<add name="Elmah"
  virtualUrl="^~/elmah.axd(.*)$"
  rewrite="None"
/>

I've tested it with Intrepid Studios and it seems to work just fine.

As always, feedback and improvements are much appreciated!

Update: jQuery Rich Text Editor [New Version]

image

A new minor update has been released to the jQuery Rich Text Editor with some new icons and an ASP.NET demo.

Changes

  • Added Silk icons for a nicer look
  • Added ASP.NET demo solution to test the script
  • Added extra function "$.rte.html".
  • Updated code to match latest changes in Google Code repo.
  • Note that this release contains BREAKING CHANGES because the options have all been renamed (see Documentation)

I tested the script with the latest jQuery release and it still works.

Let me know if you run into any trouble. I think it may still have some trouble with nested controls, which I will test soon, since my admin panel wasn't saving the text written in the control.

View the project homepage for the jQuery Rich Text Editor

Windows Phone 7 Quick Tip: Disable Hamachi [Tips & Tricks]

I ran into a problem while playing with the Windows Phone 7 CTP the other day. I was trying to use the Google data services via the WebClient object. It was throwing exceptions no matter what I did. I noticed it threw exceptions on ANY Google-hosted URI.

Long story short: disable Hamachi or any other potential virtual network adapters. VMWare seems to not interfere but Hamachi enjoys taking over connections sometimes and will hijack your phone emulator.

You can view the details of my adventure right over yonder.

 1 2 3 4 5  
An error has occured while trying to process your request. Hide