Thursday, December 23, 2010

Merry Christmas, Sauron!





Friday, December 3, 2010

Roamatherapy!

Ahh, Christmas, the time for presents, tasty food, and ruminating on the memories of days when Santa Claus really existed outside mere childhood imagination.

For the cheapskate who's always wanted to dabble in aromatherapy, and because "road aromatherapy" or "road rage smells like Christmas" didn't seem catchy enough, I present ROAMATHERAPY


TRY THIS

  1. Go to your local live Christmas Tree seller. This might be your local supermarket with trees and wreaths out front, or some guy selling these out of a tent along the roadside.

  2. Grab a discarded sprig of Douglas Fir. You also could ask nicely, but I doubt the seller would mind if it's already fallen away from the tree.

  3. Using Duck™ tape, a chip clip, or a convenient crevice between the vent and the dash, secure the sprig so that hot air from the vents wafts across it.

  4. Turn on your car's heater. Akin to the principles used by various aromatherapy diffusers, the pleasant aroma of the Douglas Fir is expressed from the plant material into your car's interior.

 

If your memories of Christmas are gloomy or nonexistent, hopefully this will bring you some of the Christmas cheer I associate with the holiday that is far more enjoyable than its rampant consumerism.


 

Thursday, December 2, 2010

String Concatenation and Implicit Conversions

I needed to modify a SQL function to strip some leading zeros in order to concatenate a string. Part of this process involved dealing with pluralization of the number of cents (I'm picky that way).


SELECT
 CASE
  WHEN CAST(CAST(CONVERT(decimal(18,6), 0.30) * 100 AS float) AS varchar(10)) = 1 THEN ''
  WHEN CAST(CAST(CONVERT(decimal(18,6), 0.30) * 100 AS float) AS varchar(10)) > 1 THEN 's' 
  ELSE ''
 END
 

The idea is that if the value (0.30 representing cents) translates into a number greater than 1, the resulting concatenated sentence will read something like "The discount is 30 cents." If the value equals 1, however, it would read "The discount is 1 cent."

When the above is executed, I get an error:

 Msg 245, Level 16, State 1, Line 1
 Conversion failed when converting the varchar value '0.03' to data type int.



At first this baffled me. Data type int?? I wasn't trying to obtain an integer value, I was ultimately trying to obtain a varchar for this string I'm building.

Then it hit me, SQL is performing an implicit conversion when it is comparing the value resulting from the conversion first to decimal, then float, and finally to varchar, with 1.

Lesson learned, when attempting to compare two varchar with numeric values, make sure that if the value being tested is decimal, that the static value being used to compare it against is also decimal.

I made the following changes and now it works flawlessly.


SELECT
 CASE
  WHEN CAST(CAST(CONVERT(decimal(18,6), 0.30) * 100 AS float) AS varchar(10)) = 1.0 THEN ''
  WHEN CAST(CAST(CONVERT(decimal(18,6), 0.30) * 100 AS float) AS varchar(10)) > 1.0 THEN 's' 
  ELSE ''
 END
 





Saturday, November 27, 2010

Pretty Formatting for XML or HTML

Sometimes it's helpful to pretty up XML or HTML in order to more easily analyze it. Many tools create machine-readable XML or HTML, which is well-suited to being parsed by computers, but whose formatting can be painful for a human to wade through. 

You might think, why do humans need to be able to work with machine-readable text, anyway? Well, if you happen to be the new guy on the job and get stuck with having to debug some code that spits out some XML or HTML you've never dealt with before for some complex data transformation processing, you can see why it might be necessary, particularly if something changes between the sender and receiver and the XML, as produced, no longer does the job.

In Notepad++, one of my favorite text editors, I can utilize the TextFX plugin to take a given chunk of XML or HTML and clean it up, neatly indenting the nodes and attributes for easier examination. I paste the text into the editor and select TextFX => TextFX HTML Tidy => TiDy clean document - wrap. Finally I select Language => XML or HTML to enable syntax highlighting.

Prior to discovering Notepad++, I had discovered the freeware MoreMotion XML Editor a few years ago when I was having to dissect some XML being output by a tool whose XML output I needed to clean up. Provided the XML was well-formed, I could very quickly pretty it up by clicking XML => Pretty Format, or even more easily with a quick key combo, Shift-Ctrl-P.

BEFORE: Messy, messy XML!


AFTER: Ahhh, clean, legible, structured XML.

Unfortunately, the original download URL for MoreMotion XML Editor appears to be defunct, leading to a parked page rather than the actual file. You can download MoreMotion's more comprehensive XML application suite here, but if you just need relatively simple XML editing provided by the older (and much smaller, around 1.3 MB) freeware tool, this working download link fits the bill. The ZIP file contains the EXE, which can be copied to a convenient folder and run.

A few caveats, however. MoreMotion seems to have a few editing issues with extremely long lines of text; you may notice keypresses on such lines may take a long time to register. Also, whereas Notepad++ will do its best to deal with poorly-formed XML or HTML and log any errors it encounters, MoreMotion will not allow you to proceed until the errors are resolved, and in my experience some of these errors can be difficult to pin down.

Nevertheless, for relatively small chunks of well-formed XML or HTML, MoreMotion XML Editor makes cleaning up XML or HTML just a few steps quicker than Notepad++.


Friday, November 26, 2010

Dell Latitude E6410 Sound Problems

The time came a few months back at my workplace to replace my venerable Dell Latitude D800 with something newer, better, faster. That replacement arrived in the form of the Dell Latitude E6410.


Dell Latitude E6410


Featuring an Intel Core i5 64-bit CPU, 8 GB of RAM, and Windows 7 Pro, I expected great things, and in many respects, I got them. Performance was leaps and bounds ahead of my old D800; tasks that my D800 plodded through like building and debugging an ASP.NET / C# website or searching through thousands of files in my local source repository proceeded many times more quickly. 


Unfortunately, I was dismayed to discover that the sound provided by the onboard IDT HD92xxx device, utilized by the NVIDIA NVS3100M video hardware, stuttered frequently. Whereas my old D800 never missed a beat, literally, even through the most challenging tasks, this brand-new, supposedly state-of-the-art machine couldn't play MP3 audio without hiccuping many times throughout any given track!

Apparently this is not an isolated issue. One thread on Dell's support forums described many users' similar issues with erratic sound. Various other posts online that I found blamed the IDT hardware, such as the first review listed for this related IDT product, followed by a couple of other reviews for same which immediately reminded me of good old Baghdad Bob...

"good, and very nice"

I decided to take a reverse shotgun approach, meaning rather than pump a few satisfying rounds of buckshot into my employer's laptop out of sheer aggravation, I'd run through a short list of steps based on research I'd done into the problem so far.

To visualize the problem, I downloaded and ran the DPC Latency Checker, which represented the stuttering issue in the form of the big, ugly red lines representing relatively huge latency leading to stuttering audio.


If I were typing the way the audio stutters, it miiiight look liiiike ttttthhhis.

Dell Latitude E6410 driver download page
on Dell's support site was my first stop. I downloaded the latest available drivers and installed them, including those for audio, video, chipset, and even the touchpad. Following the experiences related by others in the Dell support forum, I also updated to the latest BIOS.


Updating the BIOS, as described in the Dell support forum thread, helped things somewhat, but the stutter was still recurring intermittently. I also completely uninstalled Dell ControlPoint System Manager, which I noticed made the stutter markedly worse when active.

I also tried using PowerMizer Manager, a free utility which lets you control and, if desired, prevent your video adapter from downshifting performance based on demand, which can cause undesired latency.

Most recently, though, after installing the latest drivers supporting the NVS 3100M from NVidia's driver download site, I've found that the stutter has improved significantly. Now, the DPC utility shows that latency is overall much improved, but still the stutter occasionally rears its ugly head.


Definitely better than before.




In summary, here are some suggestions if audio stutters on your Dell Latitude E6410:




Thursday, November 4, 2010

A Thousand Words Isn't Enough

They say that "a picture is worth a thousand words". Personally, I think the value of photos is overrated.

No photo, digital or otherwise, carries the essence of the memories in real life that photo captures. As we travel down the river of time, our motion through it is like watching a film with the afterimages remaining in our trail behind us, kind of like light painting.

These "pictures" are one with the space-time continuum, and only someone with the ability to encapsulate this and peer inside could see the entire span of all these images across all time, somewhat like looking into a peephole from outside our realm of existence.

It is truly mind-boggling to think of the data storage requirements for that kind of recording, for every moment of motion of every iota of matter all across the universe for all time. If I were some Q-like being that could freely travel across time and make such observations and manipulations as an outsider, I'd probably go back to my physical life like a universe-scale photo album or video and play it back, in all aspects.

Alas, I don't have that power, but it's not like snapping a photo will do any better than my brain's comparatively feeble but nevertheless serviceable chronicle of my life. Whether a photo, a video, or the final, frantic firings of the synapses of my brain at death, "All those moments will be lost in time... like tears in rain."







Friday, October 22, 2010

Windows 7 Haunted Command Prompt??

I encountered a weird situation on my Windows 7 x64 machine where the command prompt window couldn't be closed.

I'd logged on to my domain account, and out of (admittedly bad) habit, I tried to right-click on the command prompt in the taskbar and close it. Usually, it goes away in moments, but this time it decided to hang around, and it was impossible to remove. 

I looked in Task Manager, and although I could see the instance of the command prompt in the Applications tab, and even right-click on it and choose Go To Process, when it shifted me to the Processes tab, it selected nothing, or if I'd clicked on any other process in the list, it prompted me to end that process rather than whatever process remained which maintained this errant command prompt.

I would've liked to use a utility like PSKill to terminate the process (as described here), but if I can't find the process ID, that isn't an option.

I did notice one thing unusual in the list of processes, there were three separate instances of an executable named conhost.exe (Console Window Host). When I selected the first instance and clicked End Process, the command prompt finally closed. 

 

I also ended the other two instances, as these don't normally hang out in my process list. I'm guessing that I might've thrown a monkey wrench into whatever this command prompt had been executing when I tried to close it, causing some process it might've been waiting to close to hang out in limbo.



Friday, October 15, 2010

Hammering A Stored Procedures vs Dynamic SQL Debate

While looking for differing viewpoints on stored procedures vs dynamic SQL, I discovered an article by Frans Bouma from a few years ago, wherein he passionately criticizes elements of a post by Rob Howard.

At the time of Bouma’s post I’d had some experience with Microsoft SQL 2000, but I was at a stage where I was doing the SQL equivalent of meatball surgery on databases rather than design. My tasks mainly involved adapting existing code to suit new or revised business logic. As a result, I can relate to aspects of where each person is coming from.

Bouma and Howard both make strong cases for their arguments. Howard, clearly in favor of stored procedures, maintains that a balanced approach should be taken to designing the data access layer to optimize data interchange, and cites stored procedures as an effective tool to abstract the data and improve efficiency and performance. Bouma, a dynamic SQL convert, strongly advocates that paradigm, favoring SQL code emitted by high-level objects to creating discrete stored procedures for specific data management tasks on the fly. He also cites some deep technical details specific to Microsoft SQL which he uses to question some of Howard’s suggested implementations of stored procedures.

At face value, each person argues strongly for their viewpoint, but whether stored procedures or dynamic SQL are in and of themselves superior depends on the design and implementation of whatever system will be hitting the database. As I read each person’s arguments I got the distinct impression that each is somewhat mired in the advantages of their preferred paradigm.

The gist of this argument from years ago can be summed up in each author’s words. Howard states, “Embedded SQL script is very brittle; small changes to the database can have severe impacts on the application.” Bouma says in response to one of the comments in his blog post, “True, it requires some work to get a dynamic query generator right, but once you have one, you don't have to recode it again.”

Both these statements ring true… under a given set of circumstances. If I need code to grab values from a static lookup table, which do I use? Probably either, since unless something major changes in the design, I won’t need to touch the query frequently to modify it. However, what if I need to do something more exotic, like process a payment or mine some data based on input variables that might differ from one query to the next? Again, either methodology could be used for these purposes. It depends I think on how effectively the tools are built to deal with the data, and whether they meet the needs of the design.

Quite frankly, it seemed to me that the authors were each getting too wrapped up in their respective favorites, and arguably from two extremes of the IT spectrum. Howard’s argument seemed somewhat less technical and more geared towards an executive’s ear, with buzzwords about efficiency and performance, whereas Bouma’s deep technical knowledge describes a quintessent engineer, quite eager to implement some project with the tools he is comfortable and happy with.

A hammer is great for driving nails into wood, and for yanking nails out of wood with its secondary nail-removing end. It’s streamlined and clearly purposed for its intended use. Would it be appropriate to use a hammer to spackle a hole in the wall, or break pieces of tile into neat square shapes?

Sure, you might manage to adapt the hammer to the task, using some duct tape to secure a credit card or other stiff piece of whatever to more effectively spackle, or try to direct the blows of the hammer to snap the tile into shape without shattering it.

Would it be efficient? Absolutely not.


Tuesday, October 12, 2010

Capture the Flag FAIL

Back in the days of Jedi Academy for the PC, I enjoyed playing capture the flag (CTF) games with a passion.

One game had me in pursuit of the enemy flag carrier, a guy named Skooby. As the screencap below shows, I loosed a blaster bolt at him just as he's inches away from capturing the flag.

The result...?!

Wednesday, September 29, 2010

Why You Need TeraCopy.

It's late, and you need to copy a bunch of files from one folder to another, one drive to another. Whatever the case, you select your folder, copy it (Ctrl-C is my favorite), then navigate to the destination and paste (Ctrl-V, here). 

Then begins the waiting game. 

Windows Explorer, in all its minimal uselessness

If you're copying thousands of files in thousands of folders, and the process stops somewhere along the way, you're stuck digging through all those files, all those nested folders, trying to find out where to resume.
 
Enter TeraCopy.

TeraCopy is without a doubt one of the best utilities I have ever used. It easily enables you to copy a large number of files and folders with the ability to verify whether the copy process completed successfully or not for each and every item in the list. Furthermore, it lets you retry any failed items individually or en masse.

TeraCopy can optionally show you the entire list of files as they're being copied.

Another feature I enjoy is that TeraCopy dynamically adjusts buffers while copying to speed up the copy process, making Windows Explorer crude in comparison. It even provides you with a live view of the data transfer speed in the title bar!

The thing I like most about TeraCopy, though, is that once installed it can completely replace Windows Explorer for all your file and folder copying needs. Given that I can copy and paste a huge number of files, and then be met, say, the next morning with a detailed report showing me details about any items that failed to copy, it really does help me sleep easier.