<CharlieDigital/> Programming, Politics, and uhh…pineapples

21Aug/07Off

Working With SQL Server Compact Edition 2005

Posted by Charles Chen

One interesting issue that I just solved involved how to specify the location of the database file for a SQL Server Compact Edition 2005 connection string in a .Net add-in for Microsoft Office.

You see, when the add-in starts, it sets the context directory as the user's documents directory, which of course, makes it impossible to enter a configuration string for the data source of the connection string.

It works fine if the directory is hard coded - which is what I did for testing purposes initially, but of course, when I switched over to XP64, this broke as on XP64, the program is installed to "Program Files (x86)".

The solution lies buried in Microsoft's SQL CE documentation: there's a note that you should use a special token with the connection string like so:

<connectionStrings>
	<add name="ClientDatabase" 
		connectionString="Data Source=|DataDirectory|\data-file.sdf"
		providerName="Microsoft.SqlServerCe.Client" />
</connectionStrings>

The token needs to be included exactly as entered "|DataDirectory|". So how is this token replaced? In the static constructor of my Connect class that was autogenerated by Visual Studio, I added the following code:

/// <summary>
/// Initializes the logging subsystem for the <see cref="Connect"/> class.
/// </summary>
static Connect() {
	string path = Assembly.GetExecutingAssembly().Location;
	path = path.Substring(0, path.LastIndexOf('\\'));
 

	// Set the DataDirectory for the SQL Server CE connection string.
	AppDomain domain = AppDomain.CurrentDomain;
	domain.SetData("DataDirectory", path);
}
Filed under: .Net, Dev, SQL Server No Comments
20Aug/07Off

Nerd Glee

Posted by Charles Chen

So this morning, a FedEx Express (redundant?) truck showed up at my front door promptly at 9:00 to deliver a little bundle of joy: a new workstation.


For as long as I've worked, I don't think I've ever received a new development machine from any of the companies I've worked for.  To cope with the invariably crappy, last gen machines that I've been assigned, I've always ended up buying my own.  I bought my own laptop after a few months suffering on an NT4 workstation with something like an 4 GB harddrive and only 100 MB were left for me to work with (this was in 2003, mind you).  I bought my own desktop (a screamer of a machine in its own right) after my laptop became too outdated to handle the resource hungry 2005 suite of software and servers from Microsoft.


The importance of good hardware can't be emphasized enough.  Fast hardware helps shorten compile times, helps shorten debugging cycles by offering better runtime performance, helps shorten development times by allowing for more installed tools (think ReSharper), and I think, in the big picture, help reduce developer stress and frustration.


As trivial a gesture as this may seem, for the first time, I feel appreciated and I feel like my employer takes my job and tasks seriously.  It's a truly special moment :-D It's as if he understands my pain (well, not so much mine since my machine is less than a year old (dual core @ 3.2GHz, 4GB RAM, 3x10K RPM HDs), but my pain in working with the rest of the team who are still on first gen. Centrino laptops with 4200RPM HDs).


I'll have to add some pictures later and some screenshots.  For now, I am beyond ecstatic that, finally, our entire team will be able to really be much, much more productive.  I can't say enough about our once CEO and now VP who really went the distance to make sure that we got some quality hardware.


Filed under: DevLife No Comments
17Aug/07Off

Interesting Find

Posted by Charles Chen

So this morning, I was contemplating signing up for Amazon Prime since the holiday shopping season is a mere three months away and because I just moved to a new house that's kind of out in the middle of nowhere.

In doing some research about the general satisfaction about the service, I came across an amazing find on the BusinessWeek website, of all places.

The article/post itself isn't so interesting or amazing in any sense, rather, it's the comments left by the readers that are amazing and utterly baffling.

Who would have thought that the readers of BusinessWeek are such giant retards who have no concept of how the Interwebs work?  Nay, who would have thought that they were so dense as to not have any concept of how customer service works?

As evidence, I present some of the comments to the article:

I had no idea that it would cost me 79 dollars to join the shipping club and would not have joined if I did. I don't order that much and don't care if it took longer.
I would like to cancel my membership and get a refund for that amount. The one purchase I made took longer then two day's anyway. It was not even paid for or shipped till 8 o2. I have not even receive any imformation about the club yet.
Than You
Donald TenEyck

Hey Donald, this is BusinessWeek, not the Amazon customer service page...get a clue!  I'm pretty sure that Jeff Bezos is not going to call you and apologize.

I have just received a charge on my Visa bill
for $79.00. I did not authorize this and will not
pay it. Please cancel "MY MEMBERSHIP" and I will expect confirmation from you immediately. I notice that I am not the only one that has unknowingly been charged. What a rip off. Please credit my account now. And then lose my email
address
Bonnie Smuffer

Is it really possible for people to be this dense and stupid and yet have access to the Internet?

And it goes on and on...the stupidity really reaches critical mass in this posting.  Of course, it's fully possible that it's just comment spam, but check out these two postings by "Jaques Laporte":

Hi AMAZON.COM
I have just received a charge on my Amex bill for $79.00.
>PRIME SHIPPING CLUB.
>Free Standard Shipping for eligible items shipped to P.O. boxes in the continental United States (excluding Alaska, Hawaii, and U.S. >territories, possessions and protectorates) and APO/FPO addresses with U.S. zip codes.
Note that I do not live in the continental USA.
I did not authorize this and will not pay it. AMEX will be notified.
Please cancel my so-called membership and refund me.
I don't want to spoil my relation with Amazon, but until total refund, YOU ARE NOT AUTHORIZED to bill directly my credit cards.
Take notice please that I currently have no payment methods in your system.
Best regards.
Jacques Laporte.

Posted by: Jacques Laporte at January 3, 2007 06:56 AM

And then:

I must confess that the refund was fast (2 days).
All's well that ends well.

Posted by: J. Laporte at January 5, 2007 12:38 PM

Amazing to think that there are such a large quantity of people with this level of stupidity...

Filed under: Rants No Comments
16Aug/07Off

Book Review: Framework Design Guidelines

Posted by Charles Chen

I originally came across a title Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries after perusing the documentation on the Subtext site.

For the most part, I had been following the guidelines outlined by Scott Bellware in his handy dandy style guide, but this text - FDG - takes it to another level and formalizes it in a way that it must be accepted by development teams since it was born from the source itself: the .NET Framework development teams.

I've reviewed it on Amazon, but here is the transcripted text:

I don't personally think that all developers will find this book useful. In fact, I have a feeling that some may find it highly useless and disruptive as it is abstract in a sense (one must apply the lessons to each library and scenario independently, taking into consideration many different aspects of usability and readability) and it does require some "retraining" of bad practices which have been long since ingrained due to years of usage.

But whether this book deserves a five star rating or a one star rating - whether this book is for you - can be answered by asking yourself the following question: are you obsessed with quality? Quality in the sense of creating a library that is:

- Easily reused by others, even first timers encountering the library or even first timers to .Net
- Well thought out with well designed classes
- Consistent within itself and consistent with the base libraries from Microsoft

The importance of the little things like naming classes, properties, methods, using one type of construct over another, using one type of accessor over another, etc. cannot be stressed enough in the overall picture of creating a library to a higher standard of quality, usability, and extensibility.

As Confucius is to have said:

"If names be not correct, language is not in accordance with the truth of things. If language be not in accordance with the truth of things, affairs cannot be carried on to success.

"When affairs cannot be carried on to success, proprieties and music do not flourish. When proprieties and music do not flourish, punishments will not be properly awarded. When punishments are not properly awarded, the people do not know how to move hand or foot.

"Therefore a superior man considers it necessary that the names he uses may be spoken appropriately, and also that what he speaks may be carried out appropriately. What the superior man requires is just that in his words there may be nothing incorrect."

As I wrote in an e-mail to my team, I think that digesting this book will lead to: higher quality public facing APIs for our customer development teams seeking to extend the functionality, increased readability and more consistency internally in our teams, increased usability and decreased maintenance costs for the support teams as well as new developers on our team, and of course, increased skill, knowledge, and competency as developers of each of the team members.

The title of this book is perhaps a bit misleading.  In reality, this book is applicable for anyone doing .Net development since it will lead to better quality code construction irregardless of whether you happen to be working on a "framework".  What I also like about the book is that the authors, architects, and various developers who worked on the .NET Framework admit error and inconsistency in some design and shows that this book is truly a work of the men in the trenches and intended for those of us who work on the front line of software development.

While the book does not delve into architecture or design, I think it still has value in enhancing the skill and mastery of any developer that takes the time to read it.  Definitely pick up this book if you are serious about becoming a better developer in the sense of being a more refined craftsman.

Filed under: Book Review, Dev No Comments
16Aug/07Off

Running Trac, Subversion, And Apache On Ports 80 And 443

Posted by Charles Chen

If you are proxying Subversion through Apache, chances are you are probably using a non-default port since Apache won't start if you configure it use port 80 and 443 for SSL if you have IIS installed.  IIS uses socket pooling which binds port 80 and 443 on all IPs -- even ones not use by IIS -- to IIS.

To disable this behavior, you need the httpcfg.exe utility.  For Windows Server 2003, this can be found in the SP1 32-bit Support Tools download.  For Windows XP, the utility is available as part of the SP2 Support Tools download.

You can find a good overview of how to use this tool at neowin.net.

Some tips:

  • I didn't have luck running net stop http /y alone; I had to stop IIS first by running net stop iisadmin.
  • Assuming you have two or more IPs, the key is that you are actually telling IIS which IPs are okay to bind to.  If you are proxying Apache over IIS, you are likely (or should) use SSL.  This means that you have to make sure that you explicitly force IIS to bind to 80 and 443 for a specific IP and leave the other IP available for Apache.
Filed under: Dev No Comments
14Aug/07Off

Random DevTools Entry: #014

Posted by Charles Chen

Okay, so this isn't strictly a development tool, but Gantt Project has a pretty nifty, free, project management application.

With GanttProject you can break down your project into a tree of tasks and assign human resources that have to work on each task. You can also establish dependencies between tasks, like "this task can't start until this one is finished". GanttProject renders your project using two charts: Gantt chart for tasks and resource load chart for resources. You may print your charts, generate PDF and HTML reports, exchange data with Microsoft(R) Project(TM) and spreadsheet applications.

The site also mentions a good point with regards to Project:

  • Good (and growing!) set of basic features. This set is enough for most people (remember that 80% of MSProject customers use 20% of it's numerous features)
  • Easy learning. You don't need thick manuals to start working with GanttProject. If you are familiar with the notion of tasks, assignments and dependencies, you'll become an expert in GanttProject in a couple of hours.

Check it out if you're in the market for a free, simple, task based project management.

Filed under: DevTools No Comments
14Aug/07Off

Normalizing And Denormalizing SharePoint Field Names

Posted by Charles Chen

Frequently, when working with Office, SharePoint, and SharePoint web services, it is necessary to convert between the "normalized" (hex escaped string) version of a field name.

To that end, I found a useful JavaScript tool for normalizing strings into SharePoint's "static name" format.

In .Net, we can simplify this using Regex and Uri.

    private static readonly Regex specialCharactersPattern
        = new Regex("[\\[*($%&)<>!?\\/\"{}\\s+-='@~`#\\\\:;^\\]]",
            RegexOptions.Compiled);
 

    private static readonly Regex encodedCharactersPattern
        = new Regex("_x00(\\d{2})_", RegexOptions.Compiled);

    /// <summary>
    /// Normalizes the name of the SharePoint property name.
    /// </summary>
    /// <param name="key">The "human readable" key/property name.</param>
    /// <returns>
    /// The string with hex representation in place of special ASCII
    /// characters.
    /// </returns>
    private static string NormalizeSharePointPropertyName(string key) {
        return specialCharactersPattern.Replace(key, ReplaceSpecialCharacter);
    }

    /// <summary>
    /// Custom match evaluator to replace special characters within the input
    /// string.
    /// </summary>
    /// <param name="match">The pattern match.</param>
    /// <returns>The formatted version of the string.</returns>
    private static string ReplaceSpecialCharacter(Match match) {
        string replacement = string.Format("_x00{0}_",
            Uri.HexEscape(match.Value[0]).TrimStart('%'));

        return replacement;
    }

    /// <summary>
    /// Denormalizes the name of the SharePoint property.
    /// </summary>
    /// <param name="key">The normalized key/property name (static name).</param>
    /// <returns>
    /// The denormalized form of the input string ("human readable"
    /// with hex patterns replaced).
    /// </returns>
    private static string DenormalizeSharePointPropertyName(string key) {
        return encodedCharactersPattern.Replace(key, DecodeSpecialCharacter);
    }

    /// <summary>
    /// Custom match evaluator to replace the hex characters with special characters.
    /// </summary>
    /// <param name="match">The pattern match.</param>
    /// <returns>The ASCII format of the special character encoded in hex.</returns>
    private static string DecodeSpecialCharacter(Match match) {
        int start = 0;

        string replacement =
            Convert.ToString(
                Uri.HexUnescape(Convert.ToString(match.Value[0]), ref start)
            );

        return replacement;
    }

Download the sample console project to test it out.

SharePointNormalizationConsole.zip (4.35 KB)

Filed under: .Net, Dev, SharePoint No Comments
9Aug/07Off

Commentary On Current Market Woes

Posted by Charles Chen

This is probably the most sensible an informative bit of commentary on the current market conditions (DOW -387):



I love how 90% of farkers don't understand exactly what the crisis is right now.


It's not the fact that the housing bubble "burst". People aren't jumping out of skyscrapers because their house value went down by 5%.


The vast majority of the problem is that the credit market for certain types of bonds has tightened up, to the point that it's almost not even trading at this point. To those that are newbies, the bond market is roughly 10x the size of the stock market in terms of dollar value. It is huge. Bonds get traded back and forth every day, and billions upon billions of dollars worth.


What happened is that mortgage-backed securities are farked up. During the housing boom, lenders would give mortgages to people, then they would package them up and then sell a whole shiatload of mortgages to things like pension funds, hedge funds, mutual funds, etc. The lenders like this because they reduce their risk, and the funds like it because it's a reliable source of income, at least mortgage-backed securities are. Well, it turns out that the lenders were selling the funds investment grade mortgages, when in fact they were more like junk bonds; the people who got these mortgages not only faked their income, but in reality could only afford these mortgages under the best of conditions. Now that short-term interest rates have spiked up, many people have defaulted on these loans. More importantly however, the price of the mortgage-backed securities drop because their price is in part related to how reliable they are as an investment.


Now, many hedge funds invest in MBSs on margin, which really screws them up, because all of a sudden they owe a huge amount of money on worthless securities. This is why 2 Bearn Sterns hedge funds got screwed over and a 3rd one is in question. It's like owning stock in a gold mining company with a certain reported amount of gold, and then finding out that there really is no gold. The price will plummet, and if you bought that stock on margin, you will get a margin call.


The same thing happened with the French hedge fund that this article is talking about. What is worse, however, is that if the markets aren't trading, you can't tell how much the stock is worth, so the French stopped trading the funds until it can get better clarity as to how much their fund is worth.


The submitter's headline is misleading because the govt isn't injecting $12 billion, it's $12 billion more than they usually inject. They are always buying and selling bonds to create liquidity. This is what they mean by the US or Euro governments injecting funds into the bond market. They are going around buying bonds to create an artifical market because regular traders aren't buying them anymore. They are buying these bonds to create liquidity, so that traders will have confidence they can buy and sell bonds again, and once the market recovers they will turn around and start selling them back to replenish their reserves.


This is the real danger here. This MBS contagion has spread throughout the world because every one around the world has invested in US MBSs. We have no idea how bad this contagion has spread, but if this MBS problem takes down funds around the world, and the credit market really tanks and there is a flight to quality, making things like MBS fall even further, it could literally evaporated trillions dollars of peoples investments around the world.


From poster tstoneman.

9Aug/07Off

I Hate Comcast

Posted by Charles Chen

Over the past 4 years, I've been both a Comcast and Cablevision subscriber.  When I moved recently, I was "forced" into subscribing to Comcast due to whatever stupid regulations are in place limiting competition.

Let me list all the ways in which Comcast blows:

  1. Their customer service reps. are completely clueless.  It took me five call to three different people to figure out a stupid promotion that they were running that required you to be a customer already.  But clearly, on the ad, the terms and conditions state that it's available to new and existing customers.
  2. Their sales reps. are retards or just fuckups.  So to ensure that I got the exact package I wanted, just before I hung up with the rep., I specifically went over each line item to ensure that I was getting what I wanted.  Yet when the installation tech showed up - a day early, but an hour late - he didn't bring the right box!  I looked at the box to see if there were component cables and as I suspected, there weren't.  So I state "Hmmm...this doesn't look like an HD box" to which he responds "Yeah, I figured you wanted an HD box (gestures to TV)...those fuckups in sales...".  I check the order and indeed, not only was I not signed up for the package that I wanted, I was not signed up for HD either.
  3. Their customer service sucks.  So my wife goes to the local field office to tell them that they messed up their order.  Instead of offering for a tech to come out for free to claim the box and install an HD box, they hand her a new box and ask her to return the old one by Saturday.  That's quality service for ya' right there.
  4. The service sucks ass.  This deserves several sub-points:
    1. The digital voice comes with a shitty modem that has led to noticeably slower Internet performance (i.e. loading pages, sending files, etc).  You have no choice but to use this shitty modem.
    2. The digital cable is very unstable...many of the digital channels consistently lose integrity (blockiness, screen blacks out).
    3. The HD selection sucks.
    4. The fastest cable internet option costs $53 per month and it's only 8mbps downstream (and something like 1.5mbps up).  Contrast this with Cablevisions Optimum Online with Boost which offers 30mbps down/5mbps up for $44.95+$14.95.  Ho-lee shit.  There is no comparison.  To make matters worse, Boost comes with:
      1. A static IP (OH SCHNAPS!!)
      2. TOS allows outbound HTTP traffic over port 80!
      3. TOS allows outbound SMTP traffic over port 25!
  5. Comcast is expensive.  The Digital Preferred, which you need to get ESPN HD, costs $74/mo.  Plus, on top of the cable cost, you have to pay an extra $5 for HD channels and rental fee for the HD box.  Cablevision?  HD is included in all of the packages.  Plus, you can get most of the HD channels with the Silver Package @ $68/mo.

So in conclusion, Comcast sucks.  Cablevision has service to the zip code, but not to the street address...so what can I do but suffer :-(

Filed under: Rants No Comments
6Aug/07Off

And I Thought My Setup Was Badass…

Posted by Charles Chen

Excessive? Maybe.


Badass? Most definitely.


Now I'd be way more impressed if those monitors were 30-inchers.