Suppress “affected rows” Output in MS SQL Server

June 22nd, 2007

It gets a little annoying when you’re writing a log in your SQL script, only to have it cluttered with (x row(s) affected) statements. These can be very easily disabled by using the following command:

SET NOCOUNT ON

JavaScript Fading Colors

June 18th, 2007

I’m sure many of you are aware of the JavaScript scripts floating around the internet allowing for fading colors on web pages. The ones that I have seen tend to not use a class-based approach. Tonight I embarked on creating a color-fading class using only JavaScript. It was important for me to write this as a class for two reasons: I’m a great fan of object-oriented development, as it allows you to really ‘hook’ into the application (for testing, API documentation, and more).

What turned out to be the biggest problem was the timing between color changes. Traditionally JavaScript (JS) uses it’s infamous window.setTimeout() command to allow you to call functions after a certain amount of time has passed. The drawback with that command is that you cannot use objects with it, for the following reasons:

  • If you pass in an object that depends on reference (i.e. you want to execute a class method for a certain instance of that class), it looses the reference, and most likely won’t find the method called.
  • If you run multiple iterations and pass in variables to the method or object you are executing within setTimeout, and the code has completed running prior to executing the call in setTimeout, the each iteration will use the last available values of your iteration; it does not remember the individual values of the parameters of each iteration.

So, very bad situation. And searching the web only complicated things more for me. There had to be a simple way to get around this. This got me to thinking about how I could retain instance- and iteration-specific values, and still be able to use setTimeout. I had used function wrappers before in non-JS projects, so I thought it just might work here as well.

What I did was write a wrapper class for the setTimeout function. Each call to the setTimeout function would create a new instance of my wrapper class, thus retaining all the relevant information that I passed in at the time it was being passed in! And what do you know, it worked!

I have attached the code here, for your criticisms, as well as suggestions. Feel free to make use of it, should you like. Please do drop me a line if you do decide to use it. Also, if you make any updates or changes, please email me your changed code, as per the licensing agreement.

To use it, simply add a tag to any object that can have a background-color, like so:

<p fade="#ff0000|20|1500">Self-fading example (on page load).</p>
<p fade="||">Self-fading defaults example (on page load).</p>
<p onclick="FOBC.fade_element(this, 30, 3000, '#ffff66');">Event-driven fade (i.e. on click).</p>
<p onclick="FOBC.fade_element(this);">Event-driven fade with defaults (i.e. on click).</p>

Click me for demo.

Download: fade.js
Include the file in your page header, like so: <script type=”text/javascript” src=”fade.js”></script>

Syntax is: fade=”[hex color]|[frames per second]|[duration in miliseconds]”.
To use the pre-set defaults, simply use the following: fade=”||”, however, fade=”" will not work.
The defaults are: fade=”#ffff66|30|3000″.
Using the previous syntax will fade all items on page-load.

To fade items on demand, use the following JS:
Syntax is: FOBC.fade_element([DOM object], [frames per second], [duration in miliseconds], [starting hex color], [target hex color]);.
To use the pre-set defaults, simply use the following: FOBC.fade_element(document.getElementById(”test”), null, null, null, null);.
Defaults are same as above.

[Updated August 16, 2007: Included click demo, and added code examples.]

[Updated August 24, 2007: improved click demo.]

[Update August 24, 2007:] I have discovered a bug that will break the rendering of the fading effect, and will have a fix for this in shortly: when clicking and dragging (speak: highlighting) text that has a fade event, the fade will stutter and then cease to fade entirely. This also occurs when high-lighting text with a fade event through double-clicking.

Creating a Baseline Development Environment - Problem Analisys

June 16th, 2007

Over the past few months I have been working on creating an optimum development environment for creating web applications in .NET. The current development environment is for creating web applications in PHP.

While the tools differ (.NET vs. PHP), the goal is still the same: creating web applications. Thus, you should be able to use the same development environment. Now, this will not hold water if you have a PHP environment that is highly specialized toward PHP development; the same goes for strongly .NET dependent environment set-ups.

My contention here is that your development environment should be set up according to the goal, and not the specific flavor of technology being implemented. This will allow for migration between different technologies without creating a huge upset in the way things are done. “What are you specifically getting at here?”, you ask me. Well, lets examine what a development environment entails.

Research
Ideas don’t just make themselves. A lot of thought, trial and error, and playing around goes into perfecting an idea and developing a use case and proof of concept. This includes database designs, code, integration of 3rd-party-tools, plug-ins, and so forth.

Documentation
Once your idea matures and you are able to show proof of concept and derive a use case from your research, it needs to be documented. Often documentation is a burden placed on developers or technical writers to satisfy process, and not necessity. I’m not talking about writing a doctorate on the work that needs to be implemented (code changes, functionality updates, new project design, application design, etc.). What I’m talking about here is the short and sweet documentation that is concise, demonstrative, and clear on how to implement the proposed items outlined in the document. You should be able to hand one portion of the documentation to any developer who should be able to create the desired end product without having to consult with the client. It needs to be that good! And at the same time you should be able to hand the other part of the documentation to the client, so as to give them a clear picture of exactly what the end product will do, what its specific parts are, how they interact, and how the client’s users will interact with them. Yes, it has to be that good. Only then will you achieve a useful product that your clients will be happy with.

Architecture
You will architect your products and applications based on the documentation, as well as your findings from your research. Architecting and documenting a web application design often go hand-in-hand and will require extensive revisioning of the documentation. Your application architecture needs to implement best practice designs wherever possible. If there aren’t any for your given situation, don’t hesitate to create best practices and publish them! Public scrutiny is your best advocate in creating high quality designs.

Development
The development stage of the product should not entail any unforeseen activities. Yes, you have developers, but they should not be trying to figure out problems as they are developing your applications. All problems, hurdles, and glitches should have been thought through in the documentation and architecture phases. At this point the development should follow the guidelines of the documentation, just as a cook follows a recipe.

Testing
While your situation may not allow for test-driven development, it is the best way to achieve your development goals with a minimum of bugs, and it also encourages use of best practices. Test-driven development means that you first develop a test class with various test methods that test each functionality of your application. Since you have thoroughly documented all functionality, you already know what you want to achieve; you write your test methods to test for the desired result by running the methods, classes, or functions of code in your application that correspond to that functionality. If the function fulfills those requirements without failing, you have achieved your goal, and your test is successful; if not, your test fails.
Like I said, not all environments will allow for this, and in the event you can’t or decide not to implement this, you always need to test your code during its development to ensure that you are meeting your goals. This testing should optimally include peers, so as to expose your code to their scrutiny. They will have feedback, certainly if there are errors, and more often than not even if your code runs fine. There is always room for improvement, and it is a great way to advance your programming skills.

Trial Phases
Once portions of the application are preview-ready they should be tried by the client. Never abandon your client during development. Keep them up-to-date at least on a semi-weekly basis, if not daily. Your client will never ever get the design specs exactly how they need to be in practice, so the trial of functionality will reveal any problems that actual implementation may hold. Keep your client in lock-step with your development, show them what’s going on, and even what is not working. Give them the opportunity to adjust the project. This is not necessarily scope creep, but more often corrective measures. We like to label this scope creep so that we can blame the client for missed deadlines. However, not all changes need too be implemented right away. Document any planned changes and add them as enhancements after the project is rolled out, or in another phase of development. Try to avoid adjusting your current documentation to much, as it will cause disruption in the development process, if many developers are working on many different parts, and have to rework a lot of their code. On the other hand, if extensive re-work is required it may be best to halt all development and iron out the details with the client, re-document, and then go from there.

Deployment
Once all trials have been performed satisfactory, the product needs to be deployed into the production environment. The deployment mechanism should have no impact on the development environment, and should not be part of, or depend on, your development environment. If at all possible, deployment should be automated, so as to avoid human error.

Maintenance
We all know that there will be updates and bug-fixes down the road, no matter how good we code an application. Maintaining bugs, and tracking errors should be done in a standardized way, regardless of technology. This means that your applications should inform you that the client is having problems. You should be aware, and maybe already have a patch available when the client comes to you with their issues.

Everything I outlined here is technology independent. It is a collection of procedures that can be adhered to regardless of the technologies being used. This means that you should be able to switch from PHP to .NET development in the same environment with no impact on your procedures, making the life of your management so much easier. Heck, it will make your life so much easier, too.

Now, this isn’t as easy as it sounds. We often have special tools to aid us with each of the above processes, like bug-tracking, project management, deployment, code versioning, and so on. Often these tools integrate with our development environments to make our lives (at the moment) easier.

This is the actual crux of my post: what tools can aid you with your processes, while remaining technology independent. I will post more on this as I work through it myself.

Renovation: the furniture has been moved!

June 11th, 2007

Well, to my delight WordPress 2.2 features enhanced Blogger import functionality, with which I have brought over all my previous posts (I discovered this after I had already manually copy/pasted all the posts, but nevertheless!).

Consider the furniture moved. Now, to re-decorate: I need to redesign my template. While the default WP theme will do for now, it’s not as slick as it could be.

We’re moving … well, renovating, really.

June 10th, 2007

I have been using Blogger as my blog engine since inception of this blog (obvious, right?). Well, I decided against upgrading to the new blogger beta, because it no longer allows me to host it, and the classic blogger functionality really is lacking. That being said, I have decided to move to WordPress, and will be converting my posts from Blogger to WordPress over the next few days. Not to mention a graphical redesign very soon.

… One Sick Bastard …

June 10th, 2007

Having been sick this past week with a serious case of a head-cold, you can imagine how antsy I am getting, being cooped up inside all week long, and all. I figured I’ll blog about my latest computer hardware disaster, that has had my Ubuntu 7.04 machine out of commission for the last 2 months.

It all started when I started experiencing random shutdowns, as if someone had just pulled th plug. At times I would literally have to wait 10 minutes for the power button to even turn the computer on again. Being the logical type I naturally deduced that it was the Power Supply. I figured that it had finally given up the ghost, after 2 years of 24/7/365 operation at 80% load. It probably had lost its edge (power supplies do experience a drop in wattage output over time).

So off I went to newegg.com to get something that would last a while: HIPER HPU-4S730-MS 730W. I know that usually modular PSUs are to be avoided, but this one turned out to b e excellent with its industrial-grade connectors.

Silly me. As if that would get rid of the gremlin that had invaded my computer… of course it was still randomly shutting off - no, not shutting down, just OFF … poof - after about 20 seconds. This would happen during boot, while I was in the BIOS, or just being idly waiting for me to insert a bootable floppy (I removed all the hard drives to eliminate any OS or HD hardware). Well, what else could it be, but the motherboard now? Right?

Having no obvious answer in mind (any other piece of defective hardware connected to the motherboard would prompt beep errors) I was at newegg.com in two clicks, buying this baby: ASUS A8N32-SLI Deluxe. Maybe this wasn’t going to be so bad after all, looks like I’ll get a whole new PC out of this when I’m done. (I didn’t want to spend too much money, so I wanted to keep my 939 AMD Athlon64 3500+, which meant I had to go with a 939 motherboard.)

Figured I would throw the gremlin out with my old motherboard. Boy, was I wrong.
Man, I was at my wits end. The only other thing that it could possibly be was the CPU. But the CPU doesn’t just shut a computer off if its bad. Well, I’ve heard of stranger things, so off I went to newegg.com, again: AMD Athlon 64 X2 4400+ Toledo.

Nothing could possibly go wrong now. And on top of it all, I now got myself a dual-core processor, which would help me multi-task the hell out of programming! :) muahaha… haha.

Having delusions of grandeur, I eagerly plopped in the new CPU … booting … loading OS … nice, I can get back to work! … PFFFT. Blackness. The gremlin was back! I couldn’t believe it. I requested an RMA, having tested all the hardware (memory, video, cdrom, floppy, harddrives, etc.) I made a call to ASUS tech support. After explaining the situation, and convincing them that my CPU was NOT overheating, they admitted it might be the motherboard and authorized an RMA for me.

10 days later I got the package with my now refurbished motherboard in the mail. Unfortunately I was heading to the otherside of the Globe that day for vacation in the Philippines. My computer would have to wait.

Coming back 3 weeks later, I looked forward to assembling my PC and being able to get back to work. The gremlin was still there. Someone must have soaked it in a lake of water, because this was one evil gremlin I could seem to shake: my computer STILL kept shutting off anywhere between 20 and 60 seconds after starting it up. I have tried various PSUs, video cards, memory sticks, removed all peripheral drives and PCI cards. All to no avail. The gremlin still had to be in the motherboard. So I called into ASUS again, and they admitted that it must be the motherboard. Sometimes this happens, they acknowledged, and gave me another RMA number.

I now have to send in my motherboard again (this coming Monday, since I was sick this last week) and hope for the best. My last resort is to go out and buy another motherboard, but I don’t want to waste the $170 I already put into the new ASUS.

Hoping for the best, your aspiring gremlin-slayer.

PS: if anyone has slain a gremlin of this nature in the past, please let me know what I’m overlooking here! ;-)

Update: as per Mista_Random’s comment, one of the best suggestions I’ve heard regarding this issue so far, I tried using a surrogate case (plugging in the case connectors from another case, while being connected to the PSU of the original case). Unfortunately it still is pulling the plug on itself after about a minute. Great suggestion, Mista, thanks! Too bad itdidn’t pan out. :(

Kevin Carmony’s Latest Article on GPLv3

June 7th, 2007

KC wrote an interesting article recently regarding the changes in the newly proposed GPLv3 license agreement. These changes would “slap” a new set of handcuffs on distributors, and could potentially inhibit the distribution of OpenSource software as we know it today, under GPLv2.
I have 2 points of criticism on KC’s post:

  1. I would like to see KC’s arguments brought before the FSF (Free Software Foundation).
  2. KC is only critical of the points he doesn’t approve of. I would like to see items that he thinks are improvements as well.

KC’s post does have the benefit that it is stirring up alot of discussion regarding this topic, and that in itself is awesome.

Also, as a side-note, some people are wondering if Linspire currently has any licensing agreement with Microsoft. The answer is, yes, they do (in order to support WMA and WMV playback out of the box; http://multimedia.cx/multimedia-api.txt).

Ubuntu 6.10 - Setting up a Wireless Network with D-Link WDA-1320

December 18th, 2006

The D-Link WDA-1320 is supported by Ubuntu 6.10 “Edgy Eft ” ‘out of the box’. This is great news, as so far there have been innumerable issues with wireless support in Linux. Let’s get right down to business:

  1. Get your Ubuntu installation CD and insert into the CDROM of the computer you will be installing the network card into.
  2. Go to a command prompt/terminal and type:
    sudo apt-get install linux-restricted-modules-`uname -r`
  3. This will install all the packages necessary for the system to ’see’ your new card.
  4. Close the terminal window.
  5. Open Synaptic Package Manager (System -> Administration -> Synaptic …).
  6. Click the Search button and look for “network manager”.
  7. Select the packages network-manager and network-manager-gnome to be installed.
  8. Click Apply to invoke the installation.
  9. After the installation completes close Synaptic.
  10. Now you will need to disable any wired networking cards (network manager tends to get confused easily if there are some still available). If you don’t have any wired network devices (ethn, where n is a number) skip ahead to step 13.
  11. Open the network connections (System -> Administration -> Networking) and uncheck any checked connections.
  12. Close the Networking window.
  13. Now power down the Ubuntu computer (turn it off).
  14. Open the case, install the card into an available PCI slot, and close everything back up again.
  15. Turn the computer back on again.
  16. You can now see the wireless networks in your area by clicking on the networking icon in the panel notification area. To connect to one, simply click on it.
  17. You may or may not need to provide security information to access that network.

Month of PHP Bugs

November 13th, 2006

Stefan Esser made a great suggestion: we should have a “Month of PHP Bugs”, highlighting a bug in PHP every day for a month.

I think this is a great idea. If for no other reason than to give novice programmers some good learning material. So far there hasn’t been much “active awareness” pushed by PHP (Zend, et al.) to communicate things that beginning programmers need to be aware of.

The drawback with this is that the programmers need to learn by trial and error (usually at the employer’s expense) and in the mean time make their applications vulnerable.

I would love it if there was a site dedicated to PHP security. Not just vulnerabilities as in bugs, but also in proper ways of coding secure applications, best practices, and such. I’ve always found php.net to be the best resource when looking up functionality and syntax. A lot of the issues and vulnerabilities that programmers need to know about are indeed “hidden” in the user contributions at the bottom of the pages, however, they are cumbersome to read through, and often include a slew of ideas, tips, tricks, warnings, and best practices thrown together.

Of course, the other side of the coin (playing devil’s advocate here) is that developers need to be on top of their game at all times. Meaning they need to educate themselves regularly about their chosen programming languages. This includes reading up on best practices, coding securely, and learning new tricks.

**SQUASH**

Here are some links on the topic to get you started:

Ubuntu 6.06 - Part 5:Amarok, the Media Player

May 10th, 2006

This post will cover the installation of Amarok, because in my experience it hasn’t been seemless. It is expected that you have the Universe and Multiverse repositories enabled in Synaptic.

  1. Open Synaptic, and click on the Sound & Video category.
  2. Check Amarok to be installed and click Apply.
  3. Once done, click the Advanced button.
  4. Search for xine.
  5. Mark the package libxine-extracodecs for installation and click Apply. It will automatically include its necessary dependancies.

You should now be able to listen to most audio formats, including streaming music.

Enjoy!