Friday, October 18, 2013

MySql Workbench not installing

When installing MySQL workbench on Linux if you get this error below it is most probably due to a previous version of MySQL workbench still have some data on your PC.

 trying to overwrite '/usr/share/mysql-workbench/shell_snippets.py.txt'

To fix make sure MySQL workbench is removed and also make sure the package "mysql-workbench-data" is removed

Thursday, June 27, 2013

Hiding data on a Excel Spreadsheet using POI

I had a requirement where I needed to hide some meta data in Excel Spreadsheet.  Instead of using hidden row/columns/cells I used Custom Properties.  Custom properties is a map in the Spreadsheet file where you can store key/value data.  I found this much safer than hiding the data on the sheets since users could delete/corrupt the data very easily.

I did thou encounter a bug in Libre/OpenOffice where Custom properties are deleted when changes are made to the spreadsheet.  The bug is logged with LibreOffice so I just updated my findings on the issue. See issue.

Due to this I have added extra example of how to store the data in the comments field of a spreadsheet.  Both .xls and .xlsx file formats are supported in the example and at the time I was using POI 3.7.

 /**  
  * Retrieve a custom property on the spreadsheet  
  *   
  * @param key  
  * @return  
  */  
 public static String getCustomProperty(final String key) {  
      if (_workbook instanceof HSSFWorkbook) {  
           DocumentSummaryInformation documentSummaryInformation = ((HSSFWorkbook) _workbook)  
                     .getDocumentSummaryInformation();  
           if (documentSummaryInformation != null && documentSummaryInformation.getCustomProperties() != null)  
                return (String) documentSummaryInformation.getCustomProperties().get(key);  
           return null;  
      } else if (_workbook instanceof XSSFWorkbook) {  
           System.out.println(((XSSFWorkbook) _workbook).getProperties().getCustomProperties().contains(key));  
           System.out.println(((XSSFWorkbook) _workbook).getProperties().getCustomProperties()  
                     .getUnderlyingProperties().sizeOfPropertyArray());  
           if (((XSSFWorkbook) _workbook).getProperties().getCustomProperties().contains(key)) {  
                List<CTProperty> propertyList = ((XSSFWorkbook) _workbook).getProperties().getCustomProperties()  
                          .getUnderlyingProperties().getPropertyList();  
                for (CTProperty prop : propertyList) {  
                     if (prop.getName().compareTo(key) == 0) {  
                          System.out.println("Key : " + prop.getName() + ", Prop : " + prop.getLpwstr());  
                          return prop.getLpwstr();  
                     }  
                }  
           }  
           System.out.println("Creator : "  
                     + ((XSSFWorkbook) _workbook).getProperties().getCoreProperties().getCreator());  
           System.out.println("Description : "  
                     + ((XSSFWorkbook) _workbook).getProperties().getCoreProperties().getDescription());  
           return ((XSSFWorkbook) _workbook).getProperties().getCoreProperties().getCreator();  
      }  
      throw new RuntimeException("Unsupported workbook!");  
 }  
 /**  
  * Add a custom property to the spreadsheet  
  *   
  * @param key  
  * @param value  
  */  
 public static void setCustomProperty(final String key, final String value) {  
      if (_workbook instanceof HSSFWorkbook) {  
           HSSFWorkbook workbook = (HSSFWorkbook) _workbook;  
           DocumentSummaryInformation documentSummaryInformation = workbook.getDocumentSummaryInformation();  
           if (documentSummaryInformation == null) {  
                workbook.createInformationProperties();  
                documentSummaryInformation = workbook.getDocumentSummaryInformation();  
           }  
           CustomProperties customProperties = documentSummaryInformation.getCustomProperties();  
           if (customProperties == null) {  
                customProperties = new CustomProperties();  
           }  
           customProperties.put(key, value);  
           documentSummaryInformation.setCustomProperties(customProperties);  
      } else if (_workbook instanceof XSSFWorkbook) {  
           ((XSSFWorkbook) _workbook).getProperties().getCoreProperties().setDescription(value);  
           ((XSSFWorkbook) _workbook).getProperties().getCustomProperties().addProperty(key, value);  
      } else {  
           throw new RuntimeException("Unsupported workbook!");  
      }  
 }  
 /**  
  * Retrieve Comments attached spreadsheet  
  *   
  * @return  
  */  
 public static String getComments() {  
      if (_workbook instanceof HSSFWorkbook) {  
           return ((HSSFWorkbook) _workbook).getSummaryInformation().getComments();  
      } else if (_workbook instanceof XSSFWorkbook) {  
           return ((XSSFWorkbook) _workbook).getProperties().getCoreProperties().getDescription();  
      }  
      throw new RuntimeException("Unsupported workbook!");  
 }  
 /**  
  * Set Comment for the spreadsheet  
  *   
  * @param comment  
  */  
 public static void setComments(final String comment) {  
      if (_workbook instanceof HSSFWorkbook) {  
           HSSFWorkbook workbook = (HSSFWorkbook) _workbook;  
           SummaryInformation summaryInformation = workbook.getSummaryInformation();  
           if (summaryInformation == null) {  
                workbook.createInformationProperties();  
                summaryInformation = workbook.getSummaryInformation();  
           }  
           summaryInformation.setComments(comment);  
      } else if (_workbook instanceof XSSFWorkbook) {  
           ((XSSFWorkbook) _workbook).getProperties().getCoreProperties().setDescription(comment);  
      } else {  
           throw new RuntimeException("Unsupported workbook!");  
      }  
 }  

Friday, June 22, 2012

Oracle (sun) java 6 install

I am currently running Mint Linux 13 which comes with OpenJDK/JRE but I require Oracle(Sun) Java here is how to install manually.  I know there are PPA's out there but I do not find them very reliable since Oracle seem to have some licensing issue with 3de parties hosting Java binaries.

Step 1: Download

Go to the Oracle site and select your Java. http://www.oracle.com/technetwork/java/javase/downloads/index.html

Step 2: Extract

I downloaded Java 7 JDK so to extract was simply

 tar -xvf ~/Downloads/jdk-7u5-linux-x64.tar.gz  

Step 3: Move

When you install Java via a package manager for a Debian system the install location is /usr/lib/jvm/.  If you go have a look at that folder you should see all the installed version of java on you pc.  So to move the extracted folder:

 sudo mv ~/Downloads/jdk1.7.0_05 /usr/lib/jvm/java-7-sunjdk  

This will move and rename the folder to java-7-sunjdk

Step 4: Install

Linux has this amazing command to where you can link commands with the option of easy switching.

So to list all the currently installed options for the command java type

 user@user-SERVER ~ $ sudo update-alternatives --list java  
 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  

As you can see here I only have Java 6 OpenJDK installed for the command java.  Now to add my Oracle java I will have to install a new option as follow:

 sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-7-sunjdk/bin/java" 1  

Now if I rerun the list command I have two options for the java command

 user@user-SERVER ~ $ sudo update-alternatives --list java  
 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  
 /usr/lib/jvm/java-7-sunjdk/bin/java

Step 5: Select Default

Now to select which one must be executed by default if I run the java command:

 user@user-SERVER /usr/lib/jvm $ sudo update-alternatives --config java  
 There are 2 choices for the alternative java (providing /usr/bin/java).  
  Selection  Path                      Priority  Status  
 ------------------------------------------------------------  
 * 0      /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  1061   auto mode  
  1      /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  1061   manual mode  
  2      /usr/lib/jvm/java-7-sunjdk/bin/java       1     manual mode  
 Press enter to keep the current choice[*], or type selection number: 2  
 update-alternatives: using /usr/lib/jvm/java-7-sunjdk/bin/java to provide /usr/bin/java (java) in manual mode.  

When you run this command you are show the current default and all the available options.  In my case I selected option 2 as my new default.

Step 6: Jippy

Your all done below are just some command for the ease to map the javaws, javac and jps.  Your more than welcome to add more.

 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-7-sunjdk/bin/javac" 1  
 sudo update-alternatives --config javac  
 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java-7-sunjdk/bin/javaws" 1  
 sudo update-alternatives --config javaws  
 sudo update-alternatives --install "/usr/bin/jps" "jps" "/usr/lib/jvm/java-7-sunjdk/bin/jps" 1  
 sudo update-alternatives --config jps  

Wednesday, May 16, 2012

Ivy Bridge HD4000 Linux Freeze

First thing I did after I received my new Ivy Bridge PC with Gigabyte GA-Z77-D3H and Intel Core i7 3770 was install the new Ubuntu 12.04.  All was fine for a while until the PC would freeze up, mouse not moving, ATL+CTRL+F1 not working, nothing!  This seemed to happen every-time semi heavy load was placed on the HD 4000 graphics processor on the i7 chip.  Something I found that really triggered this was browsing websites like Google maps or scrolling up and down on a page with lots of dynamic content in Firefox it is a guaranteed freeze.

After a bit of trail and error the solutions was found.  There seems to be a bug in the Linux Kernel 3.2.x.  Now after upgrading to Kernel 3.3.x the problem has disappeared!  Below are the steps to update the kernel in Ubuntu 12.04.

Please note I do not take any responsibility if this breaks things.  This worked for me and I am merely trying to help others.

At the time of writing this article the latest stable kernel is 3.3.6

The kernel can be found at kernel.ubuntu.com or you can just ignore this and copy and past the commands below to the terminal depending on you installation

For Ubuntu (i386 / 32-bit) run these commands
 cd /tmp && wget -O linux-headers-3.3.6-030300_3.3.6_all.deb http://goo.gl/zNlMy  
 sudo dpkg -i linux-headers-3.3.6-030300_3.3.6_all.deb  
 cd /tmp && wget -O linux-headers-3.3.6-generic_i386.deb http://goo.gl/TdBex  
 sudo dpkg -i linux-headers-3.3.6-generic_i386.deb  
 cd /tmp && wget -O linux-image-3.3.6-generic_i386.deb http://goo.gl/osZhw  
 sudo dpkg -i linux-image-3.3.6-generic_i386.deb  

For Ubuntu (amd64 / 64-bit) run these commands
  cd /tmp && wget -O linux-headers-3.3.6-030300_3.3.6_all.deb http://goo.gl/zNlMy  
 sudo dpkg -i linux-headers-3.3.6-030300_3.3.6_all.deb  
 cd /tmp && wget -O linux-headers-3.3.6-generic_amd64.deb http://goo.gl/Z9Ztt  
 sudo dpkg -i linux-headers-3.3.6-generic_amd64.deb  
 cd /tmp && wget -O linux-image-3.3.6-generic_amd64.deb http://goo.gl/jji3o  
 sudo dpkg -i linux-image-3.3.6-generic_amd64.deb 

Just reboot your system and done.

I you have any questions/problems please leave a comment and I will try to help

Friday, April 20, 2012

Seam parameter as date

When using Seam Gen to setup basic pages from the persistence objects where a primary key is a date or one of the keys in the combined primary key is a date you will run into this error:  "value must be a date"

 This is due to the date converter not working properly when seam is parsing the page parameters.  By default it just performs a toString causing the page parameter to be populated as follow:

ReadDate=2007-01-02+00%3A00%3A00.0


The fix for this is easy just add a SimpleDateFormat or if you using JodaTime a DateTimeFormatter to output a string version of the date on the hibernate object as show below:


public String getReadDateStr() {

  // SimpleDateFormat
  return new SimpleDateFormat("dd/MM/yyyy").format(date)
  // Joda Time
  return DateTimeFormat.forPattern("dd/MM/yyyy").print(date.getTime())



Then in the JSF change the parameter as follow:
<f:param name="startDate" value="#{_priceElementRate.id.readDateStr}" />




Sunday, March 18, 2012

5x5 LED Cube

The 5x5 LED cube project version 1.0 is working!



I am making use of 4 shift registers 74CH595N to control the 25 columns and 5 P2N2222A NPN Transistor to select a layer.  Currently I am writing the cube state for a layer out every 7ms.

The soldering of the cube was painful, but at least now I regained a bit of the soldering iron skill that I lost since uni.  Below are some pics of the building of the cube:



 But I must say the most fun of the project was the coding, really enjoyed playing with C again.  My next step will be to port this project from the ATmega328 chip (Arduino) to the MSP-EXP430G2 chip (TI Launchpad).