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)


how to install minecraft on ubuntu 12.04

install these: openjdk-7-jre icedtea-7-plugin
then do what that post says


regexp examples for eclipse that match specific html/jsf tag and attribute names and also parsing java code

been working for hours on a regex to match all instances of a specific jsf tag name with a specific attribute name, practically getting an ulcer, and i finally figured out a simple solution:

if TAG_NAME == convertDateTime
if ATTRIBUTE_NAME == locale

then it will match e.g.:
<f:convertDateTime type="both" dateStyle="short"
"en" timeZone="Europe/Oslo" />


<f:convertDateTime locale="#{myBean.localeString}" type="date" dateStyle="medium" timeZone="Europe/Oslo" />

this means no tag-close character, because we don't want matches like this:
<f:convertDateTime type="both" dateStyle="short" timeZone="Europe/Oslo" />
<rich:calendar locale="en" datePattern="dd.MM.yyyy"...

we want to stop the searching/matching at the end of the f:convertDateTime tag:
<f:convertDateTime type="both" dateStyle="short" timeZone="Europe/Oslo" />
<rich:calendar locale="en" datePattern="dd.MM.yyyy"...

this means that 0 or more whitespace can be between the ATTRIBUTE_NAME and the equals sign. e.g. this would also get matched:
<f:convertDateTime locale   ="#{myBean.localeString}" type="date" dateStyle="medium" timeZone="Europe/Oslo" />

i couldn't find this solution anywhere and was surprised to find so few asking for it, but lots of people writing things like "you can't use regular expressions to parse html" (a post on Stack Overflow that got 4432 positive votes!).

here's a regexp that works in eclipse for finding a tag WITHOUT a specific attribute (i've tested it):


here's an example of regexp search and replace in eclipse that uses grouping and back references for rich:calendar tags with locale attribute that either have a normal hardcoded text string value (e.g. "en") OR a backing/managed bean expression value (e.g. "#{someBean.someValue}") OR empty value (""):
replace with:

this inserts the Locale value returned from MyBean.getUsersLocale()

this means to match everything (0 matches to infinity) that isn't a ", i.e. stop matching once you reach the locale attribute's closing quote, ", e.g.:
<rich:calendar value="#{myBean.toDate}"  requiredMessage="required"
so the whole regex would match (everything in bold) e.g.:
<rich:calendar value="#{myBean.toDate}"  requiredMessage="required"
and the text with green background denotes the first back reference (\1) group, i.e.:
the enclosing parentheses ( and ) denote a grouping, so everything inside those parentheses that matches gets saved and pasted back into the result, using a backreference, e.g.: \1
for the first back reference, \2 for the second back reference/grouping, etc, e.g.:
replace with:

which would result in:


here's one that finds all elements with a locale attribute that doesn't have the value "#{myBean.usersLocale}":

means match text that ISN'T equal to XXX, and don't create a back reference for it--denoted by the question mark, ?

would mean: match text that IS equal to XXX, and don't create a back reference for it


someone had coded f:converter tags with a locale attribute, e.g.:
<f:converter locale="#{myBean.localeString}"
converterId="CustomIntConverter" />

so i needed a regex to delete all these locale attributes from all f:converter tags because locale isn't supported in this tag--not in jsf 1.2, 2.0 or 2.1! (however it is supported for related tags like f:convertDateTime and f:convertNumber)

here's the regex search:

and replace with:

i.e. keep everything that matched up until the locale attribute, and delete the locale attribute and its quoted value.


my next problem was finding all jsf tags that use some pageProps OR pageProperties class objects to get a property value and replace all references to such java classes with a standard resource bundle variable, msg, while at the same time keeping and reusing the properties label string value--yes, all in one search and replace!

so, i have code lines like this:
value="#{myBean.isBuyer ? myBean.pageProps.getPropertyValue('label.deviation.buyerdetails',  myBean.locale) : myBean.pageProps.getPropertyValue('label.deviation.transporterdetails',  myBean.locale)}"
value="#{myOtherBean.pageProperties.propertyValue('label.deviation.buyerdetails',  myBean.locale)}"

but i also have lines like this, that i don't want to match:
timeZone="#{myOtherBean.pageProperties.timeZone}" />

i want the resulting lines to look like this:
value="#{myBean.isBuyer ? msg['label.deviation.buyerdetails'] : msg['label.deviation.transporterdetails']}"

to do this, i use a regexp search like this, in eclipse:
replace with:

##########SORT OF UNSOLVED MYSTERY ###############

here i have a java method:
    private String getPropertyValue(String property) {
        if(props == null)
            props = new RBUtils(Locale.ENGLISH, null);
        return RBUtils.getString(property, null, null);

i want to find all java methods with that specific name and remove all lines before the return statement, like this:
    private String getPropertyValue(String property) {
        return RBUtils.getString(property, null, null);

here's the regexp that took me about an hour to come up with:
search for:
replace with:

matches any character

\n is just to place a newline in front of the return statement.

? is to stop greediness and force laziness.

this one will "fail" if you have the following code:
    private String getPropertyValue(String property){
        String s= RBUtils.getString(property, null, null);
        return s;

    public String getPropertyLabelValue(String property){
        return RBUtils
.getString("label."+property, null, null);

so i need to figure out how to stop the matching at the end of the method. one idea i have is to stop it at a public OR private, i.e. if it hasn't matched before it reaches a "public" or "private" string, then it's not a match.

let's try to put to words exactly what i want:
* i want to match within a method with the following signature:
String getPropertyValue(String name)

where name can be any string: \w+
and the preceding text is a string literal: (String\s+getPropertyValue\s*\(\s*String\s+)

so the whole first line is:

the surrounding parentheses are a grouping, so we can save that text and reinsert it in the replace action by using what is called a backreference, like this:

to end the matching at the end of the method is quite difficult though, if not impossible, illustrated by the following examples.

one way is to stop the matching at the first instance of a private or public:
    private String getPropertyValue(String property){
        String s= RBUtils.getString(property, null, null);
        return s;

    public ...

(note: this doesn't match because we didn't find "return RBUtils")

but if you have the following code:
    private String getPropertyValue(String property){
        String s= RBUtils.getString(property, null, null);
        return s;
} // end of the java class

there is no method after the method we're interested in--the class ends. one solution would be to somehow count the number of curly braces and stop at the last "}". i don't know how to do that or if that's possible, so someone please let me know =)

what i originally, specifically wanted was to match the following:
    private String getPropertyValue(String property) {
        if(props == null)
            props = new RBUtils(Locale.ENGLISH, null);
        return RBUtils.getString(property, null, null);

so to solve this specific problem (instead of finding all methods with that signature and erasing any variation of code before the return statement--which currently seems impossible) i need to use the following regex:
(String\ +getPropertyValue\ *\(\ *String.+\s)(?:.+props.+\s){2}(.+\s.+\})
replace with:

(?:          //group, but don't make a backreference
.+props.+\s          //match a whole line, including the newline (\s) that contains  "props"
)          //end grouping
{2}          //match that "props" line max 2 times

(.+\s.+\})          //match the whole "return" line, plus the line with the method-closing curly brace and put all this into a group, so we can backreference this second group with \2


today's fun example, 20120928, was about me figuring out that you can't use a "+" sign to dynamically concatenate label text and then get that label property value from a properties file. luckily i found this post that told me i could use EL 2.2's concat functionality.

so i need to convert all instances of this kind of JSF code:
to this:
search for:
replace with:

UPDATE 20131119

this regex searches for primefaces tags that have an update attribute, but are missing an update id for growl:

UPDATE 20131211

after migrating from richfaces to primefaces, i needed to remove all calendar attributes called "verticalOffset" (valid in rich:calendar, but not in p:calendar):


replace with:


how to setup a syslog (rsyslog) server on an ubuntu machine to log d-link DIR-655 router logs


enable sending router syslogs to myserver (Tools > Syslog):

put a checkmark next to Enable Logging To Syslog Server

Syslog Server IP Address is currently myserver:

// on the syslog server

install rsyslog:
sudo apt-get install rsyslog

edit the main rsyslog config file:
sudo nano -w /etc/rsyslog.conf
make sure the following lines are uncommented:
$ModLoad imudp
$UDPServerRun 514

$ModLoad imtcp
$InputTCPServerRun 514

in order to get dynamic log file naming to work, make sure these lines are commented out:
#$PrivDropToUser syslog
#$PrivDropToGroup syslog

before i figured out that last tip, dynamic file names using template was not working. if those 2 lines aren't commented out, then there becomes a permissions issue, and use of template won't work (see below)

edit the default rsyslog config file:
sudo nano -w /etc/rsyslog.d/50-default.conf

add the following lines at the very top:
$template DynFile,"/var/log/myrouter/%$year%%$month%%$day%.log"
:fromhost-ip, isequal, "" ?DynFile
:fromhost-ip, isequal, "" ~ is the router ip address

the bottom line means log nothing (~) after this line for any messages from host ip (i.e. the logging rules specified after this line only apply to messages from the localhost)

then restart the rsyslog service:
sudo service rsyslog restart

you will shortly begin to see router log files appearing here:

with filenames in the following format:



eclipse jboss launch configuration delete jboss tmp folders (data, log, work, tmp)

there doesn't seem to be any way to do this in eclipse's launch configuration for jboss, so i do this in my ant build.xml script instead:
<target name="jbossCleanup" description="remove jboss tmp folders">
    <property name="jbossServerDir" value="${jboss.server.dir}/${jboss.domain}"/>
    <delete dir="${jbossServerDir}/log" quiet="true"/>
    <delete dir="${jbossServerDir}/tmp" quiet="true"/>
    <delete dir="${jbossServerDir}/work" quiet="true"/>
    <delete dir="${jbossServerDir}/data" quiet="true"/>

then i include this target name as the first depends target in the main build target:
<target name="noCheckoutNoCompile" depends="jbossCleanup,clean,...

keep it simple stupid!

"just put some vinegar on it. why didn't you think of that?"
--dr. steve brule


bash regex/regexp how to remove all lines from file not matching specific text string

after struggling in the geany editor to get regex to work, i tried a different approach.

say you have a file, test.txt, with the following content:
menu2.getChildren().add(createMenuItem("none", userNorwegian ? ...
menu2.getChildren().add(createMenuItem("none", userEnglish ? ...
menu2.getChildren().add(createMenuItem("none", userNorwegian ? ...
menu2.getChildren().add(createMenuItem("none", userEnglish ? ...

but you only want a file with the lines containing the string userNorwegian, i.e. you want to remove the lines containing userEnglish.

open a terminal and run this:
sed -n 's/userNorwegian/userNorwegian/p' test.txt > out.txt

-n means:
suppress automatic printing of pattern space

p means:
Print the current pattern space.

keep it simple, stupid! ;)

thanks for the idea here:

MW3: which multiplayer playlist to use to get the Dome map

Team Deathmatch is at least one multiplayer playlist you can use to get the Dome map.


ubuntu: dont need to "exit" from terminal anymore to save bash history

when did ubuntu change things so that we don't need to type "exit" anymore in the terminal in order to save the most recent commands in bash history? quite useful, and bash_history isn't full of "exit" lines either now =)


toad sql extension eclipse plugin

in ubuntu linux, i've traditionally used squirrel as my sql client, but alternatively to installing squirrel, toad has a free plugin for eclipse that seems to work, called toad extension:
help > eclipse marketplace > toad

inline web statistics for blogger posts

one cool reason for using blogger is that if you go into your Posts view in your dashboard, you can see how many page views each of your posts has received =)

ubuntu linux bash command of the day

export your hardware configuration as a html file:
sudo lshw -html > hardware.html


description: Notebook
product: VPCSE2V9E (N/A)
vendor: Sony Corporation
version: C60A6XQR
serial: 27553856-5000146
width: 64 bits
capabilities: smbios-2.6 dmi-2.6 vsyscall32


display amount of free and used memory in the system, in gigabytes:
free -g


             total       used       free     shared    buffers     cached
Mem:             7          3          4          0          0          1
-/+ buffers/cache:          2          5
Swap:            7          0          7



how to do a clean install of eclipse

The following works for Eclipse Juno.

download the source

click Eclipse IDE for Java EE Developers > Linux 64-bitwe install eclipse manually to get the latest and best version. sometimes the ubuntu package manager isn't updated with the latest version.

unzip the file

configure eclipse.ini for svn

open a terminal and install the following (needed for the JavaHL plugin):
sudo apt-get install libsvn-java

find the path where the JavaHL library is installed (in your terminal window):
sudo find / -name

open eclipse.ini and set the java.library.path with the value from the above "find" command, e.g.:


set file encoding to UTF-8

window > preferences > general > content types > expand "Text" and everything under it.

In Eclipse Juno, the following file types need to be changed from ISO-8859-1 to UTF-8(Find the value, select it, then at the bottom, change Default Encoding, then click Update)
Java Properties
JSP > JSP Fragment
JSP > JSP Tag Definition
JSP > JSP Tag Definition > XML JSP Tag Definition

show line numbers
Windows > Preferences > General > Editors > Text Editors > checkmark the “Show line numbers” option

configure your package view
the default view is Package Explorer, but it shows you a lot of unecessary things like jars, etc. set your view to Navigator:
window > show view > navigator

click the "Link with editor" icon (2 vertical arrows pointing in opposite directions). this will highlight your file in the Navigator so you immediately see where it is.

configure Eclipse's Console
right click anywhere in the Console tab > Preferences > remove the checkmark by Limit console output

disable unnecessary validators (sometimes they take a lot of time)
preferences > validation
click disable all
then enable the following:
classpath dependency validator

don't reuse editors
it's annoying when you want to open a file in search (or compare in team synchronizing view) and you lose the previous file you were looking at because eclipse, by default, will reuse editor windows. to fix this:
Windows > Preferences > General > Search
uncheck Reuse editors to show matches