home / blog

Flash in Chrome/Ubuntu 13.04 – could not load plugin [solved]

rm -rf ~/.config/google-chrome/
Posted in geek | Tagged , | Leave a comment

ImageMagick darkening Grayscale PNGs

When converting or mogrify-ing images I’ve noticed grayscale PNG files are far darker than originals – mid-grays become almost black. It turns out ImageMagick tries to set to PNG8 based on image content even if the file was previously PNG24 or PNG32. This conversion is trigged by both convert and mogrify, e.g. image resizing with -geometry option.

The default format can be overridden in convert using either the FORMAT:output syntax or -define png:format=png24

convert input.ppm PNG24:output.png

For mogrify only the -define method works, -define png:format=png24

mogrify -define png:format=png24 -geometry x30  input.png output.png  

I also tried solutions involving -colorspace RGB or -colorspace sRGB but files generated like this looked fine in GIMP etc. but were too light in firefox, chrome etc.

Posted in geek | Leave a comment

Waiting for EBSs/WARs in JBoss to deploy using gradle / twiddle

Some home development for an issue at work… Often integration tests fail because the ESBs/WARs fail to deploy, we’d like early warning of this.

The ESBs/WARs are deployed into a JBoss instance using gradle. The deployment gradle script can be enhanced with the following to use twiddle.sh – a built in JBoss JMX client to wait for all ESBs/WARs to be marked as deployed, or timeout after some configurable period. The JMX username/password are loaded directly from the soa-users.properties file.

Example: happy path

gradle -PdeployEsbs=Foo,Bar -PdeployWars=Baz -PdeployTimeoutSecs=10
Monitoring deployment status of ESBs [Foo, Bar] and WARs [Baz]
Foo OK  | Bar x   | Baz x  
Foo OK  | Bar x   | Baz x  
Foo OK  | Bar x   | Baz x  

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/adam/development/gradle/build.gradle' line: 44

* What went wrong:
A problem occurred evaluating root project 'gradle'.
> Timed out waiting for [Bar, Baz] to deploy

Example: sad path

 gradle -PdeployEsbs=Foo,Bar -PdeployWars=Baz -PdeployTimeoutSecs=10
Monitoring deployment status of ESBs [Foo, Bar] and WARs [Baz]
Foo OK  | Bar OK  | Baz x  
All ESBs/WARs are deployed. Go go go

The code:

def deployTimeoutSecs = hasProperty('deployTimeoutSecs') ? property('deployTimeoutSecs').toInteger() : 45
def deployEsbs = hasProperty('deployEsbs') ? property('deployEsbs').tokenize(',') : []
def deployWars = hasProperty('deployWars') ? property('deployWars').tokenize(',') : []
import java.util.concurrent.TimeUnit

println "Monitoring deployment status of ESBs ${deployEsbs} and WARs ${deployWars}"
def timeStart = System.currentTimeMillis()
while (true) {
      def props = new Properties()
      props.load(new FileInputStream('soa-users.properties'))
      def jmxUser = props.stringPropertyNames().toList()[0]
      def jmxPassword = props.getProperty(jmxUser)

      def captureOutputStream = new ByteArrayOutputStream()
      exec {
         ignoreExitValue = true
         standardOutput = captureOutputStream
         executable = './twiddle.sh'
         args = ['-u', jmxPassword, '-p', jmxUser, '-h', 'localhsot:1099', 'query', '*:*']
      def capture = captureOutputStream.toString().tokenize('\n').collect { it.trim() }
      def states = new LinkedHashMap()
      deployEsbs.each {
         states.put(it, capture.contains(new String("jboss.esb.deployment=${it}.esb")))
      deployWars.each {
         states.put(it, capture.contains(new String("jboss.esb.deployment:war=${it}.war")))
      if (states.every { it.value }) {
          println "All ESBs/WARs are deployed. Go go go"

      def report = states.collect {
          return it.key+ ' ' + (it.value ? ':)' : 'x').padRight(3)
      println report.join(' | ')

      if (System.currentTimeMillis() - timeStart > TimeUnit.SECONDS.toMillis(deployTimeoutSecs)) {
          def notDeployed = states.findResults { !it.value ? it.key : null }
          throw new GradleException("Timed out waiting for ${notDeployed} to deploy")
Posted in geek | Tagged , | Leave a comment

Unmarshalling JAXB entities from SOAP wrappers

Extracting JAXB entities from inside SOAP wrappers can be done without string-chopping using standard APIs.

Example: using standard API.

String example =
        "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body><ns2:farm xmlns:ns2=\"http://adamish.com/example/farm\"><horse height=\"123\" name=\"glue factory\"/></ns2:farm></soapenv:Body></soapenv:Envelope>";

SOAPMessage message = MessageFactory.newInstance().createMessage(null,
        new ByteArrayInputStream(example.getBytes()));

Unmarshaller unmarshaller = JAXBContext.newInstance(Farm.class).createUnmarshaller();
Farm farm = (Farm)unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument());

Anti-example seen in the wild: string chopping / regex

String example =
        "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body><ns2:farm xmlns:ns2=\"http://adamish.com/example/farm\"><horse height=\"123\" name=\"glue factory\"/></ns2:farm></soapenv:Body></soapenv:Envelope>";

int start = example.indexOf("Body>") + 5;
Matcher m = Pattern.compile("</[^>]*Body").matcher(example);
int end = m.start();
String output = example.substring(start, end);

Unmarshaller unmarshaller = JAXBContext.newInstance(Farm.class).createUnmarshaller();
Farm farm = (Farm) unmarshaller.unmarshal(new ByteArrayInputStream(output.getBytes()));
Posted in geek | Tagged , , | 2 Comments

Marshalling JAXB entities into SOAP wrappers

SOAP envelopes can be added to existing org.w3c.dom.Document or JAXB instances easily.

Farm farm = new Farm();
farm.getHorse().add(new Horse());
farm.getHorse().get(0).setName("glue factory");

Example: using standard API

Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Marshaller marshaller = JAXBContext.newInstance(Farm.class).createMarshaller();
marshaller.marshal(farm, document);

SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

String output = new String(outputStream.toByteArray());

Anti-example seen in the wild: manual concatenation/formatting

String soapEnvelope =
        "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                "<soapenv:Header /><soapenv:Body>%s</soapenv:Body></soapenv:Envelope>";

Marshaller marshaller = JAXBContext.newInstance(Farm.class).createMarshaller();
marshaller.setProperty("jaxb.fragment", Boolean.TRUE); // required to stop <?xml ... being added ?>

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
marshaller.marshal(farm, outputStream);
String payload = new String(outputStream.toByteArray());

String output = String.format(soapEnvelope, payload);

Note, the namespace prefix, which the standard libraries which defaults to SOAP-ENV can be changed, but it’s hard work.

soapMessage.getSOAPPart().getEnvelope().addNamespaceDeclaration("soap", "http://www.w3.org/2001/12/soap-envelope");
Posted in geek | Tagged , | Leave a comment

13.04 Mythtv with minimal ubuntu desktop upgrade

Yes… I know about mythbuntu, however I prefer to roll-my-own and use the a standard minimal ubuntu-desktop for consistency, and also use netflix / chrome from the media-centre PC.

# pre-setup
# - backup home, etc and mysqldump
# - minimal install using mini.iso from https://help.ubuntu.com/community/Installation/MinimalCD
# - install. select only open SSH server
apt-get install --no-install-recommends emacs

# login via SSH
# restore /etc/fstab
# restore home directories
chown -R mythtv:mythtv ~mythtv
chown -R adam:adam ~adam

# static IP address
sudo emacs /etc/network/interfaces 
auto eth0
iface eth0 inet static

# minimum install
sudo apt-get install --no-install-recommends ubuntu-desktop 
# mythtv
sudo apt-get install --no-install-recommends mythtv mythweb xmltv-util dvb-apps

# hardware
sudo apt-get install --no-install-recommends nvidia-current
sudo apt-get install r8168-dkms
sudo bash -c "echo 'blacklist r8169' > /etc/modprobe.d/blacklist-r8169.conf"

# find applications in unity
sudo apt-get install --no-install-recommends unity-lens-applications
# essentials 
sudo apt-get install --no-install-recommends gnome-terminal ethtool nmap git php5-cli
# fonts
sudo apt-get install ttf-ubuntu-font-family

# restore mythtv database
mysql -u root -p < backup.sql
# change mythtv password in database to match /etc/apache2/sites-available/mythweb.conf and ~mythtv/.mythtv/config.xml
mysql -u root -p
update mysql.user set Password=PASSWORD('password') where user = 'mythtv';

# enable auto login
sudo emacs /etc/lightdm/lightdm.conf

sudo emacs ~/config/autostart/mythtv-frontend.desktop
[Desktop Entry]
Name=mythtv frontend

# Bugfix - Unity desktop show border around myth front end
gconftool --type Boolean --set /apps/compiz-1/plugins/workarounds/screen0/options/legacy_fullscreen true

# Bugfix - stop screen blanking
sudo apt-get remove gnome-screensaver

# chrome browser
sudo apt-get install --no-install-recommends libgconf2-4 libnss3-1d libxss1 libcurl3 xdg-utils
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb

# Netflix desktop
sudo apt-get remove nvidia-current
sudo apt-get install nvidia-173 # current drivers broken for fullscreen playback
sudo apt-add-repository ppa:ehoover/compholio
sudo apt-get update
sudo apt-get install netflix-desktop nvidia-settings

# iplayer
sudo add-apt-repository ppa:jon-hedgerows/get-iplayer
sudo apt-get update
sudo apt-get install get-iplayer ffmepg
Posted in geek | Tagged , , | Leave a comment

Oracle 11g XE on Ubuntu 12.10

# dependencies
sudo apt-get install alien libaio1 unixodbc

# install
unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip -d oraclexe
cd oraclexe/Disk1/
sudo alien --scripts -d oracle-xe-11.2.0-1.0.x86_64.rpm
sudo dpkg --force all --install oracle-xe_11.2.0-2_amd64.deb

# requirements for setup
sudo ln -s /usr/bin/awk /bin/awk 
sudo mkdir -p /var/lock/subsys
sudo mkdir -p /u01/app/oracle/oradata
sudo mkdir -p /u01/app/oracle/diag
sudo touch /var/lock/subsys/listener
sudo groupadd dba
sudo useradd oracle -g dba

sudo touch /sbin/chkconfig
sudo chmod a+x /sbin/chkconfig
update-rc.d oracle-xe defaults 80 01

# environment
sudo mount -t tmpfs shmfs -o size=2048m /dev/shm
sudo dd if=/dev/zero of=/swapfile bs=1024 count=2097152
sudo mkswap /swapfile
sudo su
echo '/swapfile swap swap defaults 0 0' >> /etc/fstab
swapon -a
swapon -s

# set ports / username/password
sudo rm /etc/default/oracle-xe 
sudo /etc/init.d/oracle-xe configure

# update your environment 
cat /etc/profile.d/oracle.sh
source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh 

# create normal user
sqlplus system/system
Posted in geek | Tagged , | Leave a comment

Canon powershot SX110 remote control

It seems the remote control functionality for the powershot SX110 on MacOS X 10.7.5 has been broken for quite some time now.

I stumbled across an open source project gphoto2 also offering remote control functionality.

sudo port install gphoto2
gphoto2 --auto-detect
Model                          Port                                            
Canon PowerShot SX110 IS       usb:253,003   

So far so good…

gphoto2 --summary
*** Error (-53: 'Could not claim the USB device') *** 

Oh dear, something else using the camera…

ps A | grep PTPCamera
16950   ??  S      0:00.11 /System/Library/Image Capture/Devices/PTPCamera.app/Contents/MacOS/PTPCamera -psn_0_712878
killall PTPCamera
gphoto2 --summary
Camera summary:                                                                
Manufacturer: Canon Inc.
Model: Canon PowerShot SX110 IS
  Version: 1-
  Serial Number: 7xxxxxxxxxxxxxxxxxx
Vendor Extension ID: 0xb (1.0)

Capture Formats: JPEG
Display Formats: Association/Directory, Script, DPOF, MS AVI, MS Wave, JPEG, Defined Type, CRW, Unknown(b103), Unknown(b104), Unknown(bf01)

Device Capabilities:
	File Download, File Deletion, File Upload
	Generic Image Capture, No Open Capture, Canon Capture

Storage Devices Summary:

Device Property Summary:
Event Emulate Mode(0xd045):(readwrite) (type=0x4) Enumeration [1,2,3,4,5,6,7] value: 2
Property 0xd04a:(readwrite) (type=0x2) Enumeration [0,1,2,3] value: 0
Size of Output Data from Camera(0xd02e):(read only) (type=0x6) 524288
Size of Input Data to Camera(0xd02f):(read only) (type=0x6) 524288
Battery Type(0xd002):(read only) (type=0x4) Enumeration [0,1,2,3,4,5] value: Unknown (0)
Battery Mode(0xd003):(read only) (type=0x6) Enumeration [0,1,2,3] value: Normal (1)
UNIX Time(0xd034):(readwrite) (type=0x6) 1365413554
Type of Slideshow(0xd047):(read only) (type=0x4) 0
DPOF Version(0xd046):(read only) (type=0x4) 257
Supported Thumb Size(0xd02d):(read only) (type=0x4006) a[4] 119,0,159,0
Average Filesizes(0xd048):(read only) (type=0x4006) a[19] 3981312,2785280,2050048,0,254976,2357248,1658880,1142784,0,153600,1126400,798720,569344,0,86016,0,1026048,571392,284672
Size Quality Mode(0xd02c):(read only) (type=0x4006) Enumeration [
	a[6] 2592,3456,1,0,0,0,
	a[6] 2592,3456,6,0,0,0,
	a[6] 2592,3456,11,0,0,0,
	a[6] 2112,2816,2,0,0,0,
	a[6] 2112,2816,7,0,0,0,
	a[6] 2112,2816,12,0,0,0,
	a[6] 1704,2272,3,0,0,0,
	a[6] 1704,2272,8,0,0,0,
	a[6] 1704,2272,13,0,0,0,
	a[6] 1200,1600,17,0,0,0,
	a[6] 1200,1600,18,0,0,0,
	a[6] 1200,1600,19,0,0,0,
	a[6] 480,640,5,0,0,0,
	a[6] 480,640,10,0,0,0,
	a[6] 480,640,15,0,0,0
	] value: a[6] 0,0,0,0,0,0
Remote API Version(0xd030):(read only) (type=0x6) 256
Model ID(0xd049):(read only) (type=0x6) 38928384
Camera Model(0xd032):(read only) (type=0xffff) 'Canon PowerShot SX110 IS'
Camera Owner(0xd033):(readwrite) (type=0x4002) a[13] 65,100,97,109,32,71,114,97,110,103,101,114,0
Firmware Version(0xd031):(read only) (type=0x6) 16777216
Property 0xd050:(read only) (type=0x2) 0
Property 0xd402:(read only) (type=0xffff) 'Canon PowerShot SX110 IS'
Property 0xd406:(readwrite) (type=0xffff) 'Windows'
Property 0xd407:(read only) (type=0x6) 1

Basic usage

gphoto2 --set-config /main/settings/capture=1      # extend lens
gphoto2 --set-config /main/settings/output=0       # view finder on
gphoto2 --set-config /main/imgsettings/imagesize=0 # max image quality
gphoto2 --capture-image-and-download               # snap
Posted in geek | Tagged , , , | Leave a comment

Cannot add tomcat7 server in eclipse 4.x [solved]

rm workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.server.tomcat.core.prefs

rm workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.server.core.prefs
# restart eclipse
Posted in geek | Tagged , , , | Leave a comment

Touchpad not working on keysonic ACK 540 RF [solved]

The trackpad/touchpad on my keysonicACK 540 RF although the keyboard worked fine. So did lots of debugging with dmesg, udev, xev, research on forums etc…

Turned out the batteries were just low, such that the keyboard worked but the mouse didn’t. Fresh batteries. Fixed. #checkhardwarefirst


Posted in geek | Tagged , , | 1 Comment