home / blog

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
exit
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
CREATE USER "foo" IDENTIFIED BY "bar";
Posted in geek | 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-5.2.1.0
  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 | 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 | 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

keysonic540rf

Posted in geek | Leave a comment

Installing adobe-reader on Ubuntu 12.10 – 64bit

wget http://ardownload.adobe.com/pub/adobe/reader/unix/9.x/9.5.3/enu/AdbeRdr9.5.3-1_i386linux_enu.deb
dpkg -i --force-all AdbeRdr9.5.3-1_i386linux_enu.deb
sudo apt-get -f install
Posted in geek | Leave a comment

Theme park cursor freeze [solved]

Eventually tracked this down a solution to this on a forum by someone exceedingly clever. Turns out to be an issue in the original game, but happens more often using emulators such as DOSBox.

vogons.zetafleet.com/viewtopic.php?t=31983&sid=6a3a397399f9c7837e222a265b195f4a

I tracked down the mouse pointer freeze problem some time ago thinking it might be a DOSBox issue, but AFAICT it’s a game bug. The mouse handler has a non-reentrancy flag that isn’t cleared in a specific condition that appears to be related to the mouse IRQ firing while switching between hi-res and lo-res video modes. When you play in hi-res some of the subscreens are in lo-res and switching is inevitable, but if you are careful not to move the mouse at all during the switching then the freeze can be avoided.

You can patch MAIN.EXE to fix the pointer freeze bug, but the exact offset varies between versions:
Code:
search: 0F 84 4D 05 00 00
modify: 43

There may be another problem with the mouse pointer related to hi-res/lo-res switching, but it is considerably more complicated and it can take some time before it occurs. This other problem causes the mouse pointer to disappear, and unlike the freeze problem it can’t be avoided by not moving the mouse. Actually, I would be interested in reports of pointer disappearance in Theme Park on real systems, because the complexity of what is going on makes it difficult to be certain if there is a game bug or a DOSBox issue.

Posted in geek | Leave a comment

Command line perl

I find this much more useful than sed.

Example 1: Filter/regex. Print numbers from matching lines.

foo 12 
bar 23
other
baz 34

-e is script mode. -n loops over your input automatically.

# -n option does the while loop for you
horse:~ adam$ perl -ne 'print "$1\n" if /(\d+)/' foo.txt
12
23
34

Without the -n option you’d have to add your own while loop.

perl -e 'while(<>) { print "$1\n" if /(\d+)/ }' foo.txt
12
23
34

Example 2: Modify. Wrap all numbers. -p loops around and prints the value of the substitution – much like sed

perl -pe 's/(\d+)/#$1#/' foo.txt
foo #12# 
bar #23#
other
baz #34#
Posted in geek | Tagged , | Leave a comment

Mythweb broken in Ubuntu 12.10 [solved]

HTTP 500s when trying to visit mythweb after upgrade to 12.10.

Cause, removal of allow-call-time-pass-reference option in PHP 5.4

adam@brimstone$ tail -f /var/log/apache2/error.log

[Sun Dec 02 16:59:29 2012] [error] [client 10.5.1.63] PHP Fatal error:  Call-time pass-by-reference has been removed in /usr/share/mythtv/bindings/php/MythBase.php on line 50

[Sun Dec 02 17:03:53 2012] [error] [client 10.5.1.63] PHP Fatal error:  Call-time pass-by-reference has been removed in /usr/share/mythtv/mythweb/includes/sorting.php on line 122

Fix:

// before MythBase.php: line 50
Cache::setObject($this->cacheKey, &$this, $this->cacheLifetime);
// after
Cache::setObject($this->cacheKey, $this, $this->cacheLifetime);
// before sorting.php on line 122
$response = $function(&$a, &$b);
// after
$response = $function($a, $b);
Posted in geek | Tagged , | 2 Comments

JNI helloworld

JNI is easy to use when you know how and frustrating when you don’t. I hope to demystify it and provide some pointers to when it goes wrong.

Define your native methods using the native modifier. In this example we’ll add two numbers together.

public class HelloWorld {
    public native int add(int a, int b);
}

Now generate your .h header files from the Java.

javac HelloWorld.java
javah -jni -classpath . HelloWorld

Implement your methods in a .c file

#include <jni.h>
#include "HelloWorld.h"
JNIEXPORT jint JNICALL Java_HelloWorld_add
(JNIEnv * env, jobject obj, jint a, jint b) {
  return (jint)(a + b);
}

Build your native library. This will vary between platforms.

# Linux
gcc -shared HelloWorld.c -I/usr/lib/jvm/java-6-openjdk/include -o libhelloworld.so 
# MacOS 10.6 - uses .dylib extension
gcc -shared HelloWorld.c -I-I/System/Library/Frameworks/JavaVM.framework/Headers -o libhelloworld.dylib 
# MacOS - older extension name "jnilib"
gcc -shared HelloWorld.c -I-I/System/Library/Frameworks/JavaVM.framework/Headers -o libhelloworld.jnilib 

Loading your library. This is traditionally done in a static block. The value you pass to loadLibrary() is the “base” library name – no lib prefix or .so, .dylib, .jnilib or .dll extensions.

public class HelloWorld {
    static {
	System.loadLibrary("helloworld");
    }
    public native int add(int a, int b);
    public static void main(String [] args) {
	System.out.println(new HelloWorld().add(12,34));
    }
}

Running. The most important thing here is to let the VM know where your library is. There are several methods for this.

  • Put the library in a known search path:
    # MacOS
    cp libhelloworld.dylib /Library/Java//Extensions
    # Linux
    cp libhelloworld.so /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
    
    # run as normal
    java -cp . HelloWorld
    46
    
  • Alter the VM arg java.library.path
    java -Djava.library.path=. -cp . HelloWorld
    46
    
  • Alter the OS library loader
    export LD_LIBRARY_PATH="."
    java -cp . HelloWorld
    46
    

When things go wrong: can’t see library

java -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: no helloworld in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
	at java.lang.Runtime.loadLibrary0(Runtime.java:845)
	at java.lang.System.loadLibrary(System.java:1084)
	at HelloWorld.&lt:clinit>(HelloWorld.java:6)

When things go wrong: incorrectly named library

mv libhelloworld.dylib libhelloworld.dylib2
java -Djava.library.path=. -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: no helloworld in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
	at java.lang.Runtime.loadLibrary0(Runtime.java:845)
	at java.lang.System.loadLibrary(System.java:1084)
	at HelloWorld.&lt:clinit>(HelloWorld.java:6)

When things go wrong: Method name mismatch.

JNIEXPORT jint JNICALL Java_HelloWorld2_add   <==== name changed to not match classname.
(JNIEnv * env, jobject obj, jint a, jint b) {
  return (jint)(a + b);
}
java -Djava.library.path=. -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: HelloWorld.add(II)I
	at HelloWorld.add(Native Method)
	at HelloWorld.main(HelloWorld.java:11)

When things go wrong: library depends on another library that can’t be found.

# My library now depends on libftd2xx
ldd libhelloworld.so 
	linux-vdso.so.1 =>  (0x00007fff5f9ff000)
	libftd2xx.so => /usr/lib/libftd2xx.so (0x00007f4338c68000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f43388a9000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f433868b000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4338487000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f433827f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f43390af000)
# I make it unavailable
sudo mv /usr/lib/libftd2xx.so /usr/lib/libftd2xx.so.hidden

java -Djava.library.path=. -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: /data3/development/local/java/jni/libhelloworld.so: libftd2xx.so: cannot open shared object file: No such file or directory
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1935)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1860)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1850)
	at java.lang.Runtime.loadLibrary0(Runtime.java:845)
	at java.lang.System.loadLibrary(System.java:1084)
	at HelloWorld.&lt:clinit>(HelloWorld.java:4)

When things go wrong: library without execute permissions – windows only issue

Also useful for debugging there is also a System.load() call which takes an absolute path to the library.

static {
  System.load("/Users/adam/development/java/jni/libhelloworld.dylib");
}
Posted in geek | Leave a comment

Filtered copy and preserve directory structure

Say you had a massive, slow clearcase VOB with many filetypes, but you just wanted to copy the java files to /tmp for fast searching, and preserve the directory structure.

find . -name "*.java" | cpio --pass-through --verbose /tmp/horsecopy
Posted in geek | Tagged , | Leave a comment