Friday, April 23, 2010

Making Visual Studio copy .config files

I'd created a few XML configuration files and given them the extension .config, since it was a descriptive name with the added bonus of IIS refusing to serve them.

However, using the Publish function in Visual Studio 2010 (right click -> "Publish...") to copy to the local file system, my custom .config files were never in my output directory. However, the .config files I'd created using the web.config file template were there.

I'd tried setting their "copy to output" setting to "always copy" and "copy if newer", all to no avail.

Eventually, it occurred to me to compare the properties of the ones that did work to the ones that didn't.

Screenshot of properties dialogue, 'Build Action' highlightedSo, the solution:

Bring up the Properties window for the file (right click -> Properties or alt+enter) and set the Build Action to "Content".

Now my files are copied successfully.

Wednesday, April 14, 2010

A pet peeve: Switch vs. If/Else If

One of my pet peeves is seeing an if/else tree where there could be a switch statement. I get even more annoyed when I see it in official sample code from Microsoft.

From the MSDN description of System.Web.UI.WebControls.MailDefinition
if (sourcePriority.SelectedValue == "Normal")
{
md.Priority = MailPriority.Normal;
}
else if (sourcePriority.SelectedValue == "High")
{
md.Priority = MailPriority.High;
}
else if (sourcePriority.SelectedValue == "Low")
{
md.Priority = MailPriority.Low;
}


I admit that my reasoning is largely aesthetic - switch statements just look neater, and I find them easier to read. Switch is generally held to be the more efficient of the two, but I will accept that for a 3-option split the performance gain is likely to be negligible.

Also, in this particular case, you could even use Enum.Parse().

Tuesday, April 13, 2010

It's been a while!

Some Visual Studio regular expressions I've found useful recently:

To replace your lazy Response.Write statements with something a little more correct:
Find: Response\.Write\({.#}\);
Replace: Results.Text += \1;
(Or stringBuilder.Append(\1); or whatever is appropriate.)

To find textboxes (Html.TextBox from the ASP.NET MVC helpers, and standard input elements) that don't have a maxlength set. Works on single lines only.
(Html\.TextBox|input type="text")~(.#maxlength)
(Replace maxlength with any other text for other properties.)

I found this Knol by Brian Lalonde very useful in creating these regular expressions (and I love the snarky ending paragraph).

Sunday, June 17, 2007

How to Create a Theme in Windows SharePoint Services v2

I was going to make a post about making SharePoint 2003 themes, but while I was searching for resources I came across this guide by Heather Solomon, which is far more comprehensive than anything I would have written.

Thanks, Heather!

Butterscotch ice cream

I had butter and brown sugar lying around the house, so I decided to search for a Butterscotch Icecream recipe. The only problem was that the recipe was all in Imperial (and measured sugar in grams, which is a pain for me as I don't have an electric scale).

Consequently, I present you with the same recipe, but with different measurements.

Butterscotch ice cream

60g Butter
6 tbsp Brown sugar; dark, soft
1 cup full cream milk; warm
2 Eggs
5 tbsp Caster sugar
1/4 tsp Vanilla essence
Whipping cream (10oz./283.5 g, which I estimate at about 300mL)

1. Melt the brown sugar and butter together in a pan over a gentle heat. Increase the heat until the mixture bubbles for 1 minute only.
2. Allow to cool slightly.
3. Add the warm milk.
4. Stir continuously over a gentle heat until thoroughly blended.
5. Allow to cool.
6. Beat together the eggs and the caster sugar in a bowl.
7. Pour the mixture from the saucepan on to the beaten eggs/sugar, add the vanilla essence and stir.
8. Strain back into the pan.
9. Stir over a low heat until the mixture thickens slightly; take care not to let it boil.
10. Cool the mixture.
11. Whip the cream lightly and fold into the cooled mixture.
12. Pour into a freezer container and freeze until mushy. Beat with a whisk and return to the freezer until the ice cream is firm. Put in icecream maker.
(Website notes recipe is from Scottish Tea-Time Recipes by Johanna Mathie, ISBN 1 898435 18 9.)

This is good with shortbread bits added, or macadamias, or with chocolate fudge sauce.

I'm not sure about the cream quantity, so it might come out a little intense, depending on your tastes.

Friday, June 1, 2007

Icecream Base

  • 1 cup full cream milk
  • 1 cup cream
  • 1/3 cup sugar
  • 2 whole eggs
  1. Whisk together eggs and sugar until well-combined and fluffy.
  2. Heat the milk until not-quite boiling, then stir into the egg and sugar.
  3. Stir the mixture over low heat until it thickens slightly (or coats the back of a spoon), custard style. I do this in a Pyrex bowl over a saucepan of boiling water.
  4. Refrigerate until cold, then stir in the cream.
  5. Place the mixture in your icecream maker and follow the manufacturer's instructions.
Depending on what you're adding to the mixture, add less milk and cream.

I like this recipe because it doesn't involve large amounts of egg. In my icecream maker, the end product is quite soft.

I often make this with whole 300mL cartons of milk and cream. The custard takes a little longer to thicken, but otherwise I haven't encountered any problems with it.

This recipe was inspired by the proportions at Think Quest, however I like to cook my eggs a little more than that recipe.

WoW Macros

These are mostly for my own benefit, in case I'm playing on my laptop and need my macros.

Get Ready
#showtooltip
/cast [modifier:ctrl] Conjure Water; [modifier:alt] conjure food; [modifier:shift] conjure mana emerald
/castsequence [nomodifier] reset=60 conjure water, conjure water, conjure mana emerald, conjure food, conjure food, evocation

This is a one-button food/water/gem macro. If you hold down ctrl while clicking it casts, if you hold down alt it casts food, with shift it casts mana emeralt (you'll want to change that if your spell is different).
If you don't hold down a modifier, it's a cast-sequence of water, water (makes 20), mana emerald, food, food (makes 20), and evocation. It will reset after a minute.

Mount
#showtooltip
/use [modifier:shift] Hearthstone; [modifier:alt] Swift Palomino; [flyable] Swift Red Gryphon; Swift Palomino

This will cast my (epic) flying mount if I'm in a place I can use it (ie. Outland), otherwise it will cast my ground mount. If you hold down shift it will cast Hearthstone, and alt overrides to the horse.

Polymacro
#showtooltip
/focus [target=focus, noexists]
/focus [target=focus, dead]
/focus [modifier:shift]
/s Polymorphing >%f<! Watch for it!
/castrandom [target=focus] Polymorph: Pig, Polymorph

This will focus my current target if my focus is dead or doesn't exist or if I hold down shift while clicking. It then makes an announcement of what I'm doing, and polymorphs my focus.

Ice Block
#showtooltip
/me is now a block of ice! Watch for disgruntled mobs!
/cast Ice Block

I like to let people know when I do this because it will wipe my aggro. My paladin companion likes it when we're duoing instances because she knows she can shield herself and not worry about me.

THE EYE
/target eye
/cast Fire Blast

If you've ever done undead Stratholme, this is for you. Usually takes out the Eye in one shot.