I had to drop by RadioShack tonight to charge my Razr, since the battery was so low, I couldn’t even get it to stay on long enough to have my Mac recognize and start charging it.
While I was there I picked up a PiccoZ mini-IR Helicopter!
I’ve always wanted to fly a mini-RC helicopter (or a real one actually), so for a mere $29.95, this is an absolute no-brainer of a purchase. I got back to my hotel, ate dinner, then finally opened the package. A nice touch, the heli was already charged and I only needed to load batteries into the remote unit and turn on the *tiny* switch on the heli and I was ready to go flying.
I placed the heli on the bed and tried to get used to taking off. After many attempts, it’s best to just open the throttle quite crisply and wait for the little foam heli to stabilize.
Once in the air, the PiccoZ will start spinning. The instructions tell you to hit the trim buttons and this is effective in making the heli settle down.
It’s then surprisingly easy to nudge the tail around, and let the model drift around the room.
Landing is easy, just make sure there is a clear space below the heli and reduce the throttle slowly. The PiccoZ will drift down, and crisply reducing throttle at the last second will have it settle to the ground perfectly. Very very satisfying, and lots of fun.
See link below for pics of my one on the ‘helipad’, and flying around my room at the Hyatt.
PiccoZ Mini-IR Helicopter from RadioShack
How Do I: Fix Downloaded Pictures from a Motorola Razr
One minor problem with my Motorola Razr is that the filenames of downloaded images are munged into a somewhat stupid ‘DD-MM-YYY_xxxx.jpg’ format. And as dates are not preserved when I load the files across into my Mac, I wind up with a bunch of stupidly named and largely unsortable files.
Ok, this is a job for a command on UNIX (Mac OS X in this case) called AWK. AWK is one of the most venerable of the UNIX command-line utilities. Wikipedia has a page on AWK here.
The easiest way to describe AWK is that it allows you to apply a condition to a line of input, and to then ‘do something’ with lines of input that meet the condition, typically printing a new format, or building a command and piping to some other program.
The following piece of AWK applies all three of these common behaviors to do the following:
- Pick up a filename
- Ignore the filename if it does not start with two digits
- Reformat the filename into a simple ‘mv’ command
- Pipe the ‘mv’ command to a cshell
$ ls | awk 'substr($0,1,2)+0 > 0{print"mv "$0" 20"substr($0,7,2)"-"substr($0,4,2)"-"substr($0,1,2)"_"substr($0,10,4)".jpg"}' | csh
In this case, we transform ‘dd-mm-yy_xxxx.jpg’ to ‘mv dd-mm-yy_xxxx.jpg yyyy-mm-dd_xxxx.jpg’ and execute the commands in a csh.
The funny looking part at the start is the condition, which simply tests that substr($0,1,2) added to 0 is a number > 0.
Have fun with AWK.
Mactracker … All Macs, Past and Present!
I just got through playing with the fantastic Mactracker application. Mactracker covers the entire history of the Macintosh from Macintosh, through Mac Portable, the first PowerBooks (drool) and the latest Mac Pro and Intel-based Macs.
As well as full specifications, Mactracker includes beautiful icons, a picture and potted history’s of each model. For me the most special and fun aspect of Mactracker is the startup-chime button which plays the startup-chime for each model. Ahhh, I was able to relive the sound of hearing my old Performa 6100 reboot for the umpteenth time…
Mactracker is freeware but donations are encouraged.
As an additional note, the design and fit and finish of Mactracker are absolutely exceptional. It’s a great lesson in what makes the Mac UI great.
Highly recommended!
Adding Album Art to iTunes
I’ve been steadily adding art for all my albums to iTunes, and in the case of many of the oddball CDs that I own, the iTunes Store is completely stumped, or brings up bizarre garbage like ‘HP Invent’ gifs.
If anyone else owns the Grampian Television champion Banchory Strathspey and Reel Society’s Ceol na Fidhle with solos from Banchory’s very own Paul Anderson, here’s the WalMart link for the album art.
My copy of this album was bought at Borders in Sugar Land Texas, and made me homesick to the point of practically breaking down in tears at the time. I’m alright now, sniff. ;-)
iTunes Mac Happiness and PC Woes 1
All three iTunes machines in our house have now been updated to the new iTunes 7 with somewhat mixed results.
Summary
1. No installation problems
2. Slow performance until gapless playback scanning is complete
3. Coverflow makes iTunes much more album oriented
4. You can assign almost anything as artwork
5. iTunes 7 Mac still runs just great on a PowerPC G4 (Pentium III class)
6. iTunes 7 PC is a dog on Pentium 4 2 GigHz (Slow, skips when playing)
Installation
On my G4 Powerbook iTunes installed flawlessly and initially came straight up with no problems. After starting however, I kept seeing iTunes trying to scan my library to identify songs for gapless playback. During this scanning the machine was unresponsive, and because my 2437 song 23Gig music library is stored on a slow USB linked laptop drive, the process took a long time. Eventually, I gave up trying to use the machine and just left it to do its thing. Once this process completes, it should not bother you again.
Albums and Coverflow
The next issue was with my library. Because I have so many separate single songs, sessions etc., which end up grouped into one-song ‘albums’, the coverflow feature is rendered pointless. The remedy is to very carefully, go through the library and group songs where appropriate and assign artwork.
One of the most fun things with iTunes 7 is the coverflow feature. iTunes has a new view that shows a 3d sliding image of album covers which is utterly successful in recreating that feeling of flipping through a bunch of LPs looking for something cool to put on. The side effect of this is that since starting using iTunes 7, I’ve been listening to entire albums again. Of course, you better have a bunch of good albums!
Mac Good, PC Bad (iTunes)
Now to the bad news. On my wife’s Dell Pentium 4 PC, iTunes installed just fine, as on the Macs, but unlike the Macs, it just hasn’t settled down. It looks the same, but with any activity on the PC, or even clicking within the iTunes window, the song playing will start skipping and sometimes just won’t stop.
I tried increasing the buffer size, with no real positive effect. I also quit most of the other running processes such as skype, gotomypc, vnc etc., and no improvement.
Final Words
So in summary, I say there aren’t too many issue with the Mac version of iTunes, but you should give the upgrade very serious thought if you are running on a PC. We went from having iTunes 6 run flawlessly on the PC, to having the slow skippy iTunes 7.
Note that none of these criticisms apply to the Mac version which is still great, even on a G4 laptop.
Five Key Rules for Writing Efficient and Maintainable SQL
These five key rules have been distilled from several years working on complex commercial databases and help in writing queries that perform quickly, are easy to maintain, and need minimal debugging to provide correct results every time.
I concentrate on mainly on SELECT queries here, but the principles are applicable to the other SQL forms.
1. Write a comment with the primary or alternate keys when adding a table to a join
Be conscious of the most appropriate primary or alternate key when adding a table to a join. Write a comment such as /* PK Pipeline_No, Contract_No, Effective_Date_From, Amend_no */ when adding a table to a join. This lets people know that you have thought about join efficiency and gives confirmation that you have used the appropriate fields.
If you have a large join and there’s no suitable unique index, you might want to check if there should be.
Example - Join Dispensing Sheet to Doses to List Patients for a Hospital / Facility / Day
SELECT dose.patient_code, patient.given_name, dose.drug_type /* PK: hospital_code, facility_code, disp_date */ FROM DispensingSheets disp_sheet /* IX: hospital_code, facility_code, disp_date */ JOIN Doses doses ON disp_sheet.hospital_code = doses.hospital_code and disp_sheet.facility_code = dose.facility_code and disp_sheet.disp_date = dose.disp_date /* PK: hospital_code, patient_code, eff_date_from */ LEFT JOIN Patients patient ON disp_sheet.hospital_code = patients.hospital_code AND disp_sheet.patient_code = patients.patient_code AND disp_sheet.disp_date BETWEEN patient.eff_date_from AND patient.eff_date_to WHERE disp_sheet.hospital_code = '0001' and facility_code = 'pharmacy' and disp_date = to_date( '2006-09-03', 'YYYY-MM-DD' );
2. Always SELECT only the columns you need. Don’t ever use ‘*’.
Always SELECT only the columns you need in a query. If you are lazy and just use ‘*’ in a SELECT clause, it tells other programmers nothing about what you intend the query to return.
For example, look at the example above and consider the extra cost of building the data to return using ‘*’, compared with the few columns we actually need.
3. Use GROUP BY instead of DISTINCT
Most beginning SQL programmers use DISTINCT when they really mean GROUP BY. GROUP BY can be a pest if you are not really sure what you are selecting. However, if you are inserting to a table with a primary key (which should always be true), then the GROUP BY clause can be used to guarantee that you do not have duplicate values that will break the INSERT.
Example - Insert patients from another system
INSERT INTO PH_PATIENT_TABLE ( hospital_code, patient_code, eff_date_from, eff_date_to, given_name ) SELECT imp.hospital_code, imp.patient_code, imp.eff_date_from, MIN( imp.eff_date_to ), -- Use MIN/MAX to get one value to match the MIN( imp.given_name ) -- the GROUP BY. FROM PH_PATIENT_IMPORT imp /* Filter existing PK: hospital_code, patient_code, eff_date_from */ LEFT JOIN PH_PATIENT_TABLE patient ON imp.hospital_code = patient.hospital_code AND imp.patient_code = patient.patient_code AND imp.eff_dt_from = patient.eff_dt_from /* Don't try and insert existing records */ WHERE patient.patient_code IS NULL GROUP BY imp.hospital_code, imp.patient_code, imp.eff_date_from
If you need to insert other columns outside the GROUP BY columns that occur in the SELECT, then you can use MIN(), MAX() which pick the minimum or maximum values for columns outside the GROUP BY key.
In most cases, there won’t be multiple values for eff_date_to, or given_name, but we could use a CASE expression, or HAVING statement to check if there were multiple values in these fields.
4. Never SELECT and INSERT to the same table
If you have a large SELECT/INSERT then use a staging table to break the query into two stages. Many databases allow you to look at queries that block. Use these tools to confirm and justify the extra table.
The main exception to this rule is shown above, where we do a LEFT JOIN to avoid trying insert values in the table that are already present.
5. Look at the query plan as you write the query
If you follow the steps above then your queries should be very efficient. Trust, but use the query optimizer to verify this. As a side-benefit, the query optimizer will pick up any typos prior to starting to test the query.
If you see an expensive operation, try and work out why. Fix it.
Cool Way To Prevent Those Flaming Mac Power Connectors
My wife Meredith just came up with a great way to prevent problems with the power cable on her new MacBook. Here’s how:
![]()
This is really neat since it uses the clip that’s already on the cable. This should prevent much of the bending that can lead to fraying inside the cable.