Archive for February, 2008

Multiline Search and Replace in Visual Studio

Tuesday, February 26th, 2008

Using this is a little weird. It’s basically a plain text to regex translator. A box will open and you paste your lines of code. Then click “Find”. It will convert the text into one long regular expression and then you click “Find” again. It has Find, Find in Files, and Replace. Could be very useful for refactoring.

I was cleaning my older VB .NET project some time ago. I just wanted to “refactor” some code to look more readable. All I needed was several replaces of multiline text. VS 2002, 2003 nor 2005 is unable to perform multiline search/replace. So I wrote a macro that can do it.

Multiline Search and Replace in Visual Studio

Last Night’s Dream

Tuesday, February 26th, 2008

This happened at the end of the night when I started to wake up. So, it’s unusually clear and I had no problem writing it down.

I was back in elementary school. As part of credit we were swapping part of the classes. College and elementary school for a short time. We would be treated like the kids and credit in class would count toward college. The teacher knew of our exchange program.

So, I found myself in an elementary class. Tiny desk, communal cafeteria, like Baker elementary.

With no shoes and a very inappropriate T-Shirt. The little boy next to me ran his own podcast. It was very cute.

I saw Dad there. He was a teacher. He hugged another teacher and went to teach a class. I thought he had a relationship with the other woman, not mom. I hoped he didn’t notice me, because I didn’t want that confrontation or risk of confrontation. We didn’t interact.

Colby Ezzell was there like in high school. But not in my class.

Update: Mediation Room

Sunday, February 24th, 2008

This weekend I painted the meditation room. The ceiling is done. Yay!

There’s a lot of work left to do. The windowsills have water/age damage. While cleaning them the paint/paper layer separated from the gypsum. Both have to be repaired. So far wood filler has been great for that, but I’m thinking of how to add ledges. Two to four inches for plants to sit on.

The blinds are getting replaced too. One window is 6 ft wide and the other is 3 ft. It’s hard to find blinds or shades that fit the large one. I like the idea of wood or faux wood 2″ wide blinds, but they don’t sell them that big at Lowe’s. And to be honest I don’t want another 6 ft blinds unit. It’s unwieldy and doesn’t work right. So, I thought I would get a pair of <3 ft blinds, using the center window frame as the divider.

The closets will match the hallway, because I have a whole bucket of that color left over and I like it. Still need something tough to paint the shoe holders. Maybe a dark color in high gloss.

Some things have gone pretty quickly. The taping around things for example. And this time I didn’t have to think about technique or read anything. The numerous wall patchings went pretty good.

The closets will seem like new. Which is good. They had 40 years of scuffs, nail holes, knicks, scratches, and staples. It would not take much to have them finished this week and even have the stuff moved back in. But I’m going to try installing the bamboo flooring in there. Or not. The floor heights wont match now that there are two layers of vinyl tile on the concrete. And with some quarter round you’ll never see my mistakes.

It’s time to really order the flooring. I noticed Lowe’s price in-store on Natural Horizontal Floating Bamboo flooring was $3-$4/sq ft. Similar to lumber liquidators and the sample piece looked just like mine. Getting the materials locally saves on shipping. Staci worked at a flooring store for a while and she said the important thing was to get underlayment that quiets your foot steps.

I like the look of bamboo, but it’s good for other reasons. Bamboo can group 60″ in 5 yr. Much faster than a tree. It’s really grass, so cutting it down is like giving you lawn a really deep haircut.

The wall color is unknown. I got 7 samples and they all sucked. Why does it take me 3 trips? They all looked like baby puke or baby shit or in one case a swimming pool. There more darker greens looked more promising. So, right now it seems like some form of green is the color.

I’ve been wanting a solid floor I could practice yoga on for 2-3 years. Carpet messes with your balance. One of my prereqs when looking for a house was solid floor.

The layout should be a bean bag in a corner for mediating when it strikes me, some kind of running/riding machines with a flat screen TV along a wall, yoga mat near the center of the room, plants in the windowsills, and some wall decorations. I can see most of this pretty easy. Bamboo flooring, wide white horizontal shades, pine windowsills, orange-yellow closets, green walls, and Anthem White ceilings.

Recent Discoveries

Friday, February 22nd, 2008

If You Want to Write: A Book about Art, Independence and Spirit
This book so speaks to the contemporary writer that it is nearly impossible to believe that it was originally published in 1938. In If You Want to Write, Brenda Ueland sets forth not just a philosophy about how to write or how to create, but also about how to live. Beginning writers will certainly be encouraged by Ueland’s words, but even the most experienced have much to glean from Ueland’s simple wisdom. “Everybody,” writes Ueland in the opening chapter, “is talented, original, and has something important to say.” Finding that something important involves embracing creative idleness (“the imagination needs moodling–long, inefficient, happy idling, dawdling and puttering”), freeing “what we really think, from what we think we ought to think,” and “thumb[ing] your nose at all know-it-alls, jeerers, critics, doubters.” One must think, she says, “of telling a story, not of writing it.” And when revising one’s writing, she advises, “do not try to think of better words, more gripping words…. It is not yet deeply enough imagined.” Finally, “whenever you find yourself writing a single word or phrase or page dutifully and with boredom, then leave it out…. If what you write bores you, it will bore other people.” And just because If You Want to Write is passionate, sincere, and even spiritual, do not think it is not also witty. One footnote bluntly declaims, “No doubt my terms would horrify a psychologist but I do not care at all.” Elsewhere Ueland titles a chapter “Why Women Who Do Too Much Housework Should Neglect It for Their Writing.” Amen, sister!
Amazon Review
Brenda Ueland
Brenda Ueland (October 24, 1891 – March 5, 1985) was a journalist, editor, freelance writer, and teacher of writing. She is best known for her book If You Want to Write: A Book about Art, Independence and Sprit
William Blake
William Blake (November 28, 1757 – August 12, 1827) was an English poet, painter, and printmaker. Largely unrecognised during his lifetime, Blake’s work is today considered seminal and significant in the history of both poetry and the visual arts.
The King of Kong
The King of Kong: A Fistful of Quarters is a documentary that follows Steve Wiebe as he tries to take the world high score for the arcade game Donkey Kong from reigning champion Billy Mitchell.

H: Multiline Search and Replace in Visual Studio

Friday, February 22nd, 2008

Using this is a little weird. It’s basically a plain text to regex translator. A box will open and you paste your lines of code. Then click “Find”. It will convert the text into one long regular expression and then you click “Find” again. It has Find, Find in Files, and Replace. Could be very useful for refactoring.

I was cleaning my older VB .NET project some time ago. I just wanted to “refactor” some code to look more readable. All I needed was several replaces of multiline text. VS 2002, 2003 nor 2005 is unable to perform multiline search/replace. So I wrote a macro that can do it.

Multiline Search and Replace in Visual Studio

HP: Say What You Will (Requiem for a TV News Career)

Thursday, February 21st, 2008

This is kind of long, but it’s good. Very hard to paraphrase/quote.


When I got into television, I did my best to bury my inner-revolutionary. For 16 years I’ve been a successful producer and manager of TV news, cranking out creative, occasionally daring content on good days and solid, no-frills material on the days in between. I’ve won several awards and for the most part can say that I’m proud of what I’ve done in the business, particularly since I never intended to get into it in the first place; by the time college was over, I was playing steadily in a band and fully believed sleeping on floors and subsisting on beer and Taco Bell to be an entirely noble endeavor.

Over the past several years though, something has changed. Drastically. And I’m not sure whether it’s me, or television news, or both.

That attitude began to change in April of 2006 — when I found out that I had a tumor the size of a pinball inside my head.

So I started a blog.

Ed, seeming to channel Bill Lumburgh from Office Space, informed me of that which I was already very well aware: that my name was “attached to some, uh, ‘opinionated’ blog posts” circulating around the internet. I casually admitted as much and was then informed of something I didn’t know: that I could be fired outright for this offense. 24 hours later, I was. During my final conversation with Ed Litvak and a representative from HR, they hammered home a single line in the CNN employee handbook which states that any writing done for a “non-CNN outlet” must be run through the network’s standards and practices department.


Say What You Will (Requiem for a TV News Career)

SN: Identical Twins Not As Identical As Believed

Thursday, February 21st, 2008


ScienceDaily (Feb. 20, 2008) — Contrary to our previous beliefs, identical twins are not genetically identical. This surprising finding may be of great significance for research on hereditary diseases and for the development of new diagnostic methods. How can it be that one identical twin might develop Parkinson’s disease, for instance, but not the other? Until now, the reasons have been sought in environmental factors. The current study complicates the picture.

Humans receive one chromosome from their mother and one from their father, providing for two copies of the genome. In some cases, bits of DNA are missing from a chromosome, leaving the offspring with just one copy of that bit of DNA. In other instances, mutations may produce three, four or more copies of a particular bit of DNA. In most cases, variation in the number of copies likely has no impact on health or development. But in others, it may be one factor in the likelihood of developing a disease.


Identical Twins Not As Identical As Believed

ClearType

Wednesday, February 20th, 2008

ClearType can really improve the appearance on text on the screen.

from IEBlog
HOW TO: Use ClearType to Enhance Screen Fonts in Windows XP

IE Developer Toolbar

Wednesday, February 20th, 2008

This has been really helpful. You can see the web page and the HTML that made it at the same time. There is a mode that highlights the HTML for any element that you click on.

Another very useful feature lets you select some controls on the page and do a View Source on just that part. This works even if various page elements got there from Include files. Normally, you can only do a View Source on the top page.

Internet Explorer Developer Toolbar
from IEBlog

How to Calculate the Character Width Accross Fonts and Points

Tuesday, February 19th, 2008

Ok, this is going to be long and technical. I’m writing it up for all the fools who, like me, have to figure how many pixels wide an Input field on a web page should be when the font and size are variable. Instead of letting the browser figure out the size.

This was a hideous problem to resolve, because it seems seductively simple at first. Just multiply a constant by the number of characters in a field. Give that a shot. The code I was replacing use 8 px/char on a Verdana 8pt. It doesn’t work. Short fields are too narrow and long fields are massively wider than necessary. And this strategy doesn’t account for other fonts the user can setup like Courier New for pt size from 6-18.

Each font has a unique character width. Each pt size has a unique character width.

My solution has a few parameters. The exact string is unknown. Font can be anything that the user can type and the system recognizes. Pt size again can be anything. Width is in pixels set on the Style attribute of an HTML Input tag rendered in Internet Explorer.

The system has a few defaults and I have a few favorites. So, I selected Arial, Consolas, Courier New, Georgia, Lucida Console, MS Sans Serif, Tahoma, Times New Roman, Trebuchet, and Verdana. On Point sizes ranging from 6-18, but preferably this is a function which can handle any Pt size.

Now, we see Windows, Word, and Internet Explorer solve this problem every day. The text box looks the “right” size. So, this problem has a good solution, because we see it and don’t even think about it. Perhaps the operation system will have an API or .Net call that will help us figure it our or do the calculation for us.

It does. And it’s called TEXTMETRIC In .Net 2.0 and earlier you have to reference GDI32.dll and call the API. .Net 3.0+ has a FormattedText class that seems to do exactly what we want. Unfortunately, this project is in .Net 2.0 and FormattedText is unavailable. There is yet one more way that will work in all the .Net versions. Make a Graphics object and use MeasureString to find the pixel width of a specific string.

So, lets take these one at a time. TextMetric can give you lots of information about a font. Of particular interest are MaxCharWidth and AveCharWidth. There are many ancillary measurements.

I ran a test program that would spit all of the Max and Ave(Average) character widths to a file. There is a large amount of variation here. For example, Arial 8pt has a Max of 29 and an Ave of 5. I thought I could make a functions that weighted the Max and Ave and generate a good result. This proved difficult and did not carry over to other fonts and other pt sizes. Each one would have to be guesstimated and the result might still need tweaking.

A lot of time was spent analyzing the differences between Pt sizes within one font. When you plot Max and Ave out, the graph is pretty close to a straight line. There’s some obvious rounding that causes a bit of stair stepping, but it’s not too bad.

What really sucked was the multiple characters. I had assumed that character width, on average, is constant. Yes, I know most of these are non-proportional fonts, but overall it should level out. Wrong!

This solution was not going to work. And analyzing the Max and Ave font sizes wasn’t revealing a formula that would handle any Pt size.

I did stumble upon an great Excel spreadsheet done by a college prof that will let you graphically perform a Least Squares Quadratic Analysis on a data set to determine a formula based on data only. This thing is awesome.

The code would be two layers of case statements. “What font, what Pt size, here is your function.” 10 Fonts X 12 Pt size = 120 possibilities plus a default. Ugly code. Ugly code isn’t like Ugly Betty or the Ugly Duckling. It never looks better.

The .Net 3.0+ solution with FormattedText looks great, but it can’t be considered and if this wasn’t fixed now it wasn’t going to be.

So, I rearranged my test program to use MeasureString. It spit out a comma separated file with all 10 fonts, 12 pt sizes, and string sizes from 1-79. The string was a ‘W’ at first, but became an ‘M’ after I read about em measurements. The graph I really needed was a 3d that showed the pt size and strings size, but I don’t know how to make one of these. And then give me a formula on the variables.

I do know how to calculate slope on a line and I can see that Pt size on the same number of characters is a line and not a parabola, sine wave, circle, etc. Dito with the number of characters on the same Pt size.

Slope is m = (y2-y1)/(x2-x1). (Didn’t think high school geometry was useful did you?). Slope represents the rate of change. If you know the Pt size and pixel width for 2 characters you can use slope to calculate the pixel width for 3 characters, just by knowing the Pt size. Since these are all lines the slope will be the same from 2 to 3 characters as 2 to 20 characters.

Lets look at Verdana 8pt. The Pt size is fixed and the number of characters are variable. The first pass of the formula works out thusly..

pixelWidth = fieldSize * mfor 8pt

Plug in the numbers from the spreadsheet generated by the test program to check the formula.

22.07639for 2 char = 2 * 9.26042

But, 2 * 9.26042 = 18.52084 and not 22.07639. Perhaps the formula needs some revision. Lets take the difference, 3.55555, and add it as a constant. The formula is now..

pixelWidth = fieldSize * mfor 8pt + 3.55555

Let’s jump up to a 10 character width and see if this still holds.

96.15971 = 10 * 9.26042 + 3.55555

96.15971 does not equal 96.15975, but it’s close enough. I think we found the formula for calculating the pixel width for Verdana 8pt.

Maybe, the m constant is not quite so constant. If we could get 1 formula for all Pt sizes instead of 18 of them that would really streamline the code.

Let’s get the formula for 7 pt. Here’s the data for 7 and 8 pt.

Verdana 7 pt

Num Char Width Slope (m)
1 11.21397  
2 19.31684 8.10287
10 84.13975 8.10287

Verdana 8 pt

Num Char Width Slope (m)
1 11.21397  
2 19.31684 9.26042
10 84.13975 9.26042

pixelWidth = fieldSize * mfor 7pt + 3.55555
19.31684 = 2 * 8.10287 + 3.55555

19.31684 does not equal 19.76129. The difference is .44445. A little checking against the other character sizes reveals the 3.55555 is variable on the Pt size of the font. For 7 pt it should be 3.11111. Actually, this constant calculates pretty easily to be pointSize * .44445 and this holds for all the fonts. I suspect that this constant varies on Character Set or Languages.

Lets plug this in and calculate on the 10 character data point.

84.13975 = 10 * 8.10287 + 3.11111

84.13975 is close enough to 84.13981. I think we have the new constants for Verdana 7 pt.

Is there a relationship between the change in the constants from 7 pt to 8 pt? We’ll start with a simple relationship. Calculate the slope of the slopes. This may not be true. The relationship could be a parabola or something else.

(9.26042 – 8.10287)/(8-7) = 1.15755/1 = 1.15755

You can quickly check this against the other point sizes for Verdana and see that 1.1575 is a good mfor all points. There’s a faster way to calculate mfor all points than comparing various point sizes on a font. I mean we have to do this 9 other times. There is a shortcut.

mfor all pt = mfor pointSize/pointSize

or to put it another way

mfor 8pt = 8.10287 + 1.15755 = 9.26042

for 8pt

1.15755 = 9.26042/8

So, it checks.

How does this relate to the existing pixelWidth formula?

pixelWidth = fieldSize * mfor 8pt + constant
where mfor pointSize = pointSize * 1.15755
and constant = pointSize * .44445

or the one formuala we have been looking for..

pixelWidth = (fieldSize * pointSize * 1.15755) + (pointSize * .44445)

The formula above holds for all the fonts. The constant, 1.15755, is unique for each font and actually varies by character. 1.15755 is based on ‘M’. ‘W’ will give a slightly higher constant.

The table below holds the constants for all 10 fonts. The formula is always..

pixelWidth = (fieldSize * pointSize * 1.15755) + (pointSize * .44445)

Font mfor pointSize
arial 1.14386667
consolas 0.7552125
courier new .82421875
georgia 1.2734375
lucida console 0.827475
microsoft sans serif 1.14388
tahoma 1.0579425
times new roman 1.2213575
trebuchet 0.9746
verdana 1.1575525

Here is the test program that generated the data in .Net 2.0 c#. Here is the best of the many, many datasets I generated. It’s a comma separated text file.

Sorry, I can’t list all the blind alleys I walked into. That’s a much longer and probably more useful article. There were 3 days of them.

Good luck with your project. Thanks to my friends for helping with a simple, elegant, one formula solution that fit all the parameters.

TD: Why Did A California Court Hide All Of WikiLeaks Over A Single Document

Tuesday, February 19th, 2008

A judge shut down a whole website due to one document. This is the equivalent of shutting down Ford all over the world, because of a lawsuit brought againest one car model. Me thinks this is excessive. Or someone in a robe got paid.

Why Did A California Court Hide All Of WikiLeaks Over A Single Document?
Over a year ago, we wrote about the Wikileaks project, designed to allow government and company officials to anonymously leak documents as a way of whistleblowing questionable activities. Apparently, it’s been quite successful at times. However, in doing so, it’s also building up a list of enemies, including one who has apparently convinced a California court to make the entire site disappear in the US. The Swiss banking group, Julius Baer, was upset by documents found on the site that they believe were posted by a former VP at the bank, alleging that the bank was involved in money laundering operations. Julius Baer’s lawyers claim that having these documents public could influence ongoing litigation in Switzerland (one assumes having to do with money laundering). While it’s understandable that the bank might not want those documents online, or that those documents might impact current litigation, that doesn’t explain why the California court ordered the entire site offline, demanded that its registrar block the transfer of the domain, force the registrar to point all visitors to a blank page and also having the registrar hand over all information on IP addresses of people who accessed the wikileaks site. All of that seems rather excessive, and of questionable legality.
..

HD DVD Discontinued

Tuesday, February 19th, 2008

It’s all Blu-Ray now. I know my brother got one of these, because the disks cost $30 compared with $40 for Blu-Ray. It sucks.

For customers yet to hop onto the HD express, this is good news because there’s no longer two competing standards to choose from. For customers who chose Blu-ray over HD DVD, then they can pat themselves on the back for backing the winning side.
Toshiba drops HD DVD

Housework Update

Tuesday, February 19th, 2008

This weekend I almost got the hallway done. The shoe molding is set, caulked, and painted again. The front door frame is painted. All the little areas around the door jambs are filled. The golden oak color is spot on in some places and quite noticeable in others. It’s better than the dull metallic dirtiness. There’s one more thing to paint. The walls where there trim meets the wall is still white with primer in most areas.

I began work on the mediation room by relocating everything to the living room, removing the faceplates, nails, screws, blinds, filling screw holes with putty, and taping the new outlets. I don’t think these closets have ever been painted. They are a non-glossy mustard yellow similar to the hallway; full of scuff marks, staples, and holes. The room seems to have been painted 2-3 times. Once with a light blue, then a strong red, then a strong blue. And somewhere in there is some wallpaper, at least 2 paint layers away from the top.

The closets will take an inordinate amount of time, just like the master bedroom. They need to be washed as good as possible. The floor trim needs to be pulled off the wall. The carpet has to come up, to find out what kind of floor is underneath. The sheetrock needs to be patched.

I can’t wait till this room is done. The hallway looks spectacular. The master bedroom looks very good. The meditation room is going to look spectacular too.

My painting takes a long time. Doing this room now will buy time to save money for the guest bathroom. And I wanted white walls to help pick the floor color. The current tan with blue bleed through shouldn’t affect the floor and wall colors I pick.

I’m looking for one unique item I haven’t found. Both closets have a shoe holder built in. I was thinking there might be a paint, like they use on pickup beds, to prevent scuffs and scrapes. And this paint, grey or black, could go on the shoe holders. Haven’t heard of this stuff, just spitballing that it’s out there.

Wood floor samples should come in this week. Yay!

This is what happens when my computers get frustrating and die (both of them!) and I can’t play a computer game. As much as I would love to drop into a Civ4 game, I get so much more done when I don’t play anything.

Charges Brought Against Bush and Cheney

Saturday, February 16th, 2008

What news story would you like to see in the news?

Former President Bush, former Vice President Cheney, and several former members of Mr Buch’s cabinet were brought up on various charge of bribery, war crimes, violations of various privacy laws, and even treason. The allegations have been made by several departmental employees working for the agencies charged with keeping US secrets secret.

Attorney General Sam Johnson stated with Friday’s charges, “No one is above the law. We believe that corruption has occurred at the highest levels of government. There is an overwhelming amount of evidence to support the charges. We are continuing to investigate the allegations and may bring further charges.”

Rep. Silvestre Reyese (D) Chairman of the House Intelligence Committee has confirmed that several government employees have testified privately in front of his committee on the condition of anonymity. Members of the NSA, CIA, and Pentagon have come forward to offer direct evidence to Congress in the form or emails, recorded phone conversations, and memos. Many allegations have been made over the years in tell-all books by former members of the White House.

Mr Bush is vacationing at his ranch in Crawford, TX and could not be reached for comment. Mr Cheney stated, “These allegations are groundless. They are the ravings of disgruntled employees and a vindictive Democrat party. Mr Bush and I were elected to run the country and we did so with the utmost integrity and honor. The Democrats are now choosing to revise history and besmirch our good names.”

Christopher-Staci Wedding Photos

Saturday, February 16th, 2008

Here are my photos of Christopher and Staci’s ceremony. The one below is my favorite. GMa, Mom, and Staci’s Mom also have pics. The only one without a camera was Madison.