Tuesday, February 17, 2009

Programs for reading and writing code in different languages

Just a quick post to keep things going. I end up having to read more code than I write, mainly because even when I write code I am usually pulling bits and pieces from old projects. When writing code I always use a full IDE, since I have become dependent on features such as code completion, breakpoints/debugging, and visual designers. For reading code these features are not as important, but code syntax highlighting and region/section collapsing are still very useful. For writing code I use all of the standard IDEs: Visual Studio 2005/2008 for .NET, SQL Management Studio for MS SQL, PowerShell Analyzer or PowerShell Plus for PowerShell, and IronPython Studio for IronPython. For reading code, rather than loading a bulky IDE I have started to use a free program called Notepad++, which supports multiple tabs, region collapsing, and syntax highlighting for a myriad of languages. It works a lot better than reading code in notepad and loads much faster than Visual Studio. Here is a screenshot:

Thursday, February 5, 2009

JavaScript and CSS based popup for changing Google Analytics User Segment cookie

I use Google Analytics on all of the sites that I work on for tracking page views and traffic sources. It has great reporting features, but I always have problems with traffic from my office computer or home laptop skewing the results. Most of the computers that I use have dynamic IP addresses, so a static IP filter does not work. Instead you have to setup a cookie based filter. The problem is then how do you setup the cookie and monitor if your traffic is currently being tracked or not? I created a small JavaScript and CSS based popup for setting and clearing the cookie that I can then add somewhere to the site. The first section is the JavaScript code. Place this block somewhere in your HTML or template:

The second section is the DIV/CSS popup that contains a few links that you can click on. Again just place this anywhere in your HTML or template (it uses fixed positioning and will always appear in the middle of the screen):

The final section is a link that can be placed somewhere on your page. Clicking the link will display the popup:

I use a period for the link text and hide it somewhere on the page. This way I can click the hidden link from any computer to disable tracking for that browser. This is an example of what the end result looks like:

For some reason Google Chrome does not let your clear the __utmv cookie using JavaScript. It works in IE and it works in Chrome on a localhost page, but it doesn't work on the live blog. A bit strange, but you can always clear the cookie manually in the browser. Oh, and don't forget to setup the filter in Google Analytics to exclude the traffic (see link above)

The next time I work on this I will probably change it so that the tracking status is displayed on the actual link itself using red "__ TRACKING DISABLED __" text if your page views were not being tracked or a normal period to anyone who's traffic was being tracked.

Wednesday, February 4, 2009

First Post! (aka CodeBlog Mission Statement)

I end up coding in a lot of different languages and keep on forgetting how to do simple things (is it "for x in y", "foreach", etc...). I need some place to store code that I can access from anywhere so that I don't have to keep going to Google each time I forget something. I don't want to post code snippets to my personal blog, so this is the new holding spot for all my coding tricks and treats. And thanks to SyntaxHighlighter 2.0 created by Alex Gorbatchev all those code snippets will be in full color and easy to view. For example, take this prize python gem: This returns: Don't expect any long winded posts about Systems vs. Apps Hungarian Notation (ok... well maybe a few :-) as this is designed to be home to just sweet, sweet code. Enjoy!

Blog.TheG2.Net - Your guide to life in the Internet age.