Installing XPath Explorer on NetBeans for Mac OSX

24 12 2008

I have only found this documentation on installing xpath explorer on netbeans, therefore I’ll give a little more info for mac osx (it’s easy but you have to search a little).

1. download the xpe-netbeans.jar file (from the xpe project download page).

2. place the xpe-netbeans.jar file in your NetBeans module lib dir, the following worked for me:
/Applications/NetBeans/NetBeans 6.5.app/Contents/Resources/NetBeans/platform9/lib

3. restart NetBeans and you should see the following menu option: Tools > XPath Explorer.

Adapt these instructions for your NetBeans installation path and version number if different.





vi search pattern for replacing line numbers in code snippet

19 12 2008

This is a useful search and replace pattern for deleting the line numbers in a code snippet…

use this command in vi (the unix based txt editor):

%s/^[0-9][0-9]\s*//g

this will delete (replace pattern with nothing) all the line numbers in the following code snippet (thus cleaning it and allowing you to compile it without first manually editing every line):

...
03 import java.util.List;
04 import java.util.ArrayList;
05 import java.util.Iterator;
06
07 public class Todo {
08 private String name;
09 private String note;
...





getting the back end server name from an oracle db

15 09 2008

In our hosting environment we have many servers running may different oracle instances.

Execute this query to get the back end server name (could still be a virtual server of course):

select HOST_NAME from v$instance

The only problem with this is that the user executing the SQL must have select permission on “sys.v$instance”. A better solution is to use the in-built SYS_CONTEXT package, which is available to everyone and requires no extra permissions to run.

The query below demonstrates use of the package and some of the information you can get.
select sys_context ( 'USERENV', 'DB_NAME' ) db_name,
sys_context ( 'USERENV', 'SESSION_USER' ) user_name,
sys_context ( 'USERENV', 'SERVER_HOST' ) db_host,
sys_context ( 'USERENV', 'HOST' ) user_host
from dual

NOTE: The parameter ‘SERVER_HOST’ is available in 10G only.

Any Oracle User that can connect to the database can run a query against “dual”.
No special permissions are required and SYS_CONTEXT provides a greater range of application specific information than “sys.v$instance”.

More information is available here





Installing netbeans 6.5M1 on ubuntu error:/usr/share/themes/Human/gtk-2.0/gtkrc:43: error: lexical error or unexpected token, expected valid token

6 08 2008

problem:

I get the following error when trying to run the linux netbeans 6.5M1 installer (netbeans-6.5_m1-php-linux.sh) on ubuntu 8.04:

/usr/share/themes/Human/gtk-2.0/gtkrc:43: error: lexical error or unexpected token, expected valid token

and then the installer window shows a blank screen.

(I’m guessing this post may relate to other versions of netbeans and ubuntu)

solution:

the problem was the jvm 1.5 I was running under, updating to jvm 1.6 solves the problem… I installed the sun-java6-jdk and the jvm dependencies then when executing the installer I specified the java home as follows:

./netbeans-6.5_m1-php-linux.sh --javahome /usr/lib/jvm/java-6-sun





chmod: copy user / owner permissions to group

24 07 2008

This is a useful unix command to copy the file / dir owner permissions to the group:

find * -exec /bin/sh -c 'chmod g+`ls -ld "{}" | cut -c2-4` "{}"' \;

As pointed out in the post below, chmod actually has built in support for this operation:

chmod g+u file





(X tunnelling) xhost: unable to open display

23 07 2008

I’m running ubuntu 8.04 and had a problem tunneling the X display from a solaris box to my local ubuntu test server.

when executing this command in my bash script:

DISPLAY=localhost:0
export DISPLAY
xhost +

i would get the following message

xhost: unable to open display “localhost:0″

The problem being the by default ubuntu restricts tcp listening with the following configuration default in:

/etc/gdm/gdm.conf

# If true this will basically append -nolisten tcp to every X command line, a
# good default to have (why is this a "negative" setting? because if it is
# false, you could still not allow it by setting command line of any particular
# server).  It's probably better to ship with this on since most users will not
# need this and it's more of a security risk then anything else.
# Note: Anytime we find a -query or -indirect on the command line we do not add
# a "-nolisten tcp", as then the query just wouldn't work, so this setting only
# affects truly attached sessions.
DisallowTCP=true

To fix the error message you can cgange the config option to:

DisallowTCP=false





eclipse file associations

24 05 2008

Quick easy note on associating certain file extensions with an editor in eclipse e.g. I’m developing .module and .info files for drupal modules. Just goto eclipse preferences -> general -> content types, then add the file associations using the add dialog





eclipse.ini -vm option

26 03 2008

Note to self when configuring the “-vm” option in eclipse.ini… Place the path to your jdk on a new line i.e.

...
-vm
C:\programs\Java\jdk1.6.0\bin

...

and not:
...
-vm C:\programs\Java\jdk1.6.0\bin
...

Also to see what configuration options stuck goto menu item: Help -> About Eclipse Platform, then click Configuration Details button.





java & struts file download

31 01 2008

Your file POJO will look somthing like this:
public interface MyFile
{
public int getAppraisalFindingsFileId();
public void setAppraisalFindingsFileId(int appraisalFindingsFileId);
public int getAppraisalId();
public void setAppraisalId(int appraisalId);
public String getFileName();
public void setFileName(String fileName);
public int getFileSize();
public void setFileSize(int fileSize);
public Calendar getUploadedDate();
public void setUploadedDate(Calendar uploadedDate);
public String getUploadedBy();
public void setUploadedBy(String uploadedBy);
public byte[] getFileData();
public void setFileData(byte[] fileData);
}

Once you have your file data do something similar to this in your Forms Action class execute method:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
//...
// do something like this...
response.setContentLength(myFile.getFileSize());
response.setContentType("application/x-file-download");
response.setHeader("Content-disposition",
"attachment; filename="
+ URLEncoder.encode(myFile.getFileName(), "UTF-8"));
response.setHeader("Cache-Control",
"max-age=600");
ServletOutputStream outStream = response.getOutputStream();
outStream.write(myFile.getFileData());
outStream.flush();
//...
}





broken sudo user on ubuntu

18 01 2008

Today I broke my sudo access in ubuntu by removing my user account from: System > Administration > Users and Groups > Properties (button) > User Privileges (tab) > Administer the system (tick box).

I found a very useful article here which explains how to recover from the situation. Just in case the link is broken in the future here is a brief description of what to do:

The two important files are: /etc/sudoers and /etc/group

The /etc/group file will look like this:
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:firstuser
tty:x:5:
disk:x:6:
lp:x:7:cupsys
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:firstuser,cupsys
fax:x:21:
voice:x:22:
cdrom:x:24:firstuser,haldaemon
floppy:x:25:firstuser,haldaemon
tape:x:26:
sudo:x:27:
audio:x:29:firstuser
dip:x:30:firstuser
www-data:x:33:
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:
video:x:44:firstuser
sasl:x:45:
plugdev:x:46:firstuser,haldaemon
staff:x:50:
games:x:60:
users:x:100:
nogroup:x:65534:
dhcp:x:101:
syslog:x:102:
klog:x:103:
firstuser:x:1000:
lpadmin:x:104:firstuser
scanner:x:105:firstuser,cupsys
admin:x:106:firstuser
crontab:x:107:
ssh:x:108:
messagebus:x:109:
haldaemon:x:110:
slocate:x:111:

If your broken user is missing from the admin group /etc/group file then your sudo will be broken for this user because you have to be a member of this group in order to execute sudo commands.

Question:
But how do you edit this file if you can’t “sudo nano /etc/group” or “sudo vi /etc/group” ?
(because the file is owned by root)

Answer:
You must start ubuntu in “recovery” mode which will log you in as “root”.

Once logged in as root you will have permission to edit /etc/group or any other file on the system that has become corrupted.

Just add your username to the admin group (there is also a group called “adm”, but the “admin” group is the important one!) That’s it!