Category Archives: Development

The Debugger IS Your Friend!

I’ve been trying to contribute (when I have time) to the ASP.NET Forums lately. I’ve noticed that a lot of people who are new to ASP.NET don’t seem to know to use the Visual Studio debugger. When you see funky things going on in your code or behavior that you can’t explain, jump into the debugger. It’s saved me major headaches before. That and its good to walk through your code line by line for testing purposes. It makes you analyze each line if cide to make sure its doing what you expect it to do. So, moral of the story, don’t be afraid of your debugger, it’s your friend!

Radiant CMS & Web Services

As I’ve written about previously, I’m working on a Radiant site with my buddy KB. We want to leverage a newsletter building application and an email sending service that we’ve developed for our other projects in this site. To do so, we needed to consume some web services that are part of another Rails application to do the subscribing and unsubscribing from a mailing list. There doesn’t seem to be much information about consuming web services from a Radiant application, so I thought I’d share what I found here. My discovery was based on a suggestion by Sean Cribbs to look at the Radiant LDAP extension.

So basically I found that you need to create a global tags module. In it you define your ActionWebService API and the tags you’ll use. Here’s a sample:


require 'action_web_service'

module MyTest
   include Radiant::Taggable
   class MyTestApi < ActionWebSerivce::API::Base       api_method :some_method, :expects => [{:foo => :string}]
   end

   tag 'mytest:action' do |tag|
      if request.post?
         # some code to get posted values
         myval = request.paremters['mytestvalue']
         if myval.empty?
            raise "No value."
         end
         mytest = ActionWebService::Client::Soap.new(MyTestApi, "http://someapiurl/", :handler_name => "some_handler"
         mytest.some_method(myval)
      end
   end
end

So that’s it in a nutshell. Wrap your tags and an Api class in the same module. You can call your Api methods from your tag definitions to execute the services you need.

Norton AntiVirus & ASP.NET Request.UrlReferrer

I like it when my code works. Most developers do. What I don’t like is when code I KNOW works all of a sudden STOPS working. I spent a good 3 hours ripping my hair out trying to figure out why all of a sudden UrlReferrer was always null in my ASP.NET application. A week ago, my code worked great. Today it doesn’t. I did a lot of digging, asked a couple questions on the ASP.NET forum, but no luck. Then today, I stumbled upon this thread. Could this be? A third part application, one I use to protect my development machine, be hosing my app? Turns out it was. Calling the same code from my MacBook worked as expected.

So what happened? I think a NAV virus definition update changed how the headers appear in HTTP requests from my machine, as stated in the article. I realize we depend on these third party virus protection software applications to protect us from malicious software and the like, but this is crazy. At least tell me you’re doing it and then give me an EASY way to turn it off.

Another interesting implication of this, that was briefly touched on in the above mentioned thread is, would this affect statistics capturing software? Would the stats in Google Analytics be skewed? My guess is yeah, to some degree they will be if header information is held back. What are other people’s thoughts on this?

Giving Back to the Community

No, I’m not referring to the neighborhood you live in, though you should as its a nobel thing to do. I’m referring to the Developer Community. I had one of the developers I used to work for several years ago suggest that since I was starting to ask a lot of questions to a Windows development community, that I should consider going through other people’s questions and try to help out. Not only would I probably learn something from reading other people’s posts, but I’d be adding to a growing community that was there to help people with questions just like I had. We all know how frustrating it is to be stuck and want some help. So when someone asks, help them out. Find communities that have to do with your development interests and pitch in!

ASP.NET Caching

There are a few types of caching in ASP.NET, specifically Page Output Caching and Object Data Caching. There are whole hosts of articles out there on using the cache, but for the purposes of this post, I’m going to talk about just using Object Data Caching. To many, this will be obvious, but some cache code I wrote recently made me remember that this can sometimes be confusing in the context of an ASP.NET page.

Typically, you can access the cache from just calling Cache.Add or HttpContext.Curent.Cache.Add. This gives you access to the application wide Cache object. Any object you cache here will be available to any class within your application for the time period you specified for the cached object.

But what if you want to just cache an object for a request? Say you have an item object that you reference on 4 or 5 controls on a page? You don’t want to go to the DB to get the data each time you reference it. Instead, use the HttpContext.Current.Items collection and put your object there. It will be good for the duration of the request.

The two are very different. The first will make your cached data available application wide, to all requests. This can be dangerous if the data might be different for one user than it is for another. The second is available only to the current request. Use this if you load up an object say from the database in one control, but need it in subsequent controls that make up the same request.

Be careful with your cached objects and keep an eye on where you’re putting them. Not doing so can have some potentially disasterous effects.

Linux Ethernet Information

I’m in the process of rebuilding the kernel on my Debian Linux box and wanted to make sure when I rebuilt it, I had all the hardware info I needed. This included the 2 ethernet adapters that are installed. I remember when I first installed Debian, I had to get a special install disk because of ethernet hardware Dell used for its built in adapter. I couldn’t remember what it was, and I didn’t want to shut the machine down to look inside, so I did some digging on Google and came across this site which gave the following tip:

dmesg | grep eth0

which resulted in this

eth0: Tigon3 [partno(BCM95721) rev 4101 PHY(5750)] (PCI Express) 10/100/1000BaseT Ethernet 00:14:22:7a:a6:a6
eth0: RXcsums[1] LinkChgREG[1] MIirq[1] ASF[1] Split[0] WireSpeed[1] TSOcap[1]
eth0: dma_rwctrl[76180000]

Cool! The command dmesg prints or controls the kernel ring buffer. Just grep what you’re looking for an the information you need comes up.

Acquainting New Developers

A co-worker and good friend of mine is changing jobs soon. It will be sad to see him go, but it got me to thinking a little. It’s always hard to take a new position. New co-workers in a new workplace culture can sometimes make you feel uneasy. Typically because you’re just the new guy and that’s how you feel. I started to think how it was for me when I took my current position 18 months ago, I felt a little awkward, even though I knew my co-workers personally. It was a different environment and a code base I was unfamiliar with. Knowing my co-workers personally made it easy to fit in on a personal level. But how easy was it to fit in on a working level? I had to learn how their application was developed. Where modules were and what did what.

I realized later on that I was able to pick up the new code base so quickly because of how I approached my new job. I noticed that they were having several error prone parts of the application (we received emails for every error that occurred in the web application) and I decided that I’d just jump right in and figure out what the issue was. After two weeks of basically bug squashing, we not only had a pretty solid application, but I also knew the code base inside and out.

I guess what I’m trying to say is if you want your new developers up to speed on your application the quickest, put them on bug squashing tasks for a couple of weeks and see where they are. I bet you’ll find out they learned more just going through the code fixing problems than if you just let them sit there and try and read code.

Why Reusable Code Rocks

A lot of people talk about reusable code. The Pragmaic Programmer’s push the DRY (Don’t Repeat Yourself) Principal, which I’m a huge fan of. Hence this article. What you don’t see a lot is how writing reusable code pays off. Kyle and I have two (soon to be three) e-commerce sites (YumDrop, Fright Catalog, Import Costumes) up and running. YumDrop was built upon the code base origionally written by Kyle, Joe and Dan for Fright Catalog. We pulled out all the common parts and created a base that we could reuse. Then, Kyle took his CSS and created a basic framework he could reuse. What this meant for us as a development team was that we could roll new e-commerce sites in little time. For instance, Fright Catalog took Kyle, Dan, and Joe about 6-8 months to roll out. YumDrop took us probably 2 months after we finished componentizing the codebase. Import Costumes will take us about a month to roll out. Now that’s what I call seeing the real world impact of writing reusable code.

Unix Recusive Delete Using Find

Today I found myself needing to delete a .svn directory from a Radiant CMS extension I wanted to use (the developer left them in the download, tsk tsk). Anyway, I didn’t want to traverse all of the folders myself, so I found this nifty article over at IBM that gave me what a wanted, which was this:

find . -name .svn -ok rm {} \;