Archive for 'programming' Category

« Previous PageNext Page »

[mysql] get top 10

16 August 2007

if you need top 10 rows from table ordered by point, you should use

SELECT * FROM table ORDER BY point LIMIT 10

No Comments »

[javascript] no compatibility of getElementById

10 August 2007

In IE, getElementById aquires element from name and id.
In firefox, getElementById aquires element from only id.

No Comments »

[css] difference between id and class

7 August 2007

id must be unique in a page. id is used by stylesheet, javascript and link tag.
We can specify an id using #.

class don’t need to be unique.
class is only used by stylesheet.

No Comments »

[java] How to increase runtime heap memory

20 July 2007

“mx” option can increase runtime heap memory.
If you need 256MB heap memory, command is

% java -Xmx256m ex.test.MainClass

No Comments »

[java] how to visualize hprof file

19 July 2007

JDK 6.0 has jhat, which is web visualization tool for hprof.
jhat is placed in “java/jdk1.6.0_XX/bin/”.

To use jhat, you have to output binary hprof file by “format=b” option of hprof.

% java -Xrunhprof:format=b ex.test.MainClass

Output file is “java.hprof”.
When you run

% jhat java.hprof

you can view hprof file from http://localhost:7000/.
This html file is more understandable than text hprof file.

No Comments »

[java] how to detect memory leak

19 July 2007

hprof is the most convinient way.
You must add “-Xrunhprof” to java VM.
For example, when you would like to trace “ex.test.MainClass”, a command is

% java -Xrunhprof ex.test.MainClass

hprof makes java.hprof.txt.
You can get heap, class, reference information, etc, from the file.

No Comments »

[prefuse] memory leak

17 July 2007

Prefuse leaks much memory while graph creation/deletion.
It seems that prefuse doesn’t assume frequent graph creation/deletion.

I had to modify the prefuse’s source code to fix it.
Followings are the points of leaking.

  • Display.m_offscreen (have to be null)
  • Display.m_queue (have to be null)
  • Graph.m_links (see Table)
  • Graph.m_listener
  • Graph.m_listeners
  • Table.m_listeners
  • Table.m_entries
  • Table.m_columns
  • Table.m_names
  • Visualization.m_visual
  • Visualization.m_source
  • This is why I hate Java.
    Some java programmers don’t realize java can leak memory.
    Some of them don’t know what is destractor.
    I think criminal is sun.

    No Comments »

    [java] rotating drawString

    11 July 2007

    1. move to pint(100,100).

    g.translate(+100, +100);

    2. rotate 270 degrees.

    r = 270.0;
    g.rotate(Math.PI * r / 180.0);

    3. draw string.

    g.drawString("hello world", 0, 0);

    4. rotate 90 degrees.

    r = 90.0;
    g.rotate(Math.PI * r / 180.0);

    5. move to point(-100, -100)

    g.translate(-100, -100);

    No Comments »

    [prefuse] how to extend Graph dataset

    5 July 2007

    prefuse.Visualization is not good because it has Graph and Tree depending codes. I have confesed about “m_vis.add("tree", g);“. Graph or Tree depending codes should be implemented at extend of prefuse.Visualization like prefuse.GraphVisualization.

    Anyway, I found a way to extend Graph dataset.

    1. create new Table, and add data to the Table.

    Table tb = new Table();
    tb.addColumn("key", int.class, new Integer(-1));
    tb.addColumn("text", String.class, "[No Message]");

    Tuple t = tb.getTuple(tb.addRow());
    t.set("key", i);
    t.setString("text", "sample message");

    2. create Graph and put Table to the Graph.

    Graph g = new Graph(true);
    g.addSet("message", tb);

    3. add Graph and Table to Visualization.

    vis = new Visualization();

    vis.add("tree", g);
    vis.add("message", g.getSet("message"));

    No Comments »

    [prefuse] color animation

    4 July 2007

    1. make animator action list

    ActionList animate_color = new ActionList(500);
    animate_color.add(new ColorAnimator("tree.nodes"));
    animate_color.add(new RepaintAction());
    m_vis.putAction("animate_color", animate_color);

    2. set startFillColor

    item.setStartFillColor(Color.black.getRGB());

    3. set FillColor = startFillColor

    item.setFillColor(Color.black.getRGB());

    4. set endFillColor

    item.setEndFillColor(Color.white.getRGB());

    5. run ColorAnimator

    m_vis.run("animate_color");

    6. color will be chaninging gradually from black to white in 500ms.

    No Comments »

    « Previous PageNext Page »