Tuesday, December 22, 2009

Tabs or Spaces

Some programmers have strong opinions about whether to use tabs or spaces to indent code.
This is what I use. In Visual Studio 2017 choose
Tools\Options\Text Editor\All Languages\Tabs
Select Smart Indenting
Tab size and Indent size = 4
Select "Insert spaces"

If you use Shift+Tab when in front of 4 spaces, it will delete the 4 spaces the same as if you press backspace in front of a tab character.
To convert a file one way or another there is "Tabify Selected Lines" and "Untabify Selected Lines" under the Edit\Advanced menu.

View White Space

Use the following Menu in Visual Studio to view the white space characters
Edit->Advanced->View White Space
This allows you to see whether the white space is tabs or spaces.

For me these characters are too prominent. So I dim them by choosing
Environment->Fonts and Colors
Select "Visible White Space" from the Display Items.
Select Silver. Then Click the Custom Button and use the darkness scale to choose the right amount of darkness.

In Beyond Compare you can select the following from the View menu:
Show White Space
Ignore Unimportant Differences

They are useful when dealing with differences in white space.

Wednesday, December 16, 2009

Tech Support Cheat Sheet

From xkcd, here is one great secret to computer tech support. Click on the picture to enlarge the flowchart.

I have written out some of the diagram so I can more easily find this post when I need it.
Google the name of the program plus a few words related to what you want to do. Follow any instructions.

Thursday, November 19, 2009

Covariance and Contravariance

My colleague directed me to some programming terms, covariance and contravariance.

Eric Lippert describes them quite well.

Wednesday, November 04, 2009

Reporting Services 2008 Custom Security

In MS SQL Server Reporting Services 2008 there is no longer an easy way to allow for anonymous access. I followed the steps here to get a custom security implemented. I modified it further to integrate with our existing security model.

You could also modify it to achieve anonymous access to your report server

Friday, October 23, 2009

Exception-Driven Development

One of the first things I like doing when coding is ensuring a stable error logging and notification system. I like to know about problems as soon as or sooner than my customers. And detailed logging really helps in reproducing and fixing the bug. Jeff Atwood calls this exception-driven development.

Today I found ELMAH. In a little more than an hour I implemented it in a ASP.NET app that did not have any exception handling implemented. It logs, emails and has a error log viewer. The screencast made this so easy.

Thursday, October 22, 2009

Keeping my Monster Mash

My wife used JibJab to create monster mashups of our family. I wanted to make sure we could keep the videos. I used CamStudio to capture the video and audio into avi files. I used MediaCoder to convert the avi to mp4 so I don't have to keep the very large avi files.


I just spent a long time figuring out a bug. Normally I use ASP.NET server controls. I have been working with a more JavaScript. I had a button HTML element on the page. I narrowed it down to the fact that the page submitted and reloaded when it was not supposed to.

After I added a type="button" to the button element, it stopped refreshing. After finding this article on StackOverflow, I have decided to use an input element specifying type="button"

Wednesday, October 07, 2009

Using JQuery UI Dialog with ASP.Net and AJAX Update Panel

I ran into an issue using an ASP.NET UpdatePanel and the JQuery UI Dialog. I found the solution here.

When I put an update panel in the dialog, it stopped posting back to the server. It seems that JQuery moves the containing div of the dialog by appending it to the body. This puts it as the last element of the body, outside of the form element.

The fix was to use JQuery to append the dialog to the form.

Wednesday, September 23, 2009

How to get Javascript Intellisense in VS 2008

I like to have JavaScript IntelliSense in Visual Studio. Using the ~ has not worked though. With permission of my friend, I am putting the email thread for later reference.

From: Stephen Walther
Sent: Wednesday, September 23, 2009 7:43 AM
To: Meacham, Samuel @ Tempe
Subject: RE: Javascript include problem that could easily be fixed for .NET 4.0

Hi Sam,

My favorite method of handling this issue is to use the Page.ResolveUrl method in the master page like:

<%= ResolveUrl( “~/Scripts/MyScript.js” ) %>

The ResolveUrl() method replaces the tilde ~ with the name of your application so that you can move your website without breaking the paths.

Another approach to solving this problem is to use the server ScriptManager (which also resolves the tilde ~ automatically) like this:

<asp:ScriptManager id="sm" runat="Server">


<asp:ScriptReference Path="~/JScript1.js" />



I agree that it is a little inconsistent that the <head runat=”server”> control resolves the tilde ~ for <link> tags but not other tags like <img> and <script>. But, you always have the option of using ResolveUrl in the <head> tag.

-- Stephen

From: Scott Guthrie
Sent: Tuesday, September 22, 2009 12:56 PM
To: Meacham, Samuel @ Tempe; Stephen Walther
Subject: RE: Javascript include problem that could easily be fixed for .NET 4.0

Stephen – any thoughts on this?



From: Meacham, Samuel @ Tempe
Sent: Tuesday, September 22, 2009 12:40 PM
To: Scott Guthrie
Subject: Javascript include problem that could easily be fixed for .NET 4.0

Sorry for emailing directly, but the art of feature requests and suggestions, while obviously important to both producers and consumers, has always been a dark one. I’m never sure where the appropriate forum is to make sure my idea gets read.

Master pages are great, and solved a lot of problems, like making sure the same css document gets included in every page in your whole app.

Having this in the master page:

<head runat="server">

<link rel="stylesheet" type="text/css" href="~/css/default.css" />

Renders this for a page at the app’s root:

<link rel="stylesheet" type="text/css" href="css/ErrorLoggerStyle.css" />

And this for a page in a subdirectory of the root:

<link rel="stylesheet" type="text/css" href="../css/ErrorLoggerStyle.css" />

Basically, the magic ~ solves all your problems. This doesn’t work for <script> tags, which leaves me 3 choices:

· Absolute URLs (“http://...”)

· URLs relative to the domain root (“/css/file.css”)

· URLs relative to the current directory (“css/file.css”, no leading “/”).

Obviously, each method has it’s pros and cons. With completely absolute URLs, the files will always be found (as long as they are there), but this doesn’t work well when you have multiple deployments, such as production, staging, and development, that require different versions of js files. Relative URLs fail when you have web content pages in subdirectories that use master pages in the app’s root (all of the paths break). URLs relative to the domain root (“/css/file.css”) don’t work when you don’t (or can’t) know the name of the app virtual directory, or if it changes depending on which deployment of the site you’re using (“mydomain.com/myapp” vs “mydomain.com/myapp_dev”).

Our solution here has been to put an <asp:Literal> in the <head> element, and the master page’s Page_Load() writes all the <script> tags to that literal element at runtime, with the paths properly processed. We could probably create a UserControl that did the same thing, but the end result would be the same: No js intellisense at design time.

None of the above options are particularly appealing. Do you think it’s a possibility to have VS2010/.NET 4.0 support the ~ for <script src=”~/js/file.js”>? It would solve a lot of headaches for a lot of people…

Sam Meacham

It is nice to see such prompt response from a software development team. Here are some other helpful hints.

If you are updating the documentation of your JavaScript functions you may use the Update JScript IntelliSense command (Ctrl+Shift+J) from the Edit/Intellisense menu.

Using Javascript in a User Control can be problematic since you don't know where in the file structure it may be used. The following code will enable JavaScript Intellisense at design time. The "if (false)" will ensure it is not run in the browser.

<% if (false) { %>

<script language="javascript" type="text/javascript" src="../js/util.js"></script>

<% } %>

Monday, September 07, 2009

Delete Stuck Print Job

Our printer was stuck on a print job. It would not delete. She was editing a photo and wanted to be able to undo what she was doing. Rebooting would have lost this state.

We followed the steps here. It successfully reset our print queue

Monday, August 31, 2009

"Mommy, where do ideas come from?"

I just read Mommy, where do ideas come from? It was insightful. Here are a few quotes I found interesting.
Experiencing real people in their actual environments fuels our senses of empathy and intuition that helps to guide us towards the ideas that make people happy, successful (and even better looking). Plus, the research phase affords us the opportunity to be fully immersed in the users and the domain for a few weeks at the start of the project, which in addition to providing rich data and empathy, also gives our brains boot-up time to start noodling on the problem and explore possible solutions in the background.
I am particularly satisfied when a solution I have created has made someone else work easier. I makes it more real when I talked with them or interacted in some other way.

Sometimes, words are worth 1,000 pictures

The first step in our design ideation process comes before any “official” sketching is done: we describe the users’ ideal experience in words. The scenarios we develop at this stage are forward-looking and technology-agnostic, focusing on the personas and how they think, feel and behave rather than on specific interface elements or technical implementations.
I am convinced that if we invest some time in describing in words the experience we want our users to have it will pay dividends.
There’s something special about the process of sketching - even jotting down some really bad ideas helps us learn about the tensions on the problem and gets us closer to a workable solution.
I love having the large jotting paper available to us since our move to our new office.

The power of paired designing

Because we work in pairs, Cooper designers often can’t say for sure where one person’s idea ends and the other’s begins. But what we do know is that our design partners are a major source of inspiration and design ideas. We come up with ideas while we’re talking through the problem with our partners, or while listening to them talk through it with us. We piggyback on each others’ ideas, zeroing in on what’s good about our partner’s proposed solution and tweaking what’s not working, buoyed by the collective energy in the room. And just having someone there to call b.s. when we’ve gone too far off the reservation frees us up to explore novel and even downright crazy solutions that may yield useful insights or contain aspects that can be applied to a more practical design approach.

As Richard Buchanan (Emma’s grad school professor) used to say, “Ideas don’t live in your brain or my brain but in the collective space between our brains.”

I know that one of the successes of MOS was the paired designing Sam and I did.

Don’t be afraid to stare out the window

One of the benefits our designers enjoy is that we are typically assigned to only one project at a time, which means that our design problems not only get our focused attention during work hours, but also find their way into our background brain cycles outside of the office. Oftentimes, ideas come in the shower, on a run or bike ride, or while washing dishes - any time that our minds are given the freedom to wander. Even here in the studio, you’ll often see designers staring out the window, watching a ship come into port or commuter-ants scurry through the crowded streets below. Taking some quiet time for woolgathering helps to reduce stress, while also distracting the judging part of our brains. After letting our minds meander for a bit, we can often corral some of those fragmented thoughts into a useful idea.

I am amazed at the amount of inspiration and motivation I get when I am mowing the lawn, working in my garden or just walking. Maybe there is something to the physical movement. Something about a simple task that doesn't take my brain power.

Wednesday, August 26, 2009

Modify Your Command Prompt Settings

I was just shown how to change some settings of the windows command prompt. This is what I changed.

Open your command prompt. Right click on the title bar and choose properties.

- Under the Options tab in the Edit Options section I checked QuickEdit Mode. This allows you to select text and hit enter to copy text to the clipboard.
- Under the Layout tab, I changed the Screen buffer width to 100 and the height to 500. I changed the Window width to 100 and the height to 35

When you click OK, you tell it to "save properties for future windows with the same title". If you open your command prompt from a short cut you choose "Modify shortcut that started this window".

Thursday, August 20, 2009

Dependency Injection

Here is a good explanation on dependency injection looking at Unity specifically.

Wednesday, July 22, 2009

UDF to summarize data by the week

There have been a few times I wanted to summarize MS SQL Server records by the week. There is not any built in function in T-SQL that I know that does that. The code here is a simple example of how you could create a user defined function that will encapsulate this logic so you can more readably use it in a SQL query.

/*BEGIN Proof of concept script of a user defined function
This script will clean up after itself

Written by Rich Alger 2009-07-22
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyTable]') AND type in (N'U'))
DROP TABLE [dbo].[MyTable]

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyTable]') AND type in (N'U'))
CREATE TABLE [dbo].[MyTable](
[Id] [int] IDENTITY(1,1) NOT NULL,
[DateCreated] [datetime] NOT NULL,
[Id] ASC

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[udf_WeekOf]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[udf_WeekOf]

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[udf_WeekOf]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
execute dbo.sp_executesql @statement = N'CREATE FUNCTION [dbo].[udf_WeekOf](@InDate DATETIME)
/* Return the 12:00 am of Sunday before the date passed in */
SET @DatePartOfInDate = CAST(CONVERT(VARCHAR(10), @InDate, 120) AS DATETIME)

DECLARE @WeekdayOfInDate INT
SET @WeekdayOfInDate = DATEPART(weekday, @InDate)

RETURN DATEADD(DAY, (-1 * (@WeekdayOfInDate-1) ), @DatePartOfInDate)

INSERT INTO MyTable (DateCreated) VALUES ('2008-12-30 08:32:27')
INSERT INTO MyTable (DateCreated) VALUES ('2009-01-02 12:17:16')
INSERT INTO MyTable (DateCreated) VALUES ('2009-01-06 09:02:43')
INSERT INTO MyTable (DateCreated) VALUES ('2009-01-13 16:53:02')
INSERT INTO MyTable (DateCreated) VALUES ('2009-01-14 11:12:34')
INSERT INTO MyTable (DateCreated) VALUES ('2009-01-15 13:38:23')

, dbo.udf_WeekOf(DateCreated) AS WeekOf
FROM MyTable

COUNT(*) AS RecordInWeekOf
, dbo.udf_WeekOf(DateCreated) AS WeekOf
FROM MyTable
GROUP BY dbo.udf_WeekOf(DateCreated)


/* This will drop the objects*/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[udf_WeekOf]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[udf_WeekOf]

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyTable]') AND type in (N'U'))
DROP TABLE [dbo].[MyTable]

/*END Proof of concept */

The following script will only add the user defined function

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[udf_WeekOf]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[udf_WeekOf]

CREATE FUNCTION [dbo].[udf_WeekOf](@InDate DATETIME)
/* Return the 12:00 am of Sunday before the date passed in */
SET @DatePartOfInDate = CAST(CONVERT(VARCHAR(10), @InDate, 120) AS DATETIME)

DECLARE @WeekdayOfInDate INT
SET @WeekdayOfInDate = DATEPART(weekday, @InDate)

RETURN DATEADD(DAY, (-1 * (@WeekdayOfInDate-1) ), @DatePartOfInDate)

Thursday, June 11, 2009

Enabling Concurrent Remote Desktop Sessions on Windows XP SP3

Very useful from The Boiling Mind:
If you have multiple users on your Windows XP machine, you might have heard it is possible to patch the terminal services service, to support multiple concurrent remote desktop connection (via RDP) to your computer.

Tuesday, June 09, 2009


Jonathan Weber said
I firmly believe that you should expect employees to show up for work, whenever possible, no matter what kind of company.

The reasons for this have nothing to do with checking that people are actually working. It's about efficient communications, building company culture and camaraderie, and sharing the daily bits of work and personal experiences that create a shared sense of purpose.

For over 9 months, I have been telecommuting 2 days a week. 3 other people in my team have also been telecommuting 2 days a week. One other telecommutes full time.

There are things that have not been communicated, or grown in the last while for us. That being said, I do love the freedom it brings me. It allows for more time with my family. I have less driving and lots of other benefits. I have more loyalty for my employer. Why would I want to leave and not have the benefit of working from home two days? I think my employer has made a good decision by allowing us to work from home.

We have been thinking about what we can do as a group to improve our collaboration. This is much more natural when you are all sitting in the same room. Conversations start. You show each other what you are working on. Expressing frustrations are an easy open into offering assistance. Input into design and best practices are shared.

We are moving towards a more formal software development methodology. A little more structured. Three goals so far are to design in pairs, do side by side code reviews, and have quicker iterations in our cycle. I hope that by following some structured guidelines, we will foster collaboration that happened easier when we all sat next to each other 5 days a week.

Thursday, May 07, 2009

The Development Abstraction Layer

I just heard my manager talk about some "business stuff" I usually don't hear about. It reminded me of this story in a Joel Spolsky article.
Programmers need a Subversion repository. Getting a Subversion repository means you need a network, and a server, which has to be bought, installed, backed up, and provisioned with uninterruptible power, and that server generates a lot of heat, which means it need to be in a room with an extra air conditioner, and that air conditioner needs access to the outside of the building, which means installing an 80 pound fan unit on the wall outside the building, which makes the building owners nervous, so they need to bring their engineer around, to negotiate where the air conditioner unit will go (decision: on the outside wall, up here on the 18th floor, at the most inconvenient place possible), and the building gets their lawyers involved, because we're going to have to sign away our firstborn to be allowed to do this, and then the air conditioning installer guys show up with rigging gear that wouldn't be out of place in a Barbie play-set, which makes our construction foreman nervous, and he doesn't allow them to climb out of the 18th floor window in a Mattel harness made out of 1/2" pink plastic, I [swear] it could be Disco Barbie's belt, and somebody has to call the building agent again and see [why] they suddenly realized, 12 weeks into a construction project, that another contract amendment is going to be needed for [this] air conditioner that they knew about before Christmas and they only just figured it out, and if your programmers even spend one minute thinking about this that's one minute too many.

To the software developers on your team, this all needs to be abstracted away as typing svn commit on the command line.

That's why you have management.
I am thankful for the development abstraction layer I have at work.

Folder Filters in Beyond Compare

We use subversion and ReSharper at work. Using wildcards on folder names in Beyond Compare lets me exclude the svn and ReSharper folders when comparing two working directories.

This is how my filter shows up in the text box: "-*_svn\;-*_ReSharper*\"

Thursday, April 23, 2009

Pidgin: Cannot connect to Yahoo - "connection refused" error

Recently my Pidgin, version 2.5.5, stopped connecting to the yahoo im service with a "connection refused message" I found that this was a recent issue with a work around.

I created a batch file to do this work-around if this happens again.

REM flush dns so pidgin will work with yahoo
REM see http://developer.pidgin.im/ticket/8853#comment:5
ping scs.msg.yahoo.com
ipconfig /flushdns
ping scs.msg.yahoo.com

UPDATE 2009-06-21

There are further issues with this that showed up last week, or maybe just more yahoo servers are upgraded. Pidgin 2.5.7 works for me so far and I flushed my dns a couple of times.

See http://developer.pidgin.im/ticket/8853#comment:77

Tuesday, April 07, 2009

SQL Server Reporting Services 2008 Custom Assembly Error

Error while loading code module: ‘RS_funcs, Version=, Culture=neutral, PublicKeyToken=null’. Details: Could not load file or assembly 'RS_funcs, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Last fall I was getting this error when trying to get our reporting projects created in VS 2005 to work in VS 2008. I found this post showing where to put your custom assembly in order for the VS designed to work. I post it here so as not to forget again. In VS 2008, the path is "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies"

Wednesday, January 21, 2009

Generics Review

I have had some practical experience with generics. Here is a nice explanation, from ondotnet.com, of the problem generics solves. I particularly like this summary statement, "Generics thus allow you to create type-safe collections without having to duplicate code. "

Tuesday, January 13, 2009

How to find Windows uptime?

From MS Help and Support

1. Go to "Start" -> "Run".

2. Write "CMD" and press on "Enter" key.

3. Write the command "net statistics server" and press on "Enter" key.

4. The line that start with "Statistics since …" provides the time that the server was up from.

  • The command "net stats srv" can be use instead.