Tech in a Galagzee, Not So Far Away.
Ville Walveranta
This user hasn't shared any biographical information
Posts by Ville Walveranta
Ternary beauty
Feb 8th
I love the ternary operator. It can often simplify a much more complex conditional into few characters. In PHP (and other c-like languages) it’s possible to do all sorts of things with the ternary. The following are examples from PHP.
If $b is true, print “true”, otherwise print “false”. Echo doesn’t work here.
| | | copy code | | ? |
| 1 | |
| 2 | $b ? print "true" : print "false"; |
| 3 |
Here’s something I learned today: it’s possible to assign a complex variable to an “internal” shorthand, and then in turn use the shorthand for the final assignment (based on the comparison). This way it’s not necessary to repeat the complex variable in the assignment section which makes the ternary much shorter and thus cleaner.
So instead of this:
| | | copy code | | ? |
| 1 | |
| 2 | $a = ($myObject->anotherObject->arr['somekey'] > 7 ? 7 : $myObject->anotherObject->arr['somekey']); |
| 3 |
You can do this:
| | | copy code | | ? |
| 1 | |
| 2 | $a = (($b = $myObject->arr['somekey']) > 7 ? 7 : $b); |
| 3 |
Awesome!!
How To Destroy Brand Confidence In One Hit
Jan 20th
Couple of a weeks ago the power supply of one of our PCs failed. The system is about one and half years old, so fine – sometimes things break. I replaced the power supply and the system was back up and running. The failed OCZ power supply was under warranty, and so I sent it in for replacement. The usual way: I pay the shipping in, they pay the shipping back.
The replacement – a reconditioned unit – arrived yesterday. First thing I noticed that the “WARRANTY VOID IF BROKEN OR REMOVED” sticker was, well, broken. Hm. So today I went ahead and installed it back into the original system, taking out the temporary PSU. I really hate replacing power supplies when the case is even slightly congested and this one was pretty tough to get to. Finally, the replacement PSU was in place and I hit the power button. Nothing!
Few moments of testing later I had determined that the unit OCZ sent as a replacement was DOA. I had to rip it out and put the temp PSU back in. Note to self: from now on the PSU replacement protocol will include stand-alone testing the new unit before I touch the target system.
I very much doubt the unit broke in transit; I’m guessing they either didn’t test it after repairs were completed, or for some reason the unit was never serviced and so I got someone else’s failed PSU in exchange to PSU I sent in for warranty service. The only way OCZ can salvage the situation at this point and avoid getting on my bad list is if they offer to pay shipping both ways. It’s not that much money, but the time wasted on this far exceeded what the replacement is worth.
Many companies forget that the value of warranty they offer not only comes from what they can advertise but also from the PR – positive or negative – depending how they handle warranty.
UPDATE 21 January 2010: Five Star Damage Control
OCZ handled the situation about the only way they could’ve handled it to minimize the negative impression that had already been created: they offered a free upgrade to a new product, or a pre-paid shipping label to return the DOA unit to service/exchange (apparently in case I had to keep the same model, such as a component for a tightly specified system). I chose the upgrade. Let’s hope the new unit works!
UPDATE 22 January 2010: Not so fast, my friend
More to come. Dealing with OCZ tech support turned out to be less than what the first impression promised.
Disabling reCAPTCHA extra function buttons from tab index using jQuery
Sep 30th
Here’s an easy way to disable the “Get a new challenge”, “Audio Challenge”, and “Help” buttons from reCAPTCHA display block using jQuery.
Simply add the following to $(document).ready(function() { … } on the page you have reCAPTCHA on:
| | | copy code | | ? |
| 1 | |
| 2 | $(document).ready(function() { |
| 3 | $("#recaptcha_reload_btn, #recaptcha_switch_audio_btn, #recaptcha_whatsthis_btn").attr("tabindex", -1); |
| 4 | }); |
| 5 |
Now when you tab out of the word entry field, the extra function buttons are skipped. This is a usability issue because if the extra buttons are left active in tab index, user can easily accidentally reload the challenge image when she thinks she is moving to the next item on the form (which is often the “submit” button), and then quickly hits Enter.
Explorations in the World of Linux
Sep 5th
I’ve been a FreeBSD admin for the past decade, and during this time have become quite familiar with the *BSD system. It has its quirks, but overall it’s very clean and easy to maintain.
From time to time – usually when I’ve been getting ready to upgrade to the next major revision of FreeBSD – I’ve taken some time to research what the current pros and cons are for FreeBSD vs. some Linux distro. Always, in the end, FreeBSD has won. However, a development project I’m starting to work on will utilize Zend Server, which is only supported on handful of common Linux distros and on Windows (which is, by default, not an option as I strongly maintain that Windows is not suitable as a web server platform). There is, of course, Linux compatibility layer in FreeBSD, but as Zend doesn’t currently support it as a platform for Zend Server, I wouldn’t feel comfortable using it in a production environment.
So even though I find FreeBSD superior to Linux in many ways, I’ve now spent some time getting acquainted with Linux. I first started with Red Hat, then moved to CentOS which is the Linux distribution I’m currently testing. Now it’s not bad, per se, but I frequently come back to the thought: “Why would someone, anyone prefer THIS over a BSD system?!” The package management with yum, rpm, and the GUI overlays is easy enough, but it’s chaotic! Having to enable and disable repos, set their priorities, etc. seems unnecessarily complicated. On the FreeBSD side there is the ports collection which provides most of the software that one can imagine ever needing. The odd few items that either aren’t available in ports, or whose configuration is somehow not complete enough through ports can be easily compiled from the source tarball. Everything’s quite easy to keep track of, and to duplicate if one’s building a new system.
I’m sure some of this feeling stems from the fact that I have been using a BSD system for so long, and from the fact that I probably don’t yet know Linux well enough (say, to build the system from a scratch..). But as far as I can tell, package management is done with yum and rpm (on CentOS, say), by adjusting repository priorities, and enabling/disabling repositories. That is messy!
Well, I now have a functional development server running Zend Server with Apache, Subversion, and MySQL, and as the vendor (Zend) dictates the rules, I must continue development on Linux. Perhaps in six months time I’ll have more favorable comments about it as compared to FreeBSD… but I sort of doubt it. My guess is I’ll just learn to live with it, every now and then wistfully glancing to the direction of the BSD server.
Something I didn’t know about KVM switches and Motherboard BIOS…
Sep 2nd
I recently installed Gigabyte GA-EP45T-UD3LR motherboard to a small LAN file server. It’s a decent, stable, inexpensive board. But what I didn’t realize is that if you want to use a shared USB keyboard and mouse with a Windows system, some BIOS options must be available and editable (assuming they’re not set “correctly” by default from the KVM switch’s point of view). This motherboard’s BIOS doesn’t have those options and apparently the BIOS defaults aren’t the right ones for this kind of use. The result: once USB keyboard and mouse have been switched away from the system with a KVM switch, they’ll never be reacquired by the system until the system is rebooted. Fortunately RDC works so that the console is not usually—or at least is very rarely—needed…
For reference, if you’re planning to use a Windows system with a KVM switch, make sure its BIOS has the following options:
- HALT ON ERROR: All but keyboard (usually in Standard CMOS settings)
- PnP OS: yes (usually in PnP/PCI settings)
- USB IRQ: enabled (usually in PnP/PCI settings)
Without these options set the only way to find out whether a specific motherboard will or will not work with a USB KVM switch, is to try. Gigabyte GA-EP45T-UD3LR does not.