Latest Entries »

Connect a MacBook Pro to HD TV

I purchased my MacBook Pro around March 2010 and because of this I was worried that it might not output audio over the mini display port (known issue for some models). If this is news to you have a read here. Anyway, turns out mine is fine, so here is how to do it.

First off, if you go to Apple -> About This Mac -> More Info -> System Report -> Audio (Built In) you should be able to see HDMI DisplayPort Output in the list. Check you have this before continuing.

To connect my MacBook Pro to my HD TV I am using a HDMI cable. As my MacBook Pro doesn’t have a HDMI port, I bought a Mini DisplayPort to HDMI adapter. Check out Apple Support as there are only a couple of adapters that will support the audio signal. I bought the Moshi Mini one off Ebay as well as a 3m HDMI cable.

  1. Connect the HDMI cable to the Mini Display Port to HDMI adapter
  2. Connect the Mini DisplayPort to HMDI adapter to your MacBook Pro Mini Display Port
  3. Connect the other end of the HDMI cable to an available HDMI port on your TV
  4. Turn on your TV and navigate to your AV Input selector (press AV button on remote control in my case), then select the HDMI port from step 3
  5. At this stage you should see your MacBook Pro display on the TV but there probably won’t be any audio
  6. On your MacBook Pro, navigate to System Preferences -> Hardware -> Sound
  7. Select the Output tab
  8. Select your HD TV from the device list (in my case Panasonic-TV)
  9. At this stage I still didn’t have any audio but hang in there
  10. Navigate to Applications -> Utilities -> Audio MIDI Setup
  11. Under Audio Devices, select HDMI
  12. Select the drop down arrow next to the configuration wheel at the bottom of this window
  13. Select Use this device for sound output (speaker symbol)
  14. Play some tunes and appreciate richness of sound through your TV speakers

I’m learning Puppet and Cobbler at the moment, and one problem I had recently was getting Puppet to automate OpenSSL self signed certificate generation. Scripting it just proved to be a little bit of a pain and so I’m hoping by posting my script here it might help someone faced with the same problem. First and foremost, I need to give big ups to this blog entry I found which mine is clearly based upon.

The following script has been tested on CentOS 6.2 with httpd and mod_ssl installed.

Note. The plain text password in this snippet is clearly not secure so you will want to harden it up for your purposes.

#!/bin/sh

echodo()
{
    echo "${@}"
	(${@})
}

yearmon()
{
    date '+%Y%m%d'
}

fqdn()
{
    (nslookup ${1} 2>&1 ¦¦ echo Name ${1}) \
	    ¦ tail -3 ¦ grep Name¦ sed -e 's,.*e:[ \t]*,,'
}

C=AU
ST=SA
L=Adelaide
O=codenes
OU=nes
HOST=${1:-`hostname`}
DATE=`yearmon`
CN=`fqdn $HOST`

csr="${HOST}.csr"
key="${HOST}.key"
cert="${HOST}.cert"

# Create the certificate signing request
openssl req -config /etc/pki/tls/openssl.cnf -new -passin pass:password -passout pass:password -out $csr <<EOF
${C}
${ST}
${L}
${O}
${OU}
${CN}
$USER@${CN}
.
.
EOF
echo ""

[ -f ${csr} ] && echodo openssl req -text -noout -in ${csr}
echo ""

# Create the Key
openssl rsa -in privkey.pem -passin pass:password -passout pass:password -out ${key}

# Create the Certificate
openssl x509 -in ${csr} -out ${cert} -req -signkey ${key} -days 1000

If you put this snippet in a file e.g. genSelfSignedCert.sh it’s just a matter of configuring Puppet to copy the script over to your destination machine and execute it.

iPhone 3G LCD Replacement

My iPhone 3G recently got some serious water damage (immersed completely in water) and I thought I killed it, but I managed to bring it back to life.

First off, it met with water while switched on and by the time I plucked it out the screen was flickering badly and I could see it was not in a good way. Anyway bad things happened and it became unresponsive. So I did some googling and it seemed the best solution at this point was to try to dry it out and not turn it back on until it was fully dried out. So I put it on a window sill in a container full of rice grains for 1 week in an upright position. During the week I rotated the phone to try and get all the water out.

After a week I turned it on and attempted to charge it. The screen was this greyish colour with sort of crazy lines and what looked like cloud formations on it. Being that the screen looked like this I was unable to use the phone. I thought maybe the screen artefacts were due to water still being in the phone so I dried it out for another week this time placing it on it’s back and later placing it on it’s front. At the end of this time the screen artefacts were gone but I was still left with nothing but a white screen.

A white screen is bad but my iPhone still basically worked. I discovered I could unlock it (the digitizer worked) and receive calls. I decided to open it up and check the connections inside. Note that opening your iPhone will void your warranty so proceed with caution. It is recommended that you open the iPhone up by removing the two screws at the bottom of the handset with a small phillips head and then use a suction cup to gently prise the glass screen up from the bottom part of the screen. You have to be careful because the glass screen and LCD are still attached to the motherboard by three cables at the other end. If you are going to attempt this then check out a YouTube clip that details the process, there are many to be found. I didn’t have a suction cup so I used a really thin instrument to prise the glass screen out. All of the connections looked fine but I reconnected 1 through to 3 just to be sure but it still resulted in a white screen.

I decided to have one final stab at fixing it by replacing the LCD screen. I purchased one off Ebay for $29.95 and it arrived within a couple of days. It came with a handy tool set including a suction cup.

Tools that you will need (if you don’t have them improvise):

  • New iPhone 3G compatible LCD screen
  • Razor blade
  • Thin plastic instrument/thin metal instrument/guitar pick
  • Suction cup

Instructions:

  1. Turn the iPhone off and remove your SIM.
  2. Remove the two screws at the base of the iPhone using a small phillips head and put them somewhere for safe keeping.
  3. Gently pull up the glass screen using a suction cup positioned at the base of the screen, just above the button – but do not attempt to pull the glass screen off completely. Alternatively, prise the glass screen up by inserting a thin instrument in the center of the bottom of the glass screen and leverage up.
  4. The glass screen should be connected to the motherboard by three connections labelled 1 through to 3. Gently remove each connection in order (1,2,3). I found that 1 and 2 came off easily, but 3 is clamped down with a small white piece of plastic so you need to flick the clamp up before pulling out the connection 3 ribbon. Once completed your iPhone should be in two major pieces.
  5. There are 5 screws to remove from the sides of the metal casing on the back of the glass screen, 2 on the left side and 3 on the right. You may need to remove some tape to expose the screws. These screws are smaller than the ones removed from step 2 so you won’t get them mixed up.
  6. Put the glass screen on a bench top such that the glass is touching the bench top and remove the final screw located at the top of the metal bracket (in proximity to the top right corner). At this point we are positioning ourselves to remove the LCD and it’s metal casing from the glass screen.
  7. The LCD is basically glued to the glass screen but it will come off if you do the following. Take a razor blade and use it to cut around the edges then use a thin instrument (preferably plastic) to start to pry the LCD and metal casing from the glass screen. You will probably damage the old LCD during this step which is OK since it is what we are replacing but be careful not to break the glass screen. I used a guitar pick to get between the glass screen and the old LCD. Once you have got something between them you can use the metal side rails to try and pull it up so long as you have removed enough of the adhesive with the razor blade.
  8. Once you have separated the old LCD and metal casing from the glass screen you should be able to slide it out, noting that there is a metal clip holding it in place at the top.
  9. Separate the old LCD from the metal casing. I found that I peeled the LCD off but it left this strip of reflective plastic on the casing which I had to peel off separately.
  10. Have a look at the old LCD and note that there is a right angle bend in the ribbon connector. Your new LCD will have a flat ribbon, so reproduce the bend in the ribbon on your new LCD carefully without damaging the ribbon.
  11. This step is important! You need to attach your new LCD to the metal casing. There are two pins in diagonal corners which you should use as a guide so that it fits together perfectly. But you also need to make sure your LCD is the correct way around. So get it right before you do it for real as once you have exposed the sticky side and they are stuck together it is very difficult to get them apart without damaging your new LCD.
  12. You should now peel off the protective plastic covering your LCD display. Try to avoid getting finger prints on it. Reinsert the new LCD and metal casing into the glass screen housing, sliding it under the metal clip to hold it in place.
  13. Replace the screw you removed in step 6.
  14. Replace the 5 screws you removed in step 5.
  15. You are ready to reconnect the two major pieces of the iPhone. Starting with connection 3, make sure the white plastic clamp is flicked up and gently insert the ribbon as far in as it will go and then clamp it down by pressing down on the clamp.
  16. Reconnect connections 2 and 1, making sure they are fully snapped into place.
  17. You now need to put the glass screen back in place, starting at the top end ensure the small tabs at this end are in position underneath the chrome border. Gently press the glass screen in place.
  18. Replace the 2 screws you removed in step 2.
  19. Reinsert your SIM and turn iPhone on.

After performing the above, I could finally see my iPhone display without any artefacts. However, I noticed immediately that the contrast of the new LCD was very poor, it was as if the LCD screen had a contrast setting up way too high. I looked for a contrast setting in my iPhone but discovered there is none. At the time I figured this was a consequence of fitting a cheap LCD screen but the bizarre thing was, about two weeks later I went to use my iPhone and the contrast issue was gone and it hasn’t returned since. My display is as new. I figure there was still some residual water damage that was affecting the contrast of the LCD screen when I initially fitted it that managed to resolve itself over time.

 

 

 

 

 

 

 

Surprisingly it is not straightforward to draw a circle in Google Earth. Googling led me to this KML Circle Generator web form which is currently not working. Submitting the form leads to “Go back and make sure you have entered the values we need”. So I found this alternative which does the trick.

Browse to Google Maps and paste the following URL into the “Google” search field:

http://www.nearby.org.uk/google/circle.kml.php?radius=5km&lat=-34.928622&long=138.599958&geomColor=ffffffff

Modify the URL with your own lat, lon, radius, units*, and geometry colour and press Enter. Google Maps displays your location as the center of a point radius.

* Supported units are kilometers, miles, meters, feet and km.

Fixed Circle in Google Maps

Fixed Circle in Google Maps

To view the circle in Google Earth paste the same URL into the URL address field of your browser and press enter. The file “circle.kml” is generated and downloaded by the browser. Browse to your download folder and open the KML file in Google Earth and wholah.

Fixed Circle in Google Earth

Fixed Circle in Google Earth

Android Helloworld

I’m just starting to look at writing Android apps for the first time and lets just say my Helloworld experience was not ideal. Things just didn’t exactly work first go and when it did work it would suddenly stop working, then start working again and so on (see Troubleshooting for details). Not all that inspiring when all you are trying to run is Helloworld!

Preconditions

Allow me to set the scene:

Platform: Mac OS X 10.6.5 (Snow Leopard)
IDE: Eclipse
Android SDK: 2.3

I’m using Eclipse because it would seem that it has better Android support than NetBeans currently (and comes recommended by http://developer.android.com) so let’s roll with that. Being a Java developer I already had Eclipse Java EE for Web Developers – Galileo (64-bit) on my machine so I am using that. Check http://developer.android.com/sdk/requirements.html to see if your version of Eclipse is compatible before proceeding.

Setup

I will try and gloss over the setup instructions for Android dev since you can find them in great detail online already. In brief:

  1. Download the Android SDK http://developer.android.com/sdk/index.html and extract (avoid white space in your path to SDK). Add/modify your PATH variable within .bash-profile (where <pathToAndroidSDK> is something like “yourInstallPath/android-sdk-mac_86″):
  2. export PATH=${PATH}:<pathToAndroidSDK>/platform-tools:<pathToAndroidSDK>/tools
  1. Install the ADP plug-in for Eclipse. In Eclipse go to Help –> Install New Software… –> Work with: https://dl-ssl.google.com/android/eclipse/ –> Press Enter. Check “Developer Tools” when it appears in the list and complete the install.
  2. Open Android SDK and AVD Manager (Note. This can also be done inside Eclipse Window –> Android SDK and AVD Manager) :
  3. $ cd <pathToAndroidSDK>/tools
    $ ./android
  4. In Android SDK and AVD Manager create a new virtual device. Mine had the following custom properties:
  5. Name: Android2.3
    Target: Android 2.3 - API Level 9
  6. Once your AVD has been successfully created, start Eclipse.
  7. In Eclipse, create a new Android project File –> New Project –> Android Project. Mine had the following custom properties:
  8. Project Name: AndroidHello
    Build Target: Android 2.3
    Application Name: Hello
    Package Name: com.codenes
    Create Activity: AndroidHello
    Min SDK Version: 9
  9. Expand the newly created project in the package explorer. Under the src directory you will find AndroidHello.java. We are going to modify this file ever so slightly to present the text “Hello, Android” on application startup. Modify this file to look like the following:
  10. Save your project. Let’s try and run it. Right click on your project in the package explorer and select Run As –> Android Application.
  11. You should see the emulator appear and your Eclipse console should print out some promising messages as it launches the emulator, uploads, installs and finally starts your app. I have to say that this whole process is pretty darn slow for my liking.
  12. The only notable thing at this point is the application doesn’t always start up automatically which was what I expected. It seems like it only does the first time it is loaded onto a new emulator as far as I can tell. I found that I had to hit the menu button subsequent times to launch it.
  13. Check out your app (in all it’s awesomeness) then navigate to the apps screen in the emulator to discover that it can also be launched through the icon “AndroidHello”.

Removing Your Application

  1. Start the Emulator if it is not already running.
  2. Open a terminal:
$ cd <pathToAndroidSDK>/platform-tools
$ ./adb shell
# cd data/app
# ls (to view all of the .apk apps installed on the emulator)
# rm <yourApp.apk>
# exit

Troubleshooting

  • Be careful specifying a SD card size when creating your Android Virtual Device. Initially I put some default value in this field and I was getting the following error in the Eclipse console (app killed almost immediately after startup):
  • Use LogCat to examine more meaningful error messages if you are having problems running your app. In Eclipse go to Window –> Show View –> Other –> Android –> LogCat. E.g. for the above problem with the SD card value I was seeing “Low Memory” messages in LogCat prior to processes being killed which led me to the problem.

I’m going to assume that you have already created a new SVN repository for your project in preparation for the import. As a headsup, I came into problems when I created a SVN repository with default folder structure (branches/tags/trunk) so if you encounter issues trying to import the dump file (step 6) you may need to remove your default folder structure from the SVN repository and try again.

Note. I would not attempt to import the CVS Repository from a production environment, work from a copy.

  1. Download cvs2svn (http://cvs2svn.tigris.org/) and untar the tarball cvs2svn-2.3.0.tar.gz.
  2. If you are on a Windows box, download and install Cygwin (http://Cygwin.com/setup.exe). Choose the following options during installation:
    - Install from the Internet
    - Choose install location E.g. C:\cygwin (all users)
    - Use IE5 Settings
    - Select Download Site: E.g. ftp://mirror.internode.on.net
    - Select the following packages: cvs, svn, cvs2svn, python, gnutls and rxvt (and any others you would like)
  3. Copy the extracted cvs2svn contents into your Cygwin user directory E.g. C:\cygwin\home\user\cvs2svn-2.3.0.
  4. Copy the “CVSROOT” folder and the module folder “yourProject” for your project from your CVS repository into a new folder “cvs” in your Cygwin user directory (C:\cygwin\home\user\cvs\).
  5. Run Cygwin and enter the following command *:
    $./cvs2svn-2.3.0/cvs2svn --dump-only --dumpfile ./cvs2svn.dump --fallback-encoding utf_8 ./cvs/
  6. Locate the svnadmin tool on the server hosting the SVN repository. It is now time to import the cvs2svn dump file into the SVN repository (where pathToDumpFile is the location of cvs2svn.dump generated in step 5).
    C:\Program Files\visualSVN Server\bin>svnadmin --parent-dir yourProject load pathToSVNRepository < pathToDumpFile
  7. Now is a good time to checkout the contents of the SVN repository (command line/TortoiseSVN) and check that everything is there as expected and the full history for your project is available.

* If the repository you are converting is huge and/or contains large binary files you may see “Memory Error” in the cvs2svn output which means it has fallen over. To easily fix this I suggest trimming the offending files out of the repository and repeating step 5. Note. the fallback encoding is optional, I found it was required when I converted my project due to the encoding of some commit comments.

Running Glassfish as a Service

Suitable for:

  • Glassfish Application Server V2.1
  • Windows XP

In a production environment we want Glassfish Application Server to be running with no users logged into the host machine (WinXP in this case). This post explains how to run Glassfish as a service which will automatically start up when the host machine is rebooted.

To create the service:

>sc create domain1 binPath= "C:\Sun\AppServer\lib\appservService.exe \"C:\Sun\AppServer\bin\asadmin.bat start-domain\" \"C:\Sun\AppServer\bin\asadmin.bat stop-domain\""

To check that the service has been successfully created right click on My Computer –> Manage –> Services and Applications -> Services. The service domain1 should appear in the list. Right click on the service –>Properties –> change the startup type to be Automatic and select Apply, then OK. The service should run as Local System (default).

If you need to remove the service, run the following command (make sure the Computer Management window is closed first):

sc delete domain1

Note. Glassfish can be controlled by the command line, through an IDE or as a service. It is not recommended to mix these approaches when stopping and starting the server.

Non-default Glassfish Admin Password

Recently I started noticing this irritating message (repeated multiple times) in my NetBeans Glassfish Application Server log. The message is triggered by Glassfish start up and on application deployment.

SEC5046: Audit: Authentication refused for [admin].
Web login failed: Login failed: javax.security.auth.login.LoginException: Failed file login for admin.

It annoys me because when I installed NetBeans, I specified my own admin password for Glassfish (instead of the default admin/adminadmin). Later when starting the Glassfish server through NetBeans, it prompts me for my password and I supply it yet stubbornly this message continues to appear in my log. What the hell NetBeans?

So I’ll admit I ignored it for a while.

Today, I fixed it. I simply went into the Glassfish admin console (http://localhost:4848) and changed the Administrator’s password to the one specified during NetBeans installation. I restarted Glassfish and what do you know the message is no more.

JAXB Binding Declarations

This is just a little post that comes about from my frustration in working with dates in Java. I say in Java, generally speaking, because it still bugs me that sometimes you end up with a java.util.Date object and sometimes with a java.util.Calendar and I constantly seem to have to convert between them to end up with the one that I actually want. To add to that in my GWT projects Calendar is not supported client side so I usually use Date which is not my preference.

Anyway, to end my little rant, the motivation for this post is actually javax.xml.datatype.XMLGregorianCalendar, all I could think of was not another one! I noticed in one of my web service projects that JAXB was binding <xsd:dateTime> to XMLGregorianCalendar when what I really wanted was a Calendar. I could have written a conversion method but that seemed stupid and I found a better solution in the form of JAXB binding declarations.

All you do is take your WSDL or XML schema and add the following annotation block below the <xsd:schema> element:

<xsd:schema

     targetNamespace="com.codenes"

     xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"

     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"

     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

     xmlns:xsd="http://www.w3.org/2001/XMLSchema"

     xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0">

     <xsd:annotation>

          <xsd:appinfo>

               <jaxb:globalBindings>

                    <jaxb:javaType name="java.util.Calendar" xmlType="xsd:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />

               </jaxb:globalBindings>

          </xsd:appinfo>

     </xsd:annotation>

     ...

Note. The JAXB namespace and version are specified as attributes of the <xsd:schema> element.

After modifying my WSDL as above in NetBeans I then just refreshed the web service and did a build, and the xjc (JAXB Binding Compiler) generates source with Calendar objects in place of the default XMLGregorianCalendar.

Just a short post to say that I recently had this problem – I needed to get my event web service pushing messages to my GWT server side code. But how to expose the GWT server side code like a web service? The solution I found was using the GwtRpcCommLayer library. Using this library you can expose your GWT server side methods to any Java application (Swing or command line) or in my case a Java web service. It’s very straightforward to use and there is an example Eclipse project which you can easily get up and running. For my purposes I then used the gwt-comet library to push the event messages from the GWT server side code (without polling) to my GWT client side code/browser for presentation. Very cool!