Skip to content


Qt Jambi – ListView with checkbox

Was looking for a way to add check boxes to ListViews on Qt Jambi, and a lot of the solutions came up way too complicated than what needs to be.

The following code would add an item with a checkbox to a ListViewWidget (Not a model based listview)

QListWidgetItem item = new QListWidgetItem("test1");
item.setFlags(ItemFlag.ItemIsUserCheckable, ItemFlag.ItemIsEnabled);
item.setCheckState(CheckState.Checked);
list.addItem(item);

 

To read from the list, a quick way is

int count = list.count();

for (int i=; i<count; i++) {
list.item(i).checkState() == CheckState.Checked

}

Posted in Java, Qt. Tagged with , , , , .

Clearing paragraph border in Word 2010

Annoyingly Word 2010 seems to like to convert certain symbols into these double line “Paragraph borders” that I do not know how to get rid of (or even how to put it in in the first place).

To get rid of these, highlight the lines around the border, and click the clear formatting button.

Posted in Technology. Tagged with , .

Using an SSD as the System Drive, tweaks

So just installed a new 240GB SSD (OCZ Agility 3), lets hope this one lasts a while.

Anyway, there are a number of tweaks that should be done for the new SSD

System (Thanks to http://www.ocztechnologyforum.com/forum/showthread.php?63273-*-Windows-7-Ultimate-Tweaks-amp-Utilities-*):

I’m only summarizing here the ones I personally think are necessary, some of the tweaks suggested there don’t make a whole lot of sense

  • Change Power setting to never turn off SSD
  • Change # of processors Windows use to start up to the # of cores
  • Disable unneeded services (DO NOT disable Application Experience service)
  • Disable Indexing
  • Disable defragmentation (remember to manually defragment the old mechanical disks that may still be in use)
  • Turn off Superfetch
  • Turn off Prefetch
  • Disable Page File
  • Disable Hibernate
  • Disable System restore
  • Enable TRIM commands
  • Edit the size of all recycle bins

Firefox and Chrome:

  • Firefox can be made to run off Memory, google for latest instructions
  • Chrome at the moment of writing cannot use memory cache, so we need to change the cache location. Google for the latest instructions
  • Make sure all shortcuts and all path to opening Chrome (all the shortcuts, keyboard links) open the updated link with new cache location
  • Set default browser to Firefox (otherwise the default application triggered Chrome creates a cache again on the SSD)
  • Set a reminder to check the cache location once in a while

iTunes:

  • Copy the iTunes folder from My Music to another disk (not a SSD)
  • Hold shift and start iTunes, it will ask you to pick a library, pick the new one
  • In Advanced options, set the new Media Library path to the new location also

Posted in Technology. Tagged with , .

Putting an image into the iPhone emulator’s photo library

Recently started looking at iOS development. I have to say I’m not a fan of Object-C, but xcode I really like.

Anyway, to have a test image in the Photo Library on the emulator, the simplest way is probably just open Safari on the emulator and save an image

  1. Find image
  2. Hold mouse click on the image (this is the same as a hold gesture on the actual phone)
  3. Save

Posted in iOS. Tagged with , .

Securing Dreamhost’s Trac install

Dreamhost has finally implemented the one click install of Trac a while ago (so we no longer have to go through a very long process to install a trac). It is done through FastCGI, and it start with no Authentication configured.

To setup authentication, simply use the .htaccess Auth in /trac install directory (the full path would be given by the email Dreamhost sends out on successful setup of Trac, when it tells you to change the trac.ini file)

Posted in Technology. Tagged with , .

iOS 5 update and Error 3194 and Jailbroken iPhone

If you have a jailbroken iPhone and the jailbreaking was done with the same computer that you are trying to update the firmware from, then you may get a error 3194 when iTunes tries to verify the firmware version. To solve this:

  • Open C:\Windows\System32\drivers\etc\hosts with notepad
  • See if there are any lines in there that contains a reference to gs.apple.com
  • Put a ‘#’ (without quote) in front of such line(s)
  • Try updating again

Posted in Technology. Tagged with , .

Regex lazy match

Thought I’d write about the Regex lazy match here while I still have it in a explainable state in my mind…

For example, consider the string:

[test string] [test string]

With the regex:

\[.+\]

The + operator is greedy, and will attempt to match as much text as possible, which would produce a single match group containing [test string] [test string]

To stop this behavior, use the lazy plus: +?

\[.+?\]

This produces two match groups: [test string] [test string]

 

Posted in Information, Java. Tagged with , .

Java and Regex – By Example

Going to quickly outline how to use Regex in Java by example. We are trying to parse the following content to extract underlined content into different variables for each line, while ignoring comment lines:

;MATFile=align_merge.mat
;this is a comment
;labeled data
AAA=[14762.800000 14778.793750]
BBB=[16400.800000 16477.793750]
CCC=[18240.800000 18403.793750]

Regex:

^(?!\;)(.+?)\=\[([0-9.]+)\ ([0-9.]+)\]

  • ^(?!\;) – Line does not start with ; (?! is the negate operator)
  • (.+?)\= – Lazy match all characters before the = sign
  • \[([0-9.]+)\ ([0-9.]+)\] capture the two groups of 0-9 and decimal point (where applicable)
Java code fragments:

private Pattern regexLabel = Pattern.compile("^(?!\\;)(.+?)\\=\\[([0-9.]+)\\ ([0-9.]+)\\]");

Matcher m = regexLabel.matcher(line);
if (m.matches()) {
    String label = m.group(1);
    Double start= new Double(m.group(2));
    Double end = new Double(m.group(3));
  • Nothing really major, other than group 0 is always the whole matched string

Posted in Java. Tagged with , , .

MATLAB JA Builder and Java (Eclipse)

I just started using the MATLAB’s JA Builder for some maths heavy libraries, and there were some points worth noting, especially when trying to use the final jar file with Eclipse:

  • Make sure the system’s language locale is set on English (you will get strange characters in the compiler log window otherwise)
  • Make sure to actually install a JDK (otherwise you get the obvious javac.exe not found error on the compiler)
  • Run MATLAB with the same JRE that Eclipse is using. This is important, as otherwise whenever you try to debug the code in Eclipse you will get EXCEPTION_ACCESS_VIOLATION
To set the MATLAB’s Java version, set a MATLAB_JAVA environment variable. The variable just need to be set to the jre directory (not the \bin directory)

Posted in Java. Tagged with , , , .

Java initializer block

Had a discussion about java initializer blocks with a friend a while back, and thought I’d summarize some of the points here, along with tested code examples.

Static Initializer

public class initializerTest {

    private final static String var1;
    private static String var2;

    static {
        var1 = "test";
        var2 = "a";

        System.out.println("hello");
        initializerTest t = new initializerTest();
    }

    public initializerTest() {
        System.out.println(var1);
        System.out.println(var2);
    }
}

Output:

hello
test
a
test
a
  • Can initialize final variables
  • Can run code
  • Can instantiate classes
  • Initializer blocks run before constructors
The output seen here is produced (in order) by:
  1. Initializer is run when the class definition is loaded, and hello is printed out
  2. Initializer instances a copy of initializerTest, which causes the constructor to print test\n a
  3. The main method that instanced a copy of initializerTest has the object’s constructor called, resulting in another test\n a
Non-static initializer
Of course the same block works without the static keyword, and works as a non-static initializer
Exception handling
Error: Unhandled exception, Initializer does not exit normally
{
    throw new Exception("this is checked");
}
Error: Initializer does not exit normally
{
    throw new RuntimeException("this is unchecked");
}
No errors:
{
    try {
        if (var1.equals("a"))
            throw new Exception("this is checked");
    } catch (Exception e) {
        //do nothing
    }
}
{
    if (var1.equals("a"))
        throw new RuntimeException("this is checked");
}
  • Initializer block must exit normally (no unhandled checked exception)
  • Unchecked exceptions can be thrown

Posted in Java. Tagged with , , .