February 2004 Blog Posts
I needed to create a temp table in SQL with a column that contained an incrementing integer, without making that column an identity.
For example, suppose I want to select record from a table of users, but add a column that contains an incrementing counter. The data in the table should look like so:
| counter |
UserID |
Email |
... |
| 0 |
3432 |
BillBrasky@SNL.COM |
... |
| 1 |
7913 |
zoolander@howsmyhair.com |
... |
| 2 |
8372 |
donaldtrump@ImSoRich.com |
... |
| ... |
To start, I can run the following query to create the temp table:
SELECT counter = 0, * FROM Users INTO #tmp_Users
This creates a temp table named #tmp_USers where the column "counter" is set to 0 for each row.
In order to update the counter column so that each row has a counter value greater than the previous row, run the following statement.
DECLARE @counter int
SET @counter = 0
UPDATE #tmp_Users
SET @counter = counter = @counter + 1
If you’re looking to master your T-SQL Fu, I recommend this book. It provides a great reference for advanced T-SQL querying techniques. Keep in mind that this book is not for beginners. It gets into some deep analysis of how querying works in SQL 2005
Bush believes that an amendment is necessary to bring “clarity” to the issue of gay marriage and to preserve the social fabric of our great nation.
Praise Be The Lord! Well Ok Bush, I’m with you. But before we work on that amendment, there’s another Amendment we need to pass first. The Amendment to remove the scourge of Divorce from our country. It is necessary to preserve the social fabric. For it sayeth in the Gospel of Mathew chapter 19 verse 9 (King James Version):
And I say unto you, Whosoever shall put away his wife, except it be for fornication, and shall marry another, committeth adultery: and whoso marrieth her which is put away doth commit adultery.
For your homework, also look up Deut 22:19, Matt 5:32, 19:9, Mark 10:9-12, Luke 16:18, Rom 7:2, 1 Cor 7:10-11, 7:39.
Has anyone out there used any of these ASP.NET component packages (such as Infragistics or Component One? I’m looking for reviews.
We went on a triple date last night with Walt, Celine, Dan, and Judy to eat at Jiraffe. They are having some sort of Monday prefixe special. Unfortunately, a lot of French food has egg product in it to give it an added richness, which makes it difficult for my wife. I, on the other hand, had no problem with any of the food. Especially the Fois Gras. Very rich and tasty!
Just had lunch with Erik and Ben at Manpuku. If you’ve never been, Manpuku is on Sawtelle just north of Olympic in the strip mall where Hurry Curry is. If none of that made sense to you, then you probably don’t live in L.A. ;)
In any case, they had the bento boxes and I had an Ishiyaki Bibimpap. Rice with vegetables and ground beef, served in a steaming hot clay bowl with a red hot paste mixed in. Too good.
In any case, sounds like Ben and Erik are doing well at my former establishment of employment. Erik and his wife are expecting in two months. Not much has changed, we spent five minutes catching up on personal lives, and 55 minutes talking about Microsoft Reporting Services and the various code we're all writing.
I just left to do some thinking where I get my best thinking done. While washing my hands, I realized I should mention a few issues with my previous recommendation.
Adding the SerializableAttribute to a class indicates to .NET that the class may be automatically serialized via reflection. When the class is being serialized, .NET uses reflection to obtain the values of every private, protected, and public member. What this means for your exception class, is that any properties it exposes should themselves be serializable. Should .NET attempt to serialize your class, and your class contains a member that cannot be serialized, it will throw a SerializationException during run-time
Now, I’m not sure if this is the best design, but I often expand any object parameters to my custom exception constructors rather than storing a reference to the object. For example:
[Serializable]
public class MyException : ApplicationException
{
public readonly int ObjectID;
public readonly string ObjectName;
/// <summary>
/// Constructor stores the properties of sourceObject instead
/// of a reference to sourceObject itself.
/// </summary>
public MyException(string message, MyObject sourceObject)
{
ObjectID = sourceObject.ID;
ObjectName = sourceObject.Name;
}
}
This allows me not to have to worry about whether or not MyObject is serializable.
Another way to deal with this is to mark any members that are not serializable with the NonSerializedAttribute like so:
[Serializable]
public class MyException : ApplicationException
{
[NonSerialized]
private MyObject sourceObject;
/// <summary>
/// Constructor stores the properties of sourceObject instead
/// of a reference to sourceObject itself.
/// </summary> public MyException(string message, MyObject sourceObject)
{
this.sourceObject = sourceObject;
}
}
The .NET runtime will ignore any members with the NonSerialized attribute during serialization. After deserialization, the member will have its default value (null for reference types).
Finally, you can forego automatic serialization and provide your own serialization by having your class implement ISerializable If you do so, you must still mark your class as serializable with the SerializableAttribute
[Serializable]
public class MyException : ApplicationException
{
[NonSerialized]
private MyObject sourceObject;
/// <summary>
/// Constructor stores the properties of sourceObject instead
/// of a reference to sourceObject itself.
/// </summary> public MyException(string message, MyObject sourceObject)
{
this.sourceObject = sourceObject;
}
}
What do you think?
When writing a custom Exception class, don’t forget to mark the class as Serializable? Why? If the exception is ever used in a remoting context, exceptions on the server are serialized and remoted back to the client proxy. The proxy then throws the exception on the client. By default, .NET types are not serializable. But by adding a simple Serializable attribute decoration on your class, .NET is able to serialize your exception.
[Serializable]
public class MyException : Exception
{
// Custom Code
}
This is probably the funniest thing I’ve ever heard happening on a train:
Yesterday my mom and I went on a train ride that is often billed as being a way for couples to spend a special occassion. The train was full of couples celebrating anniversaries, birthdays and other special occassions. Quite a number of couples were making out openly at the end of the train ride whose main features are a picturesque dinner on the train and a stop with a tour of a local winery.
One of the less romantic aspects of this train ride is that for the most part you have to share a table with another couple facing them. this means they get to overhear your conversation and interrupt yours. The couple we shared our table with were celebrating the guy’s birthday and his girlfriend was treating him to a special day out that ended with the train ride. After we got back on the train from the winery tour the unexpected happened. They were engaged in conversation and he was comparing her favorably to ex-girlfriends, then all of a sudden he got down on one knee and pulled out a box with a ring in it. After a stunned silence she took it, said some words softly then said “I appreciate the sentiment but the timing is inappropriate” and handed it back. This was followed by her voicing her concerns about his ability to support them and him rattling of how much he made a month plus various bonuses, etc. I think it went downhill from there.
All through this I was staring out the window trying to make small talk with my mom but failing miserably. If and whenever I do end up proposing to someone I’ve definitely learned a thing or two about what not to do.
[Via Dare Obasanjo aka Carnage4Life]
Let's see. On Friday we went to see a sneak preview of Starsky and Hutch. If you liked Zoolander, I think you'll like this. It's not the same, but has similar type of humor. It's hard to approach Zoolander in my book, but Starksy and Hutch does well.
Saturday played a game of soccer in the cold rain. Had a stalwart crew of 10 people out there.
And on Sunday, slept in till noon, had lunch in Eagle Rock, and basically had a nice relaxing lazy day.
UPDATE: Whoops! I should have read the SLA for my free hosting provider more carefully. There’s a size limit to the files I may post on my ftp server. I will work to rectify this situation by finding a new FTP site. In the meantime, email me and I will send you the documents referenced below.
This is a work in progress. Pick up the Word doc here. Please make updates and changes with change tracking on and I’ll be sure to incorporate them into the master document.
Also, just for kicks, I generated MSDN style documentation of the RssBandit class library using NDoc. You can pick that up here
If the files are unavailable, let me know. Sometimes files get deleted if I go over my quota.
Wow. All this time, I̵ve tried to follow various
Asp.Net Forums, only now to discover that each forum is syndicated via RSS! Nice!
My latest task is to produce reports useful for fraud detection. We’ve recently had incidents in which users from Vietnam opened up several accounts via stolen credit cards, deposited money via Paypal, then commit a charge back.
I won’t go into details about the specifics of these reports, but they simply identify common patterns in fraudulent activity and alert us to the potential mischief.
Lately it seems that everybody is playing “six-degrees of separation” by sprouting a social networking service. Some of the most prominent are Friendster.com, Tribe.com, MySpace.com, and Google’s Orkut. The promise these services make is that by joining, you’ll be where all your friends are and in the process make new friends and business contacts, though in reality they tend to look like glorified dating services. Look around the blogosphere and you’ll find several opinions concerning the problems and weaknesses of these services. For example, Dare’s take on social networking services, Warren Ellis’s evaluation of Orkut, and Don Park’s suggestion for improving existing services. Robert Scoble, a popular blogger, points out in this blog entry, that none of these networks interoperate. A person ends up entering his data into each site over and over again.
A better model for social networking is the blogging community itself. Most blogs these days contain a list of other blogs called a blogroll. Typically a blogroll is a list of other blogs that the blogger finds interesting. Click on a link within a blogroll and you’re instantly transported to another blog with its own blogroll. Continue navigating blogrolls and you may cover the entire blogging community, or just end up with a headache and a strong desire never to hear about another person’s opinion of Janet Jackson’s Super Bowl boob.
These blogrolls create a de-facto network, though I hesitate to call it a “friendship” network as the social networking services do, but it is a network nonetheless. Many call the larger network of blogs, the “blogosphere”.
It wouldn’t be too difficult to create a software component that could index your blogging network and provide features similar to Friendster: “Haacked is in your network, would you like to kick him out?”, or “You have 13,237 bloggers in your network. You spend too much time online.” Perhaps this would be a web control hosted by a blog, or a new feature for an RSS aggregator.
Many of these blogs are hosted by some sort of blogging back-end software whether it is http://www.blogger.com, http://radio.userland.com/, or my personal favorite Subtext. With some of these tools, there are more powerful ways to establish networks than simply following links in a blogroll. For example, after reading a blog entry about the definition of a track back, I realized that social networking occurs both ways. Not only are the owners of the blogs you link to (and those they link to and so on and so on) members of your network, but those that link to you (referrals) and those that comment on your site and create trackbacks to your site are also members.
Trackbacks are particularly interesting in that they are a form of machine communication between your blog and the blog of another author. “Hi, I'm Haacked's blog. He recently wrote a post that referred to an entry in your blog and trashes you and your family. Here's the URL. Have a nice day!” This communication provides more information than a simple link. Not only does the recipient of this trackback know that I read her blog, but she also knows that I was motivated enough to refer to her site in a post on my own blog.
In such an exchange, your blog is acting as a software agent on your behalf. Think about that for a second. In Subtext for example, the simple act of posting a blog entry with a link to another person’s blog grants your blog permission to contact her blog (on your behalf) and communicate your acknowledgment of her blog entry.
Now imagine if the next generation of these blogging tools contained new features focused on this idea of a blog as social networking tool and personal agent. Your blog could have many capabilities to act as an agent on your behalf. It’s nice to know that your blog is looking out for you.
For example, you might give your blog several pieces of personal information and create some rules about who is allowed to gain access this information in sum or in part. Taking the concept of the blogroll one step further and creating various new “rolls”, a rule might be, “Anyone that is in my “close-friend-roll” may have access to all of this information. Anyone in my “colleague-roll” may have access to my business information. And anyone who trackbacks to me may have my email address.” Now, the next time I link to your blog entry, your blog might volunteer some information about your blog to my blog, at which point my blog may refuse or accept this information (depending on my preferences).
Taken further, blogs may move past being a simple journal of your everyday thoughts, but become your representative on the web. Tired of filling out your billing and shipping information every time you shop online? Add the selected merchant sites to your “secured-merchant-roll” and the next time you purchase something from Amazon.com, just give them your URL and let them get your billing and shipping information.
This rich communication between blogs would occur through XML standards built into the next generation of blogging software. The current crop of blogging tools already supports a variety of XML standards such as the MetaWeblog API, TrackBack API, Comment API, and Blogger API. Perhaps these new communication abilities would be built on top of these existing APIs or require new APIs altogether.
The beauty of this approach is the fact that these APIs are open and not proprietary. Not to beat a TLA to death, but this architecture is an example of Microsoft’s favorite TLA these days, SOA or Service Oriented Architecture. It doesn’t matter which platform your blog is implemented on. As long as it supports these various API’s and can make an http request, it can participate in this rich communication.
Yesterday Akumi, Laura, Judy, and I drove to Mountain High (not a reference to smoking out) for a day of snowboarding. This would be my second time snowboarding since the big Conversion from skiing. Right now, I would rate myself as an intermediate snowboarder and advanced intermediate skiier.
Mountain High is only a two hour drive away from Los Angeles, which makes it ideal for a day trip. The only problem is that it’s only two hours away, meaning anybody and everybody shows up. To start the day, we took a lift up the beginner hill to get warmed up, and the hill looked like the aftermath of a battle scene from Lord Of The Rings. I’m talking Pellenor fields here, with bodies strewn all over the place. The beginners hill is in reality an obstacle course that would test even Hillary Lindh (Alaskan reference).
In any case, we had a great day of boarding. Akumi and I even tried a few jumps, though she fared much better than I did. When approaching the jumps, I need to learn to stay on my front edge. Rather than a "Need For Speed", I have an intense "Fear Of Speed" when on a snowboard approaching a ramp. I’ll start my approach, gain some speed, and as I get close, start riding on my back edge where I feel very stable on the approach, but very unstable on the landing.
I welcome any snowboarding tips in my comments section.
What is the proper way to add three hours to a DateTime for the PST timezone? Is it this?
DateTime d = DateTime.Parse("Oct 26, 2003 12:00:00 AM");
d = d.AddHours(3.0);
A valiant attempt, but wrong. Instead try this:
DateTime d = DateTime.Parse("Oct 26, 2003 12:00:00 AM");
d = d.ToUniversalTime().AddHours(3.0).ToLocalTime();
// displays 10/26/2003 02:00:00 AM which is correct!
Console.WriteLine(d);
Why all the rigamarole of converting to universal time and back to local time? A little thing we like to call Daylight savings time. Without the conversion, adding three hours would have set the time to 3:00 AM which would be wrong.
Realizing this probably would have saved me from many hours of intense debugging sessions. I remember one particular case with a system of scripts and tools I set up to analyze the very large log files for a big client. It hummed along nicely until one fine spring day when it failed miserably. After an entire day of tracking down the source of the problem, I finally nailed it down to a script’s mishandling of Daylight Savings.
To find out more about proper DateTime handling, read the following article concerning best practices with manipulating date times.
I“ll be there! Microsoft Dev Days Event.
UPDATE: Was it worth it? It was not bad. But of course, not as good as the bigger conferences such as Mix, Tech-Ed, and the PDC.
That’s a question I’ve been asked several times, and to be honest, I really didn’t know all the details. Till now. Read on.
This site has several photographs and movies of NASA experiments where they pop water ballons in 0 gravity. They simulated the 0 gravity effect of being in outer space by flying an airplane in an elliptical orbit.
I just finished reading the Log4Net Introduction and FAQ and realize I've been missing out all these years. I won't retrofit my current App (just yet), but I definitely need to give Log4Net a try with future projects.
In particular, I like the hierarchical logging that it enables, both with log levels and with the equivalent of logging namespaces. For exampl, you can create a log named "Security" and another log with "Security.Access". If you set a log level on Security, the Security.Access will inherit that log level (unless you also specify a log level for it). Very cool.
Interesting news item I found
Reuters - An angry husband who came across a video of his wife having sex with her lover on the Internet called the police who arrested a man suspected of filming a string of people without their consent, police say.
[Via Yahoo! News - Oddly Enough]
Scott Hanselman asks the question Should one go to Production with a Debug build? Although I find that an intriguing question, I’m more intrigued by the fact that his company exclusively uses Log4Net exclusively.
In my current project, I am using the built in Tracing framework that is part of the System.Diagnostics namespace. It supports multiple logging levels and you can add custom Trace listeners. So my question is, what does a framework like Log4Net offer that the Tracing framework doesn’t?
Ok, I admit it. I’m a unit-tester-aholic. I’m compulsive about it. Sometimes going overboard:
string s = "hello world";
Assert.AreEqual(s, "hello world", "s changed. How about that?");
MbUnit is my friend. I feel a great sense of accomplishment when I can write a fully automated end to end unit test of an email Newsletter mailer. Previously, testing such an app required me to run the code, open up Outlook, check my email, and “uh huh, looks good.&8221; Now, by using a custom SMTP server class running on a separate thread (and on a custom port), my unit test can send a batch of emails and then ask the server if everything looks as its supposed to. “Aye aye. Everything checks out capt’n.”
However, there are certain cases that threaten to cure my obsessive compulsive behavior. For example, unit testing the pathological cases. Now ideally, these cases should happen infrequently enough that perhaps you can let them go. Sweep them under the carpet. Nobody has to know. Besides, who runs out of memory these days?
*raising hand* Well I did today. And I didn’t have a unit test for it. I could probably be forgiven for this one. I’m writing a Windows service that reads data into 10 DataSets. As each DataSet is read, I asynchronously open an SMTP connection and begin performing a mail-merge on that data set. I made sure to cap the number of concurrent connections to 10.
Now this app passed all my unit tests, but when I deployed it to the production server, it ran out of memory. After some analysis with a memory profiler, I discovered that I had violated Performance Rule #6, “90% of performance problems are designed in, not coded in.”
Each chunk of data I read in from the database is wrapped in a RecipientBundle class. The service then gives this class to an SmtpPool class which then schedules it to be sent on an available thread. The SmtpPool class keeps an ArrayList of the scheduled bundles to avoid sending duplicate bundles.
Hopefully you see the problem with this approach. I had a complete brain shutdown when I wrote the code to add the bundle to the ArrayList. Since the ArrayList is only used to avoid duplicate bundles, all that is necessary is to store the ID of the bundle. By adding the bundle, the ArrayList is holding a referenc to the bundle, thus making sure it never gets garbage collected until the entire mailing is complete. Bad move. These bundles should be generation 0 objects. Created, sent, garbage collected.
So in any case, I’m thinking about whether or not I should write a unit case for dealing with OutOfMemoryExceptions. There are a lot of difficulties in doing so. Typically, for a case like this, I will try to write a unit test that fakes it. I will talk about how I do that later.
I already have a unit test for dealing with the ThreadAbortException. That’s also a story for another time as there are several difficulties with deaing with the ThreadAbortException. For example, it doesn’t seem to get raised in my methods that are running asynchronously. They just seem to die without a whimper. Also, there’s a slight issue with the CLR such that the finally block isn’t guaranteed to execute.
Till next time
So I was off to a running start with my ambitious new goals of contributing to several open source projects and creating a blog worth reading. But as my wife so keenly pointed out, as soon as I get an inch better, I try to take it a yard.
You see, I've been going to Occupational Therapy and will soon get some Physical Therapy for my back and wrist problems related to RSI (Repetitive Stress Injury). Carpal Tunnel is a form of RSI, but it is not what I am afflicted with. I have ulnar neuritis with a dash of tendinitis and a sprinkle of cubital tunnel syndrom (carpal's lesser known cousin from the Bronx) thrown in.
After reading Dare Obasanjo's and Scott Watermasysk's blogs, I was inspired to contribute to their respective open source projects. I started out with a mad flurry of documentation writing for RssBandit without taking frequent enough breaks. I know, bad move. My back and wrists have flared up and I'm in a bit of pain.
To add to my misery, I've caught a bad cold. Yippee Kiyay! Anyways. I'm going to turn things down a notch, but will try to write something worth reading every so often.
So I keep blabbing and blabbing about my new RSS Feed. I keep imploring you to get an RSS aggregator and subscribe to my feed. What the hell am I talking about?!
Well to clear things up, I wrote an article about how to get started with RssBandit, a very nice RSS Aggregator created by Dare Obasanjo et all. Please take the time to read it and follow its instructions. Especially you Dad. If I've done well, the article will clear thing up and you will have a subscription to my blog.
You can also download it as a word doc
I thought this was a joke until I realized that it was on Yahoo news. Bush and Cheney say we attacked Iraq because Saddam COULD HAVE made weapons of mass destruction. "Could have". Gee, well North Korea "could have" made WMDs. Should we attack them? How about India who DO have. Heck, with a bit of time, I think I have enough intelligence and skill to make a WMD. Should I expect an airstrike on my apartment sometime soon? I hope not, my wife would not be pleased.
This turnaround is particularly amusing because didn't Bush and his cronies attempt to educate the country about the concept of "Imminent Threat". Saddam posed an "Imminent Threat". I don't know about you, but "Could Have" does not seem so immiment to me. It's like locking me up because I could have made a baseball bat and beat you down. Certainly I could, but it will take me time to find the right piece of oak.
washingtonpost.com - President Bush and Vice President Cheney yesterday said the war in Iraq was justified because Saddam Hussein could have made weapons of mass destruction.
[Via Yahoo! News - Top Stories]
My latest tech toy is an HP Scanjet 5530 Photosmart Scanner (wow that's a mouthful). The defining feature of this scanner is the photo feeder built in. Simply add a pile of photos (around 24 max at a time) into the feeder, press a button, and go watch your Tivo'd episode of 24 while your photos scan (it doesn't take all that long).
The incessant creaking of my bookshelf as it strains under the load of my accumulated photos spurred me to purchase this scanner. Having shuttled around the planet while growing up, it's important to me to archive the memories of the havoc I created.
To that end, I also spent a lot of time searching for the perfect photo organizational software. The ideal program would have a clean nice interface and allow me to tag photos, organize photos into albums, search with face and image recognition, and automatically fix bad hair-day pics. I ended up purchasing Adobe Photoshop Album 2.0, which I'm quite happy with, though it doesn't have image recognition (nobody really does just yet) and won't fix my bad hair (a lost cause).
However, this new memo from Microsoft Research
describes several advances that Microsoft is working on that will make their way into future products. Examples include image recognition, improved ability to fix red-eye and cut people from one photo and paste into another. One neat feature that currently works in Asian versions of Office 2003 can convert a picture of a person into a cartoon character with pretty good resemblance. Currently it only works for asian faces. I have to admit, I'm very excited.
Read about it here to see the examples.
Stephen Wolfram’s 1000 page tome, A New Kind Of Science, is fully online. http://www.wolframscience.com/nksonline/
- Specifications are for the weak and timid!
- This machine is a piece of GAGH! I need dual Pentium processors if I am to do battle with this code!
- You cannot really appreciate Dilbert unless you've read it in the original Klingon.
- Indentation?! -- I will show you how to indent when I indent your skull!
- What is this talk of 'release'? Klingons do not make software 'releases'. Our software 'escapes' leaving a bloody trail of designers and quality assurance people in its wake.
- Klingon function calls do not have 'parameters' -- they have 'arguments' -- and they ALWAYS WIN THEM.
- Debugging? Klingons do not debug. Our software does not coddle the weak.
- I have challenged the entire quality assurance team to a Bat-Leth contest. They will not concern us again.
- A TRUE Klingon Warrior does not comment his code!
- By filing this SPR you have challenged the honor of my family. Prepare to die!
- You question the worthiness of my code? I should kill you where you stand!
- Our users will know fear and cower before our software. Ship it! Ship it, and let them flee like the dogs they are!
I've never played Allegiance. I've never even heard of the game. But Microsoft is releasing the source code rather than abandoning the game. It's a large download, but an interesting look at the full source code for a game.
Download it here.
Oh my fucking lord...
Reuters - A Tennessee woman has filed a class action suit against Janet Jackson and others
involved in her breast-baring Super Bowl halftime show, saying millions of people are owed monetary
damages for exposure to lewd conduct.
[Via Yahoo! News - Oddly Enough]
My coworkers have been sending me some funny videos to get me caught up with pop-internet culture. Click on the "Humor" category to the left to see the latest funny videos. The Dave Chappelle one is especially worth watching.
It's a bit painful to watch. But you gotta love this kid's attitude.
WilliamHung.wmv.
So this kid has a dorky moment alone at school in a little studio where he films himself. Next thing you know, his friends upload the tape to Kazaa and this kid is everywhere! People all over the net are remixing the video. Here is the Original and a remix:
Matrix Agents Remix
A lot of the remixes don't work.
>Port knocking is a method of establishing extra security between a networked computer and the outside world. It seems like a great idea. For hosts that are running private services that need to be connected to the net, require clients to make a specific series of connection attempts to various ports. After the correct sequence is made, the firewall opens up the port for the client. This would be very difficult to uncover via a port scan.
I usually ignore the spam that I get (and I get a bunch), but I read one of them a bit more carefully:
We hereby inform you that your computer was scanned under the IP 194.90.37.141 . The contents of your computer were confiscated as an evidence, and you will be indicated.
Umm... I think that the author was probablyÂlooking forÂâ€inditedâ€.
[Via Eric Gunnerson's C# Compendium]
This is just too funny! It’s a skit about a white family with an unfortunate last name which sounds just like a terrible racial epiteth, “Niggar”.
Dave Chappelle is a master at getting a laugh out of race issues. He’s testing the boundaries of racial issues and finding laughs.
If you like this video, I suggest you check out Chappelle's Show - Season 1 on DVD. His most memorable skit is the one in which he plays Clayton Bigsby, a white supremacist who is both blind and black, only he doesn’t know he is black because no one ever told him.
Can somebody out there point me to a reference that explicitly says whether or not we can count on the underlying order of a DataTable rows to be the same order that is returned by a SQL statement or a Stored Procedure?
I read a posting somewhere where the author states that though it appears to be the case that the DataTable rows are ordered in the same order as retrieved from the database, that this ordering is not guaranteed by ADO.NET and should not be relied upon. For those familiar with hash tables, you know that a hashtable gives no guarantees about how elements are sorted.
Now I know all about the DataView class and how that can be used to have a sorted view of items in a DataTable. But my concern is this. Suppose the DataTable does respect ordering (for now) and thus my underlying data is already sorted. If the DataView uses traditional Quicksort to sort the data, that is the pathological worst case. Now there are new variants of quicksort that handle already sorted data just fine. I have yet to run benchmarks to find out how the DataView performs.
It’s amazing the fallout over the Janet Jackson breast incident.
My god people! It’s a breast!
It was on for three seconds!
We’ve all suckled on one when we were children (some even later) so I don’t buy the concern “think about the children!” Children see a breast on tv they think, “Hee Hee, a booby.” They don't think, “Oh! I saw a breast. My innocence has been stolen, I think I’ll go out and engage in promiscuous unprotected sex.” Show a kid the closeup they’ll probably think, “Oh! That’s gotta hurt!”
In any case, I think Chris Sells makes a good point here:
Severe Beating Shown, CBS Shocked/FCC Investigates
Or rather, that’s the headline I wish I could post. However, instead of CBS and the FCC getting freaked out about the insane amount of severe violence on TV, available to our children any time of the day or night, they’re worried about 3 seconds of breast.
Idiots.
This is why I always recommend
Spybot Search and Destroy.
A CNET News.com investigation finds that some "spyware killers" install the same type of programs they promise to erase.
[Via CNET News.com - Front Door]
Erik would like to point out that http://www.network-tools.com can also be used for url encoding. I still like my trick. It’s faster. However, network tools does have a nice collection of commonly used tools for the web or network programmer.
Quick, what's the hex code for question mark? How about the ampersand? Since, like me, you probably don't waste valuable space in your brain with that type of information, I have a little trick for you to quickly look up the hex encoding (or URLEncoding) for a character that doesn't require you building an ASP or ASP.NET page and calling Server.UrlEncode().
Go to Google and type the character in the search box and then click "Google Search". Now look in your address bar at the very end. Everything after the "q=" is the encoding of your character. For example, if I search on "?" I get:
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=%3F
Thus the hex encoding for ? is %3F.
I'm working with a third party component (I will not name the guilty party) that has a method with the following signature and implementation (with no overrides):
public void doSomething(DataTable table)
{
for(int i = 0; i < table.Rows.Count; i++)
{
DataRow row = table.Rows[i];
//Do Something with row...
}
}
What is the problem with this method?
In my opinion, it is an example of poor class design. Suppose the user of this class wanted to have the component process the rows of the DataTable in a particular order. How would one accomplish that?
If you take a look at the DataTable class members, you won't find a Sort() method. The reason is that a DataTable cannot be sorted. The correct way to sort a table is through a DataView. The DataView is simply a view (appropriately enough) of the underlying data within a DataTable. You can have multiple views on a single DataTable and sort and filter all you want on the views, but the underlying data does not change. For example, a naive approach (and one that I took) was to apply a sort on the DefaultView of the DataTable. I tried this before I knew the method's internal implementation. This approach failed due to the fact that the method completely ignores the view of the DataTable.
I would suggest that the method be changed to iterate over the DataTable's default view. That's what it is there for. However, the author may have decided to iterate over the DataTable for performance reasons. If so, a better design would have allowed for an override method that takes in a DataView and uses the view to iterate. Like so:
public void doSomething(DataView tableView)
{
for(int i = 0; i < tableView.Count; i++)
{
DataRowView row = tableView[i];
//Now Do Something with row...
}
}
This results in improved flexibilty for the user of the class. Thankfully, the author promised to include this in the next version of his component and send me a preview copy.
I am now running on Subtext, but my design remains a “developer made” design.
So what is up with this ugly new site? Basically it is one of those “Oh gawd, a developer is trying to design” designs. It is one of the default designs that comes with .TEXT a blogging back-end that I am now using. You’ll also notice that my URL is some funky long piece of work with "europe" in it. No, I haven’t moved to europe. My good man Erik pointed me towards free ASP.NET hosting with SQL Server access. I’m trying it out and hosting my blog here. As for the design,don’t worry, it is temporary. I have some underground monkeys working feverishly hard to produce a mind blowing, head splitting, taste bud exciting new design. Some new features to note:
- Notice the bright orange image link with the big "XML" on it? That links to my RSS feed. Finally! RSS. Now if I can just get you to subscribe to it...
- Posts are now arranged in categories. So if you could care less about .NET (i.e. family members, college buddies), you should bookmark the General category. Or better yet, subscribe to the General rss feed.
- Disagree with something I said? You’re a fool. But now you can expose your foolishness via comments! Please comment. Please.
Now that I have this in place, I will probably forego sleep in order to post content worth reading. Come back now, ya heard!