albertkao 12 Junior Poster in Training

This SQL operation will get the desired Proposal_ID.
[CODE]SELECT P.Proposal_ID,
AVG(c.Task_Good_Idea) AS Average
FROM proposals P,
proposal_appraisal c
LEFT OUTER JOIN users b
ON (c.Evaluator_ID = b.User_ID)
LEFT OUTER JOIN submission_status d
ON (c.Primary_Evaluation_Status_ID = d.submission_status_ID)
WHERE (P.Proposal_ID = c.Proposal_ID)
AND P.Proposal_ID >= 931 AND d.Submission_Status_ID = 2
GROUP BY Proposal_ID
HAVING Average >=25 [/CODE]

How to modify the following SQL operation so that only desired Proposal_ID are used?
[CODE]select cfp_Id, P.proposal_id, P.institution_Name, sum(P.Task_Good_Idea + P.Task_Involve_Youth + P.Task_Involve_Partnerships + P.Task_Exploit_Digital_Medium + P.Task_Value_For_Money + P.Task_Theme + P.Task_Skills_Development + P.Task_LOC_Curriculum) as Task_Good_Idea
from proposals P
group by P.proposal_ID
having (Task_Good_Idea >= 25) and (cfp_Id = 22)
order by P.proposal_id desc
[/CODE]

albertkao 12 Junior Poster in Training

Given the following two SQL operations:
[CODE]select prod_Id, P.proposal_id, P.institution_Name
from proposals P
group by P.proposal_ID
having mark >= 50
order by P.proposal_id desc

select prod_id, P.proposal_id, PA.evaluator_ID, U.user_Given_Name, U.user_surname
from users U, proposals P
LEFT outer JOIN proposal_appraisal PA
ON (P.proposal_Id = PA.proposal_id)
where PA.evaluator_ID = U.user_id
group by prod_id, PA.evaluator_ID
order by PA.proposal_ID, U.user_ID desc
[/CODE]

How to modify the following SQL operation so that prod_Id will be selected in addition to the existing columns being selected:
[CODE]select PA.proposal_id, PA.evaluator_ID, PA.Primary_Evaluation_Status_ID, PA.Secondary_Evaluation_Status_ID, U.user_Given_Name, U.user_surname,
from users U, proposal_appraisal PA
where PA.evaluator_ID = U.user_id
group by PA.proposal_id, PA.evaluator_ID
order by PA.proposal_ID, U.user_ID desc[/CODE]

albertkao 12 Junior Poster in Training

How to calculate an average and use that average to select some data?
e.g. for this query and its result.
[CODE]select Proposal_ID, Mark, AVG(Mark) AS Average from proposal where (Proposal_ID >= 931) GROUP BY Proposal_ID
931 20 22.2222
935 30 22.2222
936 30 21.1111
967 30 25.5556
968 30 20.0000
994 30 19.4444
995 20 15.5556
1010 30 17.7778
1011 20 17.5000
1015 20 17.7778
1018 20 17.7778
1020 30 18.8889
1049 30 20.0000
1050 30 22.5000
1051 0 15.5556
1052 10 17.7778
1053 30 23.3333
[/CODE]
How to refine the query so that after the average is calculated, then select those Proposal_ID where its average >= 20?

albertkao 12 Junior Poster in Training

I print the following webpage with Firefox & Chrome:
[url]http://en.wikipedia.org/wiki/Final_(Java[/url])

Both hardcopies of the long line "public static final double PI = 3.141592653589793; // this is essentially a constant" is cut off.
i.e. the line does not wrap around.
Both Firefox & Chrome display that line on screen in one line without any cut off nor wrap around.
How to make the hardcopy of that long line without any chop off?
I do not want to reduce the font size of the web page.

Benevolent Dictator For Life or BDFL is a title given to a small number of open source software development leaders. The BDFL resolves disputes or competing arguments within the community. The C++ community does not have a BDFL. Should the C++ community have a BDFL? If yes, does he want to be the BDFL?

[QUOTE=firstPerson;1240552]>>I want to optimize the following small integer program in speed

May I ask why?[/QUOTE]

This code snippet is part of a larger program which will run for a long time.

[QUOTE=WASDted;1218196]DaniWeb plans to interview Bjarne Stroustrup, the designer and original implementer of C++ and the author of many books on C++. This is truly a treat and rare opportunity for us as a community to talk to the father of C++.

As the new editor-in-chief of DaniWeb's News and Reviews I would like to reach out and involve the entire community and ask for your suggestions. Rather that simply asking Mr. Stroustrup the questions that come to my mind I would like to hear from you what you would like to know. Suggest a specific question or a general topic. Please keep it clean, respectful and relevant [to technology].

At the end of next Wednesday (May 19, 2010) I will review and consider all of your suggestions and come up with a list of questions for Mr. Stroustrup. I really look forward to your feedback and suggestions.[/QUOTE]

Ask him what will be the priority for the future C++ Standard Library wishlist ([url]http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2034.htm[/url]) after C++0x comes out in about a year
Personally I wish Web services, Web service container, Database support, Aspects and Design by contract will be the highest priority.

albertkao 12 Junior Poster in Training

I want to optimize the following small integer program in speed.
My g++ compiler version is 4.3.4 on 32 bit linux.
Please suggest or comment the following ideas.
Some ideas are:

  1. use compile flag such as -O3
  2. rewrite the bigger function with function object

[CODE]#include

include // for abs()

using namespace std;

const int N = 50;
const int D = 20;
bool bigger (int i) { return abs(i) >= D; }

int main()
{
int seq[N], diff[N];
// initialize seq
// ...
adjacent_difference(seq, seq + N, diff);
int count = count_if(diff + 1, diff + N, bigger);
// ...
return 0;
}[/CODE]

albertkao 12 Junior Poster in Training

Pressing the enter key at the jsp page receive extra invalid data at the ProdController.java.
The alertgroupStr receive "unack" as expected.
However, I do not understand why alertgroupStr receive the extra invalid "null" later.
Debug log:
11:14:52,187 DEBUG com.systems.monitoring.war.ProdController:54 - alertgroupStr unack
...
11:14:52,187 DEBUG com.systems.monitoring.war.ProdController:54 - alertgroupStr null

ProdController.java:
[code]
@Override
public ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String alertgroupStr = request.getParameter("alertgroup");
logger.debug("alertgroupStr " + alertgroupStr);
[/code]
Jsp page:
[code]<?xml version="1.0" encoding="UTF-8" ?>
<%@ include file="/WEB-INF/jsp/includeTaglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Hw Monitoring .pageNumber { float:left; padding: 3px 0; margin-left: 0; margin-bottom: 0; margin-top: 0.1em; font: bold 12px Verdana; } .pageNumber .noLink{ float:left; padding: 3px 0.5em; margin-right: 3px; margin-top: 3px; border: 1px solid white; border-bottom: 1px solid white; background: white; } .pageNumber a{ float:left; text-decoration: none; padding: 3px 0.5em; margin-right: 3px; margin-top: 3px; border: 1px solid #778; border-bottom: 1px solid gray; background: white; } .pageNumber a:hover{ border-color: navy; background-color: #8dd8f8; color: #FFF; } .rowPerPage { float:left; padding: 3px 0; margin-left: 0; margin-bottom: 0; margin-top: 0.1em; font: bold 12px Verdana; } function init() { } function isEmpty(v) { return (v == null) || (v.length == 0); } function isInteger(v) { return !isEmpty(v) && !/[^\d]/.test(v); } function setalertgroup() { var alertgroup = 'all'; var ...
albertkao 12 Junior Poster in Training

Pressing the enter key of the following page (created by JSP) submit page more than once.
Both alert popup boxes appear as expected:
alert('i ' + i + ' elem[i].checked ' + elem[i].checked);
alert('alarmgroup ' + alarmgroup + ' rowsPerPage ' + rowsPerPage);
appear.

However, then this alert appear again, which is unexpected:
alert('i ' + i + ' elem[i].checked ' + elem[i].checked);

but alert('alarmgroup ' + alarmgroup + ' rowsPerPage ' + rowsPerPage);
do not appear.

[CODE]<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Hw Monitoring .pageNumber { float:left; padding: 3px 0; margin-left: 0; margin-bottom: 0; margin-top: 0.1em; font: bold 12px Verdana; } .pageNumber .noLink{ float:left; padding: 3px 0.5em; margin-right: 3px; margin-top: 3px; border: 1px solid white; border-bottom: 1px solid white; background: white; } .pageNumber a{ float:left; text-decoration: none; padding: 3px 0.5em; margin-right: 3px; margin-top: 3px; border: 1px solid #778; border-bottom: 1px solid gray; background: white; } .pageNumber a:hover{ border-color: navy; background-color: #8dd8f8; color: #FFF; .rowPerPage { float:left; padding: 3px 0; margin-left: 0; margin-bottom: 0; margin-top: 0.1em; font: bold 12px Verdana; } .rowPerPage { float:left; padding: 3px 0; margin-left: 0; margin-bottom: 0; margin-top: 0.1em; font: bold 12px Verdana; } function init() { } function isEmpty(v) { return (v == null) || (v.length == 0); } function ...
albertkao 12 Junior Poster in Training

My javascript function setHw is not called by pressing the return key in all of the following pages.
Please help.

[CODE]

Rows Per Page

[/CODE]

[CODE]

Rows Per Page


[/CODE]

albertkao 12 Junior Poster in Training

I want to implement JavaScript Internationalization.
However, JavaScript does not have the property file mechanism (which is available in Java).
I am thinking of using the Java property file mechanism in Javascript. Is it possible?
I had implemented Java Internationalization with the Spring framework message. e.g.
[CODE][/CODE]
How do I use that in Javascript?
All of the following codes had 'code cannot be resolved' parsing error in JSP.
[CODE]
var confirmDeleteStr = '<%= spring:message code="account.confirmDelete" %>';
var confirmDeleteStr = 'spring:message code="account.confirmDelete"';
[/CODE]

albertkao 12 Junior Poster in Training

My program should display '*' when entering a password to a text box by a user. How to do that?

albertkao 12 Junior Poster in Training

How do I recursively remove all the directories and files which begin with '.'?
My test program rmdir.py does not do the job yet.
Please help.
Code:

!c:/Python31/python.exe -u

import os
from shutil import *
root = "C:\test\com.comp.hw.prod.proj.war\bin"
for curdir, dirs, files in os.walk(root):
print (curdir)
print (dirs)
for d in dirs:
print ("d " + d)
if d.startswith('.'):
print ("dotd " + os.path.join(curdir, d))
rmtree(os.path.join(curdir, d))

C:\python>rmdir.py
C:\test\com.comp.hw.prod.proj.war\bin
['.svn', 'com']
d .svn
dotd C:\test\com.comp.hw.prod.proj.war\bin.svn
Traceback (most recent call last):
File "C:\python\rmdir.py", line 14, in
rmtree(os.path.join(curdir, d))
File "C:\Python31\lib\shutil.py", line 235, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "C:\Python31\lib\shutil.py", line 233, in rmtree
os.remove(fullname)
WindowsError: [Error 5] Access is denied: 'C:\test\
\com.comp.hw.prod.proj.war\bin\.svn\entries'

I rewrite my program to:
[CODE]#!c:/Python31/python.exe -u
import os
import re

path = "C:\test\com.comp.hw.prod.proj.war\bin"
for dirpath, dirs, files in os.walk(path):
print ("dirpath " + dirpath)
p = re.compile('\.(\w)+$')
if p.match(dirpath):
continue
print ("dirpath " + dirpath)
for dir in dirs:
print ("dir " + dir)
if dir.startswith('.'):
continue

    print (files)
    for filename in files:
        print ("filename " + filename)
        if filename.startswith('.'):
            continue
        print ("no . ")
        print ("dirpath filename " + dirpath + "\\" + filename)
        # process the files here

[/CODE]
C:\python>walknodot.py
dirpath C:\test\com.comp.hw.prod.proj.war\bin
dirpath C:\test\com.comp.hw.prod.proj.war\bin
dir .svn
dir com
[]
dirpath C:\test\com.comp.hw.prod.proj.war\bin.svn
dirpath C:\test\com.comp.hw.prod.proj.war\bin.svn

I do not expect C:\test\com.comp.hw.prod.proj.war\bin.svn to appear twice.
Please help.

albertkao 12 Junior Poster in Training

I want to walk a directory and ignore all the files or directories which names begin in '.' (e.g. '.svn').
Then I will process all the files.
My test program walknodot.py does not do the job yet.
Please help.
[CODE]#!c:/Python31/python.exe -u
import os

path = "C:\test\com.comp.hw.prod.proj.war\bin"
for dirpath, dirs, files in os.walk(path):
print (dirpath)
print (dirs)
print (files)
for filename in files:
print ("filename " + filename)
print (dirs)
if "^." in dirs:
continue
if "^.
" in filename:
continue
print ("no . ")

process the files here

[/CODE]

C:\python>walknodot.py
C:\test\com.comp.hw.prod.proj.war\bin
['.svn', 'com']
[]
C:\test\com.comp.hw.prod.proj.war\bin.svn
['prop-base', 'props', 'text-base', 'tmp']
['entries', 'entries.bak']
filename entries
['prop-base', 'props', 'text-base', 'tmp']
no .
filename entries.bak
['prop-base', 'props', 'text-base', 'tmp']
no .
C:\test\com.comp.hw.prod.proj.war\bin.svn\prop-base
[]
[]
C:\test\com.comp.hw.prod.proj.war\bin.svn\props
[]
[]
C:\test\com.comp.hw.prod.proj.war\bin.svn\text-base
[]
[]
C:\test\com.comp.hw.prod.proj.war\bin.svn\tmp
['prop-base', 'props', 'text-base']
[]
C:\test\com.comp.hw.prod.proj.war\bin.svn\tmp\prop-base
[]
[]
C:\test\com.comp.hw.prod.proj.war\bin.svn\tmp\props
[]
[]
C:\test\com.comp.hw.prod.proj.war\bin.svn\tmp\text-base
[]
[]
C:\test\com.comp.hw.prod.proj.war\bin\com
['comp']
[]
C:\test\com.comp.hw.prod.proj.war\bin\com\comp
['hw']
[]
C:\test\com.comp.hw.prod.proj.war\bin\com\comp\hw
['proj']
[]
C:\test\com.comp.hw.prod.proj.war\bin\com\comp\hw\proj
['war']
[]
C:\test\com.comp.hw.prod.proj.war\bin\com\comp\hw\proj\war
['service']
['Activator.class', 'MessageReceiver.class', 'messages.properties', 'messages_fr.properties', 'ShutDownController.class', 'HwController
.class', 'HwManagerController.class']
filename Activator.class
['service']
no .
filename MessageReceiver.class
['service']
no .
filename messages.properties
['service']
no .
filename messages_fr.properties
['service']
no .
filename ShutDownController.class
['service']
no .
filename HwController.class
['service']
no .
filename HwManagerController.class
['service']
no .
C:\test\com.comp.hw.prod.proj.war\bin\com\comp\hw\proj\war\service
['impl']
['HwService.class']
filename HwService.class
['impl']
no .
C:\test\com.comp.hw.prod.proj.war\bin\com\comp\hw\proj\war\service\impl
[]
['HwServiceImpl.class', 'HwServiceManager.class']
filename HwServiceImpl.class
[]
no .
filename HwServiceManager.class
[]
no .

[QUOTE=JRM;1210774]try:

[CODE]echo exec("./testprog");[/CODE][/QUOTE]

It works!
Thanks.
Why specifying the current path "." in the PATH environment is not good enough?
$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/sbin:.

albertkao 12 Junior Poster in Training

I want to call a C++ program from PHP with apache server on Fedora 12 linux.
testprog is put in the same directory of the test php program.
I see the output of exec('ls -lrt') but not exec("testprog").
Please help.
The following are my php and cpp test programs.
[CODE]

PHP Test

[/CODE]

testprog.cpp
[CODE]#include

include

int main() {
int array[] = { 23, 5, -10, 0, 0, 321, 1, 2, 99, 30 };
int elements = sizeof(array) / sizeof(array[0]);
std::sort(array, array + elements);
for (int i = 0; i < elements; ++i)
std::cout << array[i] << ' ';
}[/CODE]

albertkao 12 Junior Poster in Training

How to recursively walk directory & rename files & directories with Python 3.1 on windows?

[CODE]#!c:/Python31/python.exe -u
import os

path = "test"
for (path, dirs, files) in os.walk(path):
print (path)
print ("-----------------")
if "monitoring" in path:
dst = path.replace("monitoring", "managing", 10)
print (dst)
os.rename(path, dst)
print ("path----")
for file in files:
if "hw" in file:
print (file)
dst = file.replace("hw", "hw2", 10)
os.rename(file, dst)
print (dst)
print ("file----")[/CODE]
My test program has this error:
Traceback (most recent call last):
File "C:\python\pathwalk.py", line 17, in
os.rename(file, dst)
WindowsError: [Error 2] The system cannot find the file specified

[QUOTE=albertkao;1184800]The hwform is changed to the following.
Now pressing the key and clicking the "Apply" button has the same result - the button value is changed from "ack" to "all".
However, I expect that the button value should not change.
[CODE]



HW
Rows Per Page
[/CODE][/QUOTE] I took out the submit button and the group button is still present. The group button in my form is set to "unack". After typing in a number at the text box, then I press the "Enter" key. The group button in my form is set to "all", which is unexpected. I expect the group button still set in the "unack" state. [CODE]

HW
Rows Per Page [/CODE]

The hwform is changed to the following.
Now pressing the key and clicking the "Apply" button has the same result - the button value is changed from "ack" to "all".
However, I expect that the button value should not change.
[CODE]



HW
Rows Per Page
[/CODE]

Modify to this but still has the same problem:
[CODE]
Rows Per Page[/CODE]

Modify to this but still has the same problem:
[CODE]
Rows Per Page[/CODE]

albertkao 12 Junior Poster in Training

The group button in my form is set to "unack".
The Spring HwController receive the correct group "unack" when the "apply" button is clicked.
However, the HwController receive the null group when the cursor is moved to the text box and press the key.
Only the data from the button is received incorrectly, the other form data are received correctly.
Please help so that the HwController will receive the correct group when the key is pressed.
I use Spring 2.5.x to implement JSP.
Eclipse console output:
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:57 - groupStr unack
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:60 - group unack
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:71 - rowsPerPageStr 40
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:80 - rowsPerPage 40
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:57 - groupStr null
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:60 - group all
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:69 - acked null
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:71 - rowsPerPageStr 60
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:80 - rowsPerPage 60

Hw.jsp file:
[CODE]
function setgroup() {
var group = 'all';
var elem = document.getElementsByName("radio");
for (var i = 0; i < elem.length; i++) {
if (elem[i].checked) {
group = elem[i].value;
}
}

var rowsPerPageElem = document.getElementById("rowsPerPage");
var rowsPerPage = rowsPerPageElem.value;
var chkelem = document.getElementById("ok");
var ok = chkelem.checked;

window.location = "Hw?rowsPerPage=" + rowsPerPage + "&ok=" + ok  + "&group=" + group;

}

All
albertkao 12 Junior Poster in Training

My controller.java encounter an input string: "undefined".
Please help.
[CODE]public ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {

int rowsPerPage = 20;
String rowsPerPageStr = request.getParameter("rowsPerPage");
logger.info("rowsPerPageStr " + rowsPerPageStr);
if (rowsPerPageStr != null) {
rowsPerPage = Integer.parseInt(rowsPerPageStr);
}[/CODE]

My jsp page use javascript as follows:
[CODE]window.location = "hwdisplay?rowsPerPage=" + rowsPerPage;[/CODE]

Eclipse Console output is:
rowsPerPageStr undefined
Servlet.service() for servlet hwmgr threw exception java.lang.NumberFormatException: For input string: "undefined"

albertkao 12 Junior Poster in Training

I want to keep the value of the user input (e.g. text box value) displayed after page refresh by a javascript.
The following test web page is used.
The alerts appear before and after the page refresh as expected on all browsers (FF, Chrome, Opera & IE).
The input value in a text box still appear after page refresh for IE but not FF, Chrome, Opera.
Please help to make it work for FF, Chrome, Opera.
[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Cookie
Rows Per Page Cookie.init({name: 'mydata'}); function savevalue() { var rowsPerPageElem = document.getElementById("rowsPerPage"); alert('rowsPerPageElem.value ' + rowsPerPageElem.value); Cookie.setData('rowsPerPage', rowsPerPageElem.value); window.location.reload(true); var rowsPerPage = Cookie.getData('rowsPerPage'); alert(' rowsPerPage ' + rowsPerPage); var rowsPerPageElem = document.getElementById("rowsPerPage"); rowsPerPageElem.value = rowsPerPage; } [/CODE]

What is the proper way to initialize pageContext?

albertkao 12 Junior Poster in Training

How to store variables in the jsp page scope with the spring 2.5.x framework?

This has compile errors.

[CODE]import javax.servlet.jsp.PageContext;

@Override
public ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {

    PageContext pageContext;

    Object o = pageContext.getAttribute("com.mycompany.pageId");[/CODE]

Description Resource Path Location Type
The local variable pageContext may not have been initialized HwController.java /com.mycompany.monitoring.war/src/com/mycompany/monitoring/war line 59 Java Problem

albertkao 12 Junior Poster in Training

Why the following code has the error: 'document.mainform.unknownHw' is null or not an object?

function setUnknownHw(unknownHw)
{
document.mainform.unknownHw.checked = unknownHw;
}



Unknown Hw