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)


regex code for "remove duplicate lines" in geany

if you have duplicate lines in a text file, in this format:
line 1
line 1
line 2
line 2

this regexp code will remove the duplicate lines:

search: (.*)\n\1
replace: \1\n

regular expression syntax for geany


uploading sf2 soundfont files to doesn't show the files on the item page

i uploaded a bunch of SF2 soundfonts to
Nickleus SF2 SoundFont Collection

but after the upload was finished, none of the files i had uploaded were shown on the main item page.

here's the archive support thread:

jeff kaplan found out that the mediatype needed to be set to software, because doesn't automatically recognize the SF2 file type for some reason.


java - are "ArrayList"s of String arrays (String[]) mutable? yes

I wanted to find out if an ArrayList of String arrays (String[]) was mutable or not and i found out that it is. Here's some test code to play with:

package com.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayMutationTest {

    public static void main(String[] args) {
        List<String[]> objList = new ArrayList<String[]>();
        String[] l1 = {"a",""};    // (K)ey, (V)alue
        String[] l2 = {"b",""};
        String csStringK = "a,b";    // (K)eys
        String csStringV = "1,2";    // (V)alues
        List<String> filterFieldKeys = Arrays.asList(csStringK.split("\\s*,\\s*"));
        List<String> filterFieldValues = Arrays.asList(csStringV.split("\\s*,\\s*"));

        for(Object[] ff : objList) {
            String filterKey = (String) ff[0];

            int i = filterFieldKeys.indexOf(filterKey);
            if(i != -1) {
                ff[1] = filterFieldValues.get(i);


after populating objList first, it looks like this:
["a", ""]
["b", ""]

after setting values in the for-loop it looks like this:
["a", "1"]
["b", "2"]


sony xperia ubuntu 13.04 usb not connected can't read storage sd card, but the phone charges

i tried stopping, killing and clear cache for all processes related to usb and mtp, but still couldn't get ubuntu to recognize my mobile cell phone.

then i went here on my sony xperia:
settings > wireless and network settings > tethering (but didn't do/click anything)

then after about 30 seconds the phone connected to ubuntu.... weird.

sometimes i get the following error message in ubuntu:
Unable to access “SEMC HSUSB Device”
Unable to open MTP device '[usb:003,003]'

quite the headache...

it seems like maybe this has something to do with it:

"most probably it’s a result of hardware failure rather than a driver or kernel bug. USB has an over-current protection, which gets triggered when power consumption from the port is too high.
Unplug all USB devices from PC, turn power off, and wait a minute or two. Plug everything back and boot into Linux."

java - how to find the number of days difference between two java.util.Date objects using core java api and not Joda Time

here's a method that calculates the number of days between 2 dates:

public static long getDateDiffInDays(Date date1, Date date2) {
  long diffInMillis = date2.getTime() - date1.getTime();
  return TimeUnit.MILLISECONDS.toDays(diffInMillis);

and here's some test code you can use:

public static void main(String[] args) {
  // today
  Calendar today = Calendar.getInstance();

  // tomorrow
  Calendar tomorrow = Calendar.getInstance();
  tomorrow.add(Calendar.DAY_OF_YEAR, 1);

  System.out.println(getDateDiffInDays(today.getTime(), tomorrow.getTime()));


In Calculating the Difference Between Two Java Date Instances there's a great, general method for getting differences between dates:

public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) {
  long diffInMillies = date2.getTime() - date1.getTime();
  return timeUnit.convert(diffInMillies,TimeUnit.MILLISECONDS);

and here's some test code:

public static void main(String[] args) {
  Calendar today = Calendar.getInstance();
  Calendar tomorrow = Calendar.getInstance();
  tomorrow.add(Calendar.DAY_OF_YEAR, 1);

  // Calculate the difference in days. OUTPUT: 1
  System.out.println(getDateDiff(today.getTime(), tomorrow.getTime(), TimeUnit.DAYS)); 

  // Calculate the difference in hours. OUTPUT: 24
  System.out.println(getDateDiff(today.getTime(), tomorrow.getTime(), TimeUnit.HOURS));

  // Now add 6 hours to "tomorrow"'s point in time
  tomorrow.add(Calendar.HOUR_OF_DAY, 6);

  // Calculate the difference in hours. OUTPUT: 30
  System.out.println(getDateDiff(today.getTime(), tomorrow.getTime(), TimeUnit.HOURS));

Here's a test class you can play around with:

Thanks also to:

milliseconds to days

Relevant Java API documentation:


[SOLVED] ejb3 jboss 7 postconstruct annotation not called/working

we had a weird problem where a @PostConstruct (javax.annotation.PostConstruct) annotation wasn't getting called in one of our ejbs.

we found out that the problem was some old ejb2 lifecycle methods needed to be removed from the java class:
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbCreate() {}

when we built the project again and restarted jboss, then @PostConstruct worked :)