Twitter Updates

Thursday 29 January 2009

List of Hard Drive Cases

A list of ways of connecting external hard drives I wrote for some one a while ago:
[1] Icy Box Dual Disk £27 http://www.scan.co.uk/
[2] Icy Box Dual Disk with Gigabit NAS £100 http://www.scan.co.uk/ WikiSupport
[3] Icy box single drive £30 http://www.ebuyer.com/ http://www.scan.co.uk/
[4] Icy box single drive NAS £44 http://www.scan.co.uk
[5] Hard Drive Docks £22 http://www.scan.co.uk/
[6] Laptop 2.5" (2 platter 1/8 Height 9mm) sata £6 http://www.ebuyer.com/
[7] Laptop 2.5" (2 platter 1/8 Height 9mm) ide £6 http://www.ebuyer.com/
[8] No enclosure Any drive Dongle £27 http://www.quietpc.com

Tuesday 27 January 2009

Mac OS X Java Switch case broken?

I think the java switch statment is broken on OS X java 1.6 try running this.
//case_test.java
public class case_test {
public static void main(String args[]) {
int newVal = 2;
switch (newVal) {
case 0 :System.out.println(newVal + " = " + 0);
case 1 :System.out.println(newVal + " = " + 1);
case 2 :System.out.println(newVal + " = " + 2);
case 3 :System.out.println(newVal + " = " + 3);
case 4 :System.out.println(newVal + " = " + 4);
case 5 :System.out.println(newVal + " = " + 5);
}
}
}


$ javac case_test.java
$ java cast_test
2 = 2
2 = 3
2 = 4
2 = 5

Aarggh!

$ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)

OK Answer is use break statments, which I dont have to trhe languages which I use more often.
Answer was staring me in the face if I read to the end of the lines in the Sun examples or looked at there second example. Sun Java Switch

Saturday 24 January 2009

Mac OS X Update Java

Mac OS X 10.5.2+ Install Java 1.6
http://www.apple.com/downloads/macosx/apple/application_updates/javaformacosx105update1.html
57MB Download

Mac OS X 10.5.4+ Update your java.
This update will upgrade your version to a later release. ie if you 1.4.2 it will be the latest 1.4.2_18. 1.5 to the latest 1.5_16.
http://support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_2
135MB Download

Now change your default java
/Applications/Utilities/Java/Java Preferences.app

Apple Java Info
http://developer.apple.com/java/javaleopard.html

Create .dmg files from the command line

While working on my sourceforge project FileExplorer I wanted to have an alpha release at which point I discovered that I can not upload .app's directly they have to be bundled inside a .dmg file.

The command line utility for this is called hdiutil. Then man page can be found here :

http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man1/hdiutil.1.html

The Line I use for my app is
$hdiutil create ./dist/FileExplorer.dmg -srcfolder ./dist/ -ov

This creates a .dmg in the dist folder with the existing contents of dist (where the .app is located). The file is part of a script which makes sure there are no .dmgs inside the dist folder first though. -ov Allows the file to be overidden if it is already there, useful if not part of the prementioned script.

Friday 16 January 2009

YHK6VP 20% off MOO.com Photo cards

YHK6VP 20% off 1 product @ MOO.com Photo cards

Visio Grid

When zooming in and out Visio changes the grid size by default, it would be nice if it did this in powers of 2, so things would still be alligned on finer settings but no, it is fractional and changing zoom can move objects off the grid.

The simplest soloution is to use a fixed grid.
Viso -> Tools -> Ruler & Grid
Set
Horizontal Grid Spacing = fixed
Vertical Grid Spacing = fixed
Horizontal Minimum spacing 5 mm
Vertical Minimum spacing 5 mm


Source http://office.microsoft.com/en-us/visio/HP012313791033.aspx

Thursday 15 January 2009

Java exec and Spaces

As part of my latest java project I need to open files in the OS standard program for that type.

<code example>
String command;
try {
  if (System.getProperty("os.name").contains("Mac")){
   command = "open " + newLocation + "";
  }
  if (System.getProperty("os.name").contains("Win")) {
   command = "cmd.exe /c start " + newLocation;
  }
  Process p = Runtime.getRuntime().exec(command);
  int exitCode = p.waitFor();

} catch (IOException e) {
  System.err.println(e.getMessage());
} catch (Exception e) {
  e.printStackTrace();
}
</code example>

However spaces and escape characters are not handled as you would expect. ie if the filename I am trying to open has spaces in it, it will not work.
This bug report better describes the problem with a potential solution.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6468220

Wednesday 14 January 2009

Ant with OS Specific builds

I have been using XCode to start a Java application, what I had not realised is that the build.xml created for ant relise on files from the Mac base install, ie it will not build correctly on any other OS which completely voids the point of writing in a portable language.

Below should be an example of an ant file that can do OS specific things.

<project name="OS-check-with-if-switch" default="chkOS">
 <!-- affects global scope -->
 <property file="build.global.properties" />
 <target name="chkOS" description="if switch to set OS specivic settings">
    <condition property="isMac">
          <os family="mac" />
    </condition>
 
    <condition property="isUnix">
       <and>   
          <os family="unix" />
          <not>
              <os family="mac" />    
          </not>
       </and>
    </condition>
 
    <condition property="isWindows">
       <os family="windows" />
    </condition>
    
    <antcall target="setMacEnv" />  
    <antcall target="setUnixEnv" />
    <antcall target="setWindowsEnv" />
 </target>
 <target name="setUnixEnv" if="isUnix">
  <echo>This is an Unix machine.</echo>
  <!-- affects local scope only -->
  <property file="unix.properties" />
 </target>
 <target name="setMacEnv" if="isMac">
  <echo>This is an Mac machine.</echo>
  <!-- affects local scope only -->
  <property file="mac.properties" />
 </target>
 <target name="setWindowsEnv" if="isWindows">
  <echo>This is a Windows machine.</echo>
  <!-- affects local scope only -->
  <property file="windows.properties" />
 </target>
</project>

Tuesday 13 January 2009

Switch from Xcode to Eclipse for java development on OS X

Switching from Xcode to Eclipse for java development on OS X, is relatively easily however Eclipse does not use the ant build.xml by default.

Java is a programming language developed by sun. Java 6 API
Ant is like make for java, A scripted build process.
Normally just calling ant in they same dir as the projects build.xml will compile the java application.

Xcode is an anoying IDE that is part of the Apple Developer toolset
Eclipse is a opensource IDE editor mostly written in java.

Need to figure out how to backup the configuration as it took hours to set up colours for a dark background, the preffered way to programme.

But I really just wanted to make a note of this site http://www.eclipsezone.com/eclipse/forums/t65486.html. It is a mini tutorial on setting up Eclipse to use the build.xml instead of its own build process. You need to do this if changing a project from Xcode to Eclipse.

Basically in Eclipse, Project -> Properties -> Builders. Then Add a new Ant Build and point to your build.xml.

Monday 12 January 2009

Subversion commit as a different user

I have been using Subversion for revision control of my source control for some time. It was not until recently when using sourceforge.net that my local user name and remote username differed.

$svn --username remoteUserName command

Other SVN (Subversion resources)
http://subversion.tigris.org/
http://svnbook.red-bean.com/

Saturday 10 January 2009

Mac Launching GUI apps from the command line

So I am working on my first sourceforge project (FileExplorer), which is a file browser. I really miss the ability to cut files and when pasting I want the contents of folders to be merged not just over written. That aside I have been trying to figure out how to trigger the operating systems default file handler.

The answer found here was quite simple, just call;
$ open somefile.xyz

it also shows away that you can force opening the file with a different application.
$ open -a Smultron someTextFile.txt
This will come in useful for right-click open with menus.

Wednesday 7 January 2009

Windows XP CMD

Since Windows XP the command line tool CD (Change Directory) does not seem to work properly.

To get a command line up you can just do Start->Run and enter CMD and hit return.

To make CD behave as expected always use 'CD /d' The /d forces it to change drives if required! When would I not want it to change to the drive I requested!

Other useful commands for Windows are
$ipconfig -all (Discover your network cards IP address)
Start->run 'msconfig' (Speed up windows boot time by reducing the applications launched on startup)

Thursday 1 January 2009

Support Wikipedia

Wikipedia Affiliate Button

Wikipedia is a very useful and free source of information, please help support it.