Monthly Archives: June 2007

QT Jambi

I just tested QT Jambi. It is cool of QT widgets in Java. I like it. And it is very fast and the QT Designer is good but not as good as WindowBuilder Pro‘s SWT Designer, IMO.

But there is a nasty bug for QT Jambi integration with Eclipse. QT Jambi will add a com.trolltech.qtjambi.juicBuilder to each projects in my workspace. And these modifications will mark all of my projects as SVN modified. I have to disable it and restore all my .project files! This bug is really nasty!

Posted in Jambi, QT | Comments Off on QT Jambi

Failed to Download Files from FTP Servers

Today, I came across a problem: I could not download files given by “ftp://…”. I could ping that server, but could not link to it. I was using FlashGet and I tried to change some preferences but didn’t work. At last I turned off my Windows XP’s firewall and downloading worked at once. At later, I re-open the firewall and add my FlashGet or Filezilla to the trusted applications list.

Posted in Tricks | Comments Off on Failed to Download Files from FTP Servers

Why Java Web Start Sucks

Just have a long waiting time for downloading the *.jar files, and always it comes to a security dialog notifying that the *.jar file is not signed or not signed by known CA while it requires unlimited local access and remote connection access!

How can I accept “Unlimited local access and remote connection access” for unknown *.jar application! Java Applet or Java Web Start really sucks.

Posted in Java | Comments Off on Why Java Web Start Sucks

Subversive Sucks

There are many bugs in Subversive besides the known bug “Can not compare with old deleted repository resources“.

And yesterday, one of my colleague used Subversive’s “Check out as” to a different location resulted in deleting all her one-week modifications. I think it was a bug that Subversive did not warn her that it was going to delete modified sources in “Check out as” mode!

In my experience, I found Subclipse is a much better plugin. So Subversive sucks.

Posted in Bug Fix, Eclipse, Subversive | 2 Comments

Add Source Highlighting to WordPress Editor

If you are a technical geek, you may want to write some blog articles attaching some sources for discussion. And if you are using WordPress, you may find a lot of difficulties in struggling with WordPress’ messy TinyMCE editor in preserving codes format.

Thanks for early WordPress bloggers, there are some plugins trying to solve this problem. A known plugin is “Preserve Code Formatting“. But that plugin may be not good enough for you, at least not good enough for me.

I modify that plugin a little, and deploy it in my WordPress 2.2. And I also add my own source syntax highlighting tools.

Here is my modified preserve-code-formatting.php:

<?php
/*
Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

function c2c_prep_code( $text ) {
$use_nbsp_for_spaces = false;

$text = preg_replace("/(\r\n|\n|\r)/", "\n", $text);
$text = preg_replace("/\n\n+/", "\n\n", $text);
$text = str_replace(array("&#36&;", "&#39&;"), array("$", "'"), $text);
//$text = htmlspecialchars($text, ENT_QUOTES);
$text = preg_replace("/\n\s+\n/", "\n&#160;\n", $text);
$text = str_replace("\t", ' ', $text);
if ($use_nbsp_for_spaces) $text = str_replace(' ', '&#160;&#160;', $text);
// Change other special characters before wptexturize() gets to them
$text = c2c_anti_wptexturize($text);
//$text = nl2br($text);
return $text;
} //end c2c_prep_code()

// This short-circuits wptexturize process by making ASCII substitutions before wptexturize sees the text
function c2c_anti_wptexturize( $text ) {
$text = str_replace('---', '&#45;&#45;-', $text);
$text = str_replace('--', '&#45;-', $text);
$text = str_replace('...', '&#46;..', $text);
$text = str_replace('``', '&#96;`', $text);

// This is a hack, look at this more later. It works pretty well though.
$cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round");
$cockneyreplace = array("&#39;tain&#39;t","&#39;twere","&#39;twas","&#39;tis","&#39;twill","&#39;til","&#39;bout","&#39;nuff","&#39;round");
$text = str_replace($cockney, $cockneyreplace, $text);

$text = preg_replace("/'s/", '&#39;s', $text);
$text = preg_replace("/'(\d\d(?:&#8217;|')?s)/", "&#39;$1", $text);
$text = preg_replace('/(\s|\A|")\'/', '$1&#39;', $text);
// $text = preg_replace('/(\d+)"/', '$1"', $text);
$text = preg_replace("/(\d+)'/", '$1&#39;', $text);
$text = preg_replace("/(\S)'([^'\s])/", "$1&#39;$2", $text);
// $text = preg_replace('/(\s|\A)"(?!\s)/', '$1"$2', $text);
// $text = preg_replace('/"(\s|\S|\Z)/', '"$1', $text);
$text = preg_replace("/'([\s.]|\Z)/", '&#39;$1', $text);
$text = preg_replace("/ \(tm\)/i", ' &#40;tm)', $text);
$text = str_replace("''", '&#39;&#39;', $text);

$text = preg_replace('/(d+)x(\d+)/', "$1&#120;$2", $text);

$text = str_replace("\n\n", "\n&#160;\n", $text);
return $text;
} //end c2c_anti_wptexturize()

function c2c_preserve_code_formatting( $text ) {
$text = str_replace(array('$', "'"), array('&#36&;', '&#39&;'), $text);
$tags = array('code', 'pre');
foreach ($tags as $tag) {
$text = preg_replace(
"^(<$tag>)\n?([\S|\s]*?)\n?(</$tag>)^ie",
"'<$tag>' . c2c_prep_code(\"$2\") . '</$tag>'",
$text
);
}
$text = str_replace(array('&#36&;', '&#39&;'), array('$', "'"), $text);
return $text;
} //end c2c_preserve_code_formatting()

add_filter('the_content', 'c2c_preserve_code_formatting', 9);
add_filter('the_excerpt', 'c2c_preserve_code_formatting', 9);
// Comment out this next line if you don't want to allow preserve code formatting for comments.
add_filter('get_comment_text', 'c2c_preserve_code_formatting', 9);

?>

And here is my css style:

.code {
overflow:scroll;
overflow-y:hidden;
background-color:#f0f0f0;
}

code {
white-space: pre;
color: #222;
}

.keyword {
color:blue;
}
.api {
color:navy;
font-weight:bold;
}
.scope {
color:#f0f;
}
.string {
color:green;
}
.comment {
color:#777;
}
.tag {
color:#f70;
}

And here is the instruction to add my source highlighting when editing:
1. Go to visit http://demo.java2script.org/syntaxor/ , and you can highlight your sources there;
2. Copy the link at left upper corner, which started by a blue block;
3. Bookmark any page, and then modify the bookmark’s URL property to the above link location (a “javascript:” link to load source syntax highlighting);
4. Try to write or edit a post in browser, and then click the above bookmarked link, and the same source highlighting application window shows up after a while, try to paste your highlighted HTML source in the wordpress’ TinyMCE editor.

Posted in Blog Tips, Java2Script, Wordpress | Comments Off on Add Source Highlighting to WordPress Editor

Get Projects List in Eclipse Workbench

http://dev.eclipse.org/newslists/news.eclipse.newcomer/msg13300.html

Add
org.eclipse.core.resources
in the Require-Bundle section in your plugin MANIFEST.MF file
and invoke code:

ResourcesPlugin.getWorkspace().getRoot().getProjects()

Posted in Eclipse, Java, Tricks | Comments Off on Get Projects List in Eclipse Workbench

Clean Eclipse Plugins’ Build Path Errors

Sometimes, Eclipse may have errors in calculating build paths, which may result in that some projects are marked as red cross error icons and further building is interrupted. The common error message for this would be “Project … is missing required project …”.

Try to check out and make sure that there are no errors. But try to clean and rebuilt the project do not clean out that error mark? Please try to close the project, and then re-open it, clean and rebuilt the project. It may help.

Posted in Eclipse, Tricks | Comments Off on Clean Eclipse Plugins’ Build Path Errors

Enablement Expression and Property Tester

Source: http://www.eclipse.org/webtools/wst/components/server/runOnServer.html

Enablement Expression Performance

Enablement expressions allow you to create arbitrarily complex expressions using ands, ors, nots, and Java code. For performance reasons, it’s always better to use the expression support instead of using Java code, which is slower or may be in plugins that aren’t loaded yet. However, simple Java tests can provide much better flexibility and do not need to cause large delays.

The best practice is to use enablement expressions as much as possible to filter down the number and types of objects that are applicable. As a final check, a property tester can then be used. However, it is still important to use expressions first, even if you know you’ll be using a property tester for the last check – this will keep the performance up for all the objects that are filtered out.

Adding a Property Tester

To add a property tester to an enablement expression, try using the following example. In your plugin.xml, add the propertyTesters extension point:

<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
id="org.eclipse.myplugin.propertyTester"
namespace="org.eclipse.myplugin"
properties="someProperty"
type="java.lang.Object"
class="org.eclipse.myplugin.internal.MyPropertyTester">
</propertyTester>
</extension>

Inside your plugin, add and implement the property tester code:

package org.eclipse.myplugin.internal;
import org.eclipse.core.expressions.PropertyTester;

public class MyPropertyTester extends PropertyTester {
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
// cast receiver and/or expectedValue
// if (xx) // check some dynamic property
return true;
// else
//return false;
}
}

You can now use a property expression within the enablement:

<test property="org.eclipse.myplugin.someProperty" value="true"/>

Posted in Eclipse, Tricks | Comments Off on Enablement Expression and Property Tester

Pin Your Firefox Favorite Tabs

I always have many tabs (10+) open. I found that I was switching to some of tabs, like GMail, from time to time. In cases, I have to click tabs’ drop-down button on the upper right corner, and select them from the pop-up menu.

If possible, I would like to manage a list of my favorite tabs and pin them on the left of tab bar if they are open.

Posted in Uncategorized | 2 Comments

Create a Process and Read Its Output

This is a snippet of windows C++ code to create a process and read its output until some specific string is printed. This is useful for programmer to start a server and only to return until the server is started, as sometimes server may take some seconds to initialize.

BOOL CreateProcessAndWait(char* cmdline, int flag,
STARTUPINFO *si, PROCESS_INFORMATION *pi,
const char* keyString)
{
HANDLE hOutputReadTmp,hOutputRead,hOutputWrite;
HANDLE hErrorWrite;
SECURITY_ATTRIBUTES sa;

// Set up the security attributes struct.
sa.nLength= sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;

// Create the child output pipe.
if (!CreatePipe(&hOutputReadTmp, &hOutputWrite, &sa,0)) {
printf("CreatePipe\n");
}
// closes one of its std output handles.
if (!DuplicateHandle(GetCurrentProcess(),hOutputWrite,
GetCurrentProcess(),&hErrorWrite,0,
TRUE,DUPLICATE_SAME_ACCESS))
printf("DuplicateHandle");
// Create new output read handle and the input write handles.
// Set the Properties to FALSE. Otherwise, the child inherits
// the properties and, as a result, non-closeable handles to
// the pipes are created.
if (!DuplicateHandle(GetCurrentProcess(),hOutputReadTmp,
GetCurrentProcess(),
&hOutputRead, // Address of new handle.
0,FALSE, // Make it uninheritable.
DUPLICATE_SAME_ACCESS))
printf("DupliateHandle");

ZeroMemory(si, sizeof(STARTUPINFO));
si-&gt;cb = sizeof(STARTUPINFO);
ZeroMemory(pi, sizeof(PROCESS_INFORMATION));
flag = CREATE_NEW_PROCESS_GROUP | flag;
si->dwYCountChars = 5000;
si->dwFlags |= STARTF_USECOUNTCHARS;
si->dwFlags |= STARTF_USESTDHANDLES;
si->hStdOutput = hOutputWrite;
si->hStdError = hErrorWrite;

int ret = CreateProcess(NULL,
cmdline, /* command line */
NULL, /* Security */
NULL, /* thread */
TRUE, /* inherit handles */
flag, /* start flags */
NULL, /* winenv, */
NULL, /* current directory */
si, pi);
if (ret != -1)
{
CHAR lpBuffer[256];
DWORD nBytesRead;
DWORD keyLength = strlen(keyString);
DWORD index = 0;
memset(lpBuffer, 0, sizeof(lpBuffer));

DWORD dwTimeoutThreadId;
HANDLE hTimeoutThread = CreateThread(
NULL, // no security attribute
0, // stack size, BUGBUG:Try to use the limit size!
(LPTHREAD_START_ROUTINE) TimeoutThread,
(LPVOID) pi->hProcess, // thread parameter
0, // not suspended
&dwTimeoutThreadId); // returns thread ID

if (hTimeoutThread == NULL)
{
printf("No time out thread for specific string %s.\n",
keyString);
}
else CloseHandle(hTimeoutThread);

while(TRUE)
{
if (ReadFile(hOutputRead,lpBuffer + index,
sizeof(lpBuffer) - index,
&nBytesRead,NULL) && nBytesRead)
{
if ((index + nBytesRead >= keyLength)
&& strstr(lpBuffer, keyString))
{
break;
}
if (index + nBytesRead > sizeof(lpBuffer)
- keyLength) {
// move
for (DWORD i = 0; i < keyLength; i++) {
lpBuffer[i] = lpBuffer[index + nBytesRead
- keyLength + i];
}
index = keyLength;
memset(lpBuffer + keyLength, 0,
sizeof(lpBuffer) - keyLength);
} else {
index += nBytesRead;
}
}
}
}
return ret;
}

Posted in C++, Snippet, Tricks | Comments Off on Create a Process and Read Its Output