December 02, 2009

MacBook Pro iSight camera fixed!

So I decided to sell in my Mac Mini and get a MacBook instead. I intended to buy a 17" MacBook Pro on my visit to Florida later this year. However about a week ago $2,500 + tax seemed steep for a machine I just wanted to use to browse the web and use iTunes on.... now I think I should have just bought a new one in Florida. Ah well, it's too late.

Anyway so I bought a second hand 17" MacBook Pro, model A1212 or MA611*/A. It's the one with a 2.33 GHz CPU, 2 GB RAM and a 160 GB HDD. It was in really good condition so I thought it was a good deal until I realised the iSight camera didn't work. At this point, I probably should have just given it back to the seller, but for various reasons I decided to keep hold of it.

I checked out the How to Troubleshoot iSight page on Apple's website to no avail. I thought it could be the connection between the iSight camera and the computer itself and so searching around the Internet brought me to a blog reporting a fix to my suspicion and a how-to on opening a MacBook Pro screen. They were both for different MacBooks, but gave me the inclining to have a go myself.

In the end it worked, so here's what I did. Essentially it involves the following three 'simple' steps:

  1. Unscrew MacBook Pro and remove screen.
  2. Open screen and re-connect iSight cable.
  3. Put everything back together and hope for the best.

Overall it took me about an hour.

Step 1

Basically unscrew every screw you can see. That includes all screws around the sides and underneath including the two screws that require a Torx T6 screwdriver under the memory compartment. So not to scratch my laptop I did this all on my bed. I would recommend doing this on an anti-static surface.

Once all the screws are out, the part with the keyboard and trackpad just pops off. Do it slowly though. The ribbon cable connecting the two pieces is easily removed by lifting the connector vertically off the motherboard. For better instructions on how to get this far, check-out the numerous hard disk upgrade how-tos elsewhere.

Second part of this step is removing the screen. For me, this is when my heart rate increased like I was disarming a bomb. Carefully unclip the cables between the motherboard and the screen by removing the tape holding them in place and using common sense on how these cables come out of the connectors. You may want to take the tape off in a way that you can re-use it later. Using the Torx screwdriver, remove the screws on each pair of hinge holds. On one of the pairs of hinge holds, remark the different screw used--i.e. the left most screw on the right pair of hinges is different, vice versa on the left pair of hinges, the right most screw is different.

Once you're complete you'll end up with a disaster like this:

Step 2

Opening the screen or actually the shell of the screen was the hardest part. I thought it couldn't be done at first and was ready for giving up until I really used to brute force. Check out the how-to I mentioned before on removing the shell. To quote them:

Once you get the two screws removed from the front of the bezel, you must remove the back plastic bezel. To do this, start from one of the bottom corners and slowly pry the back of the bezel off.

Once you get one corner free, move the other bottom corner and free that side from the laptop as well. Using your fingers, carefully pry the remaining bezel from the laptop.

The back plastic bezel is the aluminium backing plus the what seems to be plastic inner lip. Check out what part is coming away from what here:

Once you've got the bezel off, turn the screen so that it is face down and remove the black plastic cover over the PCB of the iSight camera.

I simply removed the cable the and re-inserted it and then held it into position with a little bit of tape. It really needs to be tidy as the bezel needs to fit well.

See that little black bit in the top circle to the the left of the connector? That simply dropped off so it couldn't have been important!

Step 3

Once ye done, sew 'er back up. Remember what I said about the two different screws on one of the the two pairs of hinges and make sure that all cables are connected and are tidy like they were before--you don't want to trap any wires!

Insert the battery/connect up the mains and switch her on. I'm not joking but the Apple start up chime was great to hear. Before trying PhotoBooth, I went to System Profiler and under USB High-Speed Bus, there it was, Built-in iSight!

October 26, 2009

iPhone 3GS slow after upgrading to OS 3.1

I had some time available yesterday so I wiped my iPhone before plugging it into iTunes and selecting "Set up as a new iPhone" option. It now appears to behave like new even with everything re-sync'd (albeit settings, game save positions/scores and text messages lost).

Ever since I upgraded my iPhone 3GS to OS 3.1, it behaved rather sluggish (even with the latest 3.1.2 installed). Wipping my finger across the screen to unlock the phone sometimes required various attempts before the GUI actually responded and the phone unlocked, writing on the keyboard was commonly delayed and I found I just had to type "blindly" for a few seconds before the keyboard responded and the text actually hit the screen. It was as if there was some resource-intensive background operations that the iPhone was carrying out every so often, and if I actually wanted to use the phone during this time, I had to endure sluggish operation until it completed (about 3-4 seconds later).

I thought the phone was at fault until I lost it and then with a brand-new replacement 3GS, using the "Restore from the backup of" option in iTunes, the behaviour was exactly the same.

So yesterday I used the Erase All Content and Settings option from the phone before plugging it back into iTunes and selecting the option Set up as a new iPhone. It now works perfectly again!

August 03, 2009

My Book Studio Edition II under Linux

If you're thinking of buying one of these external RAID drives for use under Linux then you may want to reconsider. I've have had a 1 TB (2 x 500 GB) Western Digital My Book Studio Edition II for a few months now and running it under Linux is simply difficult because of the its power management features. After around 10 minutes of inactivity the drives spin down. Under Windows and OS X, WD's Drive Manager software spins the discs back up and presumably ensures that the computer waits while doing so.

I've tried several work arounds including touching a file via a cron job every few minutes to no avail. These are the kernel messages I get when trying to read the file system after the drive has spun down:

kernel: sd 0:0:0:0: Device not ready: <6>: Current: sense key: Not Ready
kernel:     Additional sense: Logical unit not ready, initializing command required
kernel: end_request: I/O error, dev sdb, sector 12511
kernel: sd 0:0:0:0: Device not ready: <6>: Current: sense key: Not Ready
kernel:     Additional sense: Logical unit not ready, initializing command required
kernel: end_request: I/O error, dev sdb, sector 12527
kernel: journal_bmap: journal block not found at offset 12 on sdb1
kernel: Aborting journal on device sdb1.
kernel: sd 0:0:0:0: Device not ready: <6>: Current: sense key: Not Ready
kernel:     Additional sense: Logical unit not ready, initializing command required
kernel: end_request: I/O error, dev sdb, sector 12431
kernel: Buffer I/O error on device sdb1, logical block 1546
kernel: lost page write due to I/O error on sdb1
kernel: ext3_abort called.
kernel: EXT3-fs error (device sdb1): ext3_journal_start_sb: Detected aborted journal
kernel: Remounting filesystem read-only

Running ls for example produces the following error until the drive has spun up again. As the file system now may contain errors, it's re-mounted as read-only and I have to run fsck on it to ensure that it is clean (which it usually is).

ls: reading directory .: Input/output error

My current work-around is to re-define how I use the drive. Sounds silly, but I now have designated the drive a vault (kind of archive) that I only need to write to every few months and when I need something off it, by default mount it as read-only. I use a tool called scsi-spin (part of the scsitools package available in Debian) to spin the drive up before mounting. scsi-spin won't spin up a mounted drives so remember to unmount the drive after use and for some reason I always have to issue this command twice.

June 24, 2009

Export ODBC tables to CSV files

There's quite a few tools on the web for this, but for lack of trust (malware) and not having complete control I found it easier to write a script in Windows Scripting Host (WSH) instead.

The script was written to be invoked from the command line using cscript.exe and then with the following parameters; (1) ODBC DSN name; (2) table Name; and (3) output CSV name. You could quite easily update strDNS, strSQLTable, strFile though.

Option Explicit
Dim objConn, objRecordset
Dim objFileSystem, objFile
Dim intCount, intNoFields, strSQL
Dim strDSN, strSQLTable, strFile

Const ForReading = 1, ForWriting = 2

' get command line arguments
strDSN = WScript.Arguments.Item(0)
strSQLTable = WScript.Arguments.Item(1)
strFile = WScript.Arguments.Item(2)

' open odbc dsn connection
Set objConn = WScript.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=" & strDSN & ";Uid=myUsername;Pwd=;"
objConn.Open

' execute query
strSQL = "SELECT * FROM " & Trim(strSQLTable)
Set objRecordset = objConn.Execute(strSQL)

' open file for writing
Set objFileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile(strFile, ForWriting, True)

' loop through recordset
intNoFields = (objRecordset.Fields.Count-1)
objRecordset.MoveFirst
Do While Not objRecordset.EOF

   ' get number of fields (columns) within recordset and
   ' for each field output to file seperated by a tab,
   ' but skip nulls and don't add a tab if at last field.
   For intCount = 0 to intNoFields
       If IsNull(objRecordset.Fields.Item(intCount)) = False Then
           objFile.Write objRecordset.Fields.Item(intCount)
           If intCount <> intNoFields Then objFile.Write vbTab
       Else
           If intCount <> intNoFields Then objFile.Write vbTab
       end if
   Next
  
   ' write new line at end of each record and move onto next
   ' (nicely does it now)
   objFile.Write vbNewLine
   objRecordset.moveNext
Loop

' finish up
objFile.Close
Set objFile = Nothing
Set objFileSystem = Nothing   

objRecordset.Close
Set objRecordset = Nothing
objConn.Close
Set objConn = Nothing

As I wanted to have the script scheduled and the output zipped and placed onto a UNC path, I created the following Windows shell script. The script is actually a bit of an overkill but as I had already written it for something else and liked the logging and verbose output features used it again.

I've modified this script slightly for sake of simplification and posting on the web; I actually extracted a number of tables and captured these in additional phases (phase 2, phase 3, etc.). The current phase 2 (ZIP compression) was numbered after the last extract phase (e.g. phase 4). If you’re going to do the same, don’t forget to update the variables section to add multiple "set odbc_tableX=", etc. Good luck!
rem -----------------------------------------------
rem  determine current date and time
rem -----------------------------------------------

for /f "tokens=1-3 delims=-/. " %%a in ("%date%") do set XDate=%%c%%b%%a
for /f "tokens=1-3 delims=:. " %%a in ("%time%") do set XTime=%%a%%b%%c

rem Possible bug: Above only works if regional
rem settings are set to region that has either
rem has "-", "/", "." as the date seperator
rem and either ":" or "." as a time seperator
rem --which should cover all default regional
rem settings. Please update 'delims' above if
rem you have issues. To help test, uncomment
rem the following lines.
rem echo %XDate%%XTime%
rem goto end

rem -----------------------------------------------
rem  user variables
rem  (do not include trailing slash on path names!)
rem -----------------------------------------------

setlocal
set description=ODBC2TXT script

rem 7-zip location, destination dir and destination output
set zipprog_dir=C:\Program Files\7-Zip
set dest_dir=\\server\share
set dest_zip=extract_%Xdate%-%XTime%.zip

rem wsh script location
set script_dir=c:\odbc2txt
set wshscript=odbc2txt.vbs

rem odbc dns and SQL tables
set odbc_dsn=databasename
set odbc_table1=tablename

rem working dir and log file
set working_dir=%TEMP%\ODBC2TXT
set log_file=%working dir%\odbc2txt.log

rem -----------------------------------------------
rem  clean up working directory
rem -----------------------------------------------

rem create working folder if not already exists) and ensure
rem it is empty.
if not exist "%working_dir%" md "%working_dir%"
if exist "%working_dir%\*.*" del /f /q "%working_dir%\*.*"

rem -----------------------------------------------
rem  script header information
rem -----------------------------------------------

set message=%description%
echo %message%> "%log_file"

cls
echo *===============================================
echo %message%
echo *===============================================
echo.

set message=*** Script started. Processing...
echo %message%>>"%log_file"
echo %message%

rem -----------------------------------------------
rem  phase 1: extract table
rem -----------------------------------------------

:phase1
set message=*** Phase 1: Extracting table %odbc_table1%...
echo %message%>>"%log_file"
echo.
echo %message%

rem start WSH script with parameters
cscript.exe /Nologo "%script_dir%\%wshscript%" %odbc_dsn% %odbc_table1% "%working_dir%\%odbc_table1%.txt" >>"%log_file"
if not exist "%working_dir%\%odbc_table1%.txt" goto phase1_error

set message=DONE!
echo %message%>>"%log_file"
echo %message%

goto phase2

:phase1_error
set message=ERROR! File was not created. Script failed!
echo %message%>>"%log_file"
echo %message%

goto end

rem -----------------------------------------------
rem  phase 2: Compress and copy to outbound folder
rem -----------------------------------------------

:phase2
set message=*** Phase 2: Compressing extracts and copying to outbound folder...
echo %message%>>"%log_file"
echo.
echo %message%

"%zipprog_dir%\7za.exe" a -y -w"%working_dir%" "%working_dir%\archive.zip" "%working_dir%\*.txt" >>"%log_file"
if not exist "%working_dir%\archive.zip" goto phase3_error

rem copy zip file to given destination directory.
copy /y "%working_dir%\archive.zip" "%dest_dir%\%dest_zip%" >>"%log_file"
if errorlevel 1 goto phase3_error

set message=%dest_zip% created and copied to
echo %message%>>"%log_file"
echo %message%

set message=%dest_dir%
echo %message%>>"%log_file"
echo %message%

set message=DONE!
echo %message%>>"%log_file"
echo %message%

goto end

:phase2_error
set message=ERROR! Failed. Check log.
echo %message%>>"%log_file"
echo %message%

goto end

rem -----------------------------------------------
rem  Finish off
rem -----------------------------------------------

:end
set message=*** Script complete. Exiting...
echo %message%>>"%log_file"
echo.
echo %message%
echo.

endlocal
pause

March 26, 2009

cisvc.exe hogging my CPU!

I'm getting so fed of Windows XP at work. Maybe it's all the stuff they have to install, but besides it takes forever to boot, it sometimes becomes unusable for 1-2 minutes with the CPU at 100%.

So instead of phoning the helpless desk I decided to investigate. Opening Windows Task Manager and sorting by CPU under Processes showed me the offending process that was hogging the CPU. It was cisvc.exe and there's plenty of articles around on this. Anyway, I've just disabled the Indexing Service and the CPU usage instantly dropped back to normal.

We'll see what that means to me and my applications in the coming days.... in the mean-time I have my computer back. Watch this space!

http://msdn.microsoft.com/en-us/library/ms689718(VS.85).aspx
http://en.wikipedia.org/wiki/Windows_Indexing_Service

January 06, 2009

Excel Autofilter function not filtering all rows

I can't remember which template I'd used off the Office Online site, but had an issue whereby I couldn't autofilter the additional rows I'd entered. It was strange, I'd only added about 50 new rows, but they just weren't showing up in the autofilter drop down list. It was if the autofilter function was filtering by a set range.

Indeed it was. You can see the autofilter range at any time by pressing CTRL+G and then manually entering sheet1!_filterdatabase into the dialogue box.

To resolve the issue, turn off autofilter first and then select the new area you want to be included in the autofilter. Then re-enable autofilter and the new rows should now be included!