~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The simplest way would be to configure a path[a directory] in your web.xml and use the same path to upload/download images based on the image name specified.

In your web.xml:

<web-app ...>
  <context-param>
    <param-name>RESOURCE-PATH</param-name>
    <param-value>d:/My-Uploads</param-value>
  </context-param>
</web-app>

In your Servlet when saving:

// TODO: Move the image writing code to a separate utility
// class to maintain a sane level of abstraction
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
  String path = getServletContext().getInitParameter("RESOURCE-PATH");
  OutputStream out = //retrieve the file stream
  String imageName = request.getParameter("image-name");
  File dir = new File(path);
  File file = new File(dir, imageName);
  // write from the servlet request stream to this file
}

In your Servlet when retrieving:

// TODO: Move the image reading code to a separate utility
// class to maintain a sane level of abstraction
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
  String path = getServletContext().getInitParameter("RESOURCE-PATH");
  String imageName = request.getParameter("image-name");
  File dir = new File(path);
  File file = new File(dir, imageName);
  // Check file existence; throw appropriate error if not present
  // Write the contents of the file to the servlet response stream
}

- Of course there might be problems implementing this approach, but this is as simple as it gets.

- You can also store your images in a database as BLOB to get all the benefits offered by an RDBMS if required.

- You can also store the images relative to your web application root instead of just any random location on …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You essentially throw away almost all the records read by reading the database entries in the ResultSet loop by not doing anything. If you want to compare the user entered value with the ones present in the database, do the comparison in the ResultSet loop. Set a flag and break out of the loop if the comparison succeeds.

Also a few points worth mentioning:

- Class names in Java should begin with an uppercase character; the same applies for Servlets.

- Since the JVM maintains a string pool, try not to use new String() *ever* in your code. Just use the string literals and let the JVM do the heavy lifting of deciding whether to use the existing pool instance or create a new one i.e.

// Instead of doing
String name = new String("");

// Do
String name = "";

// Or better yet; though depends on the particular use case
String name = null;

- For production/real use, don't prefer a JDBC-ODBC bridge driver but a pure Java Type 4 driver. Even if you are trying out things, doing things the right way would be much preferred. Use a database like MySQL or Derby along with the type 4 drivers which come along with it.

- You can simplify things a *lot* by modifying the query instead of jumping through all those hoops yourself. Just add an additional WHERE clause in your query and check if the returned ResultSet has at least one record; …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> If anybody reads this and is pinning topics *coughcough* please take a
> look at:

You can of course go ahead and create a sticky-worth thread in the forum you feel appropriate and PM the concerned sub-forum moderator regarding the same; that should get the job done. If everything else fails, PM me. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Or just use Pattern.quote('your-pattern') and let the Pattern class do the heavy lifting...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Oh snap, first Tek and now you; you people sure are demanding. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I did see it when I first logged in, but trying after around half an hour made it go away.

iamthwee commented: test +23
kvprajapati commented: Yes! +13
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I see a hanging [/url] in the first paragraph.

And as far as the comments regarding Grails are considered, why would a company/team/developer planning to use RoR suddenly consider Grails? If you are planning to shift from the Ruby ecosystem to the Java ecosystem, the closest you can get to is using JRuby on Rails; the simplicity and maturity of Ruby[as a language] with the infrastructure of Java.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What a thing to write Mr. Dave!!

Really an interesting read (both the story as well as the quote at the end).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Nice snippet, though it would be better if you included the output so that beginners don't have to compile and execute your code to understand what is going on.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> How to you handle tabs?
If you will notice, this is not a generic function, the way we have in Python, Ruby and other languages. You need to pass the character to be stripped. If you want to strip off tabs, pass the junk character to be '\t'.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Here is a simple implementation of implementing a simple Left trim (ltrim) and Right trim(rtim) of unwanted characters from a C style string. (null terminated strings). Doesn't suffer the overheads of the memmove implementation in which the worst case scenario (a string containing all junk characters) is approx. N^2 / 2.

Comments, constructive criticisims are welcome.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

But this code won't work if the text field loses focus and then gains it again and for a variety of other conditions. With a bit of tweaking you guys should get the desired result. Here is my stab at it...:

<html>
<head>
    <title>Cool Text Effect</title>
</head>
<body>
    <label>Click on this text box </label>
    <input type="text" name="txt" value="Search" 
        onfocus="if(this.value == 'Search') { this.value = ''} " 
            onblur="if(this.value == '') { this.value='Search'; }" />
</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

...and not to forget the using namespace std; which has to be placed after the includes so that we can start using the constructs under the standard namespace without prefixing each of them with std::

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Has been taken care of, thanks for the notification once again.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Has been taken care of, snippet modified to incorporate the change.
Thanks for notifying this, your help in the code snippet section is greatly appreciated.

Hope you find out more such bugs :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The duplicate code snippet issue has been dealt with.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
T arraynums[n] ;
arraynums[n] = n ; // dont you think its out of bounds error.

Please make sure your code works before you post it in the code snippets section. In future code snippets which dont compile will be deleted.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The code does not even compile. Please verify that the code works before posting it. Next time such imcomplete codes will be deleted...

This time I am ediiting so that it just works..

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string s;
    cout<<"Type something...\n";
    getline(cin,s);
    string::iterator end = s.end( ) - 1;

    for( ; end != s.begin( ) - 1; end--)
    {
        cout << *end;
    }
    return 0 ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The behaviour of fflush( stdin ) is always undefined whatever be the compiler -- its just that some compilers let you get away with it.

And as far as sorting the linked list is concerned, there is another simple way of doing it -- sort the list as and when the data is entered so that the list is always in sorted form. Before adding each data element, make a search through the entire llist to find where that data exactly belongs to so that it can be inserted at the appropriate position.

Thank you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

actually it looks complex bcoz you have initialized the array in read only memory it would be easier if you had dynamically allocated the array making it r+w

I dont know if I quite get you but are you saying that I should have created the input string dynamically and then modified the same ?

But thats not what I wanted to do, I wanted to keep the input string intact. Also creating two functions -- a interface and one actual functionality helps me get rid of using a static type qualifier.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It is complex since rather than just printing out the reversed string, it "actually" returns a reversed string and that too using recursion.

Have a go at it urself and you will understand its not that simple to handle.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello to everyone out there. Recently many people on different forums have been asking how to make a recursive function which reverses the string passed to it. But unlike the normal recrusive funtion which only prints out the reversed string, this implementation returns a pointer to reversed string.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In Javascript:

var input = "03857";
var arr = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
var output = input.replace(/(.)/g, function(a, b) {
    var i = parseInt(b); if(!isNaN(i)) return arr[i] + " "; else return "";
  });
print(output);

I'm sure we can come up with shorter and better constructs in modern programming languages but that's a moot point if you are asked to do it in C; show some mercy to those starting out with programming. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The program parses the digits in the number supplied to it and converts it to aplhabetical equivalent. Fore eg. input: 1234 output: one two three four This is a simple exercise for newbies, must try out. Tested and works under ideal input conditions.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Some constructive comments:

1. exit (0) means successful return from a function. In case of unsuccessful memory allocation use, exit (1) instead of exit (0)

2. Always send the errors to the error stream rather than the output stream. In most of the cases the error stream is the ouput stream ie your monitor, but in specific cases it can be a log file.

3. A lightweight way to add a newline rather than writing printf ("\n") ; is putchar ('\n') ; 4. According to the principles of Software Engineering, the less the parameters passed to the functions, the better the function is. If your passed parameters exceed 4, try to re analyze your design.
The number of parameters passed is directly proportional to the complexity of the function.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Using goto LABEL; is not a recommended programming practice. THe same applies to system ("PAUSE") calls. Calling OS dependent functions is not good programming practice.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Changes made and now working for any kind and length of input -- thanks for letting me know it didn't work previously.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello here i am posting the non recursive or no recursion implementation of outputting Permutations of a string as compared to the recursive implementations previously posted.

Any feedback, constructive criticism or comments are most welcome.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Please my friend try ur code before posting it on the forum so that other ppl are not misled.

THe code u have posted doesnt work.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Thats the reason i posted the updated version which works and uses safe functions like fgets().
:mrgreen:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The above method for gettign the string from the user wont work and would give an run time error since the user input is stored in a character ptr for whom no memory has been allocated.

Better use

#include<stdio.h>
#include<string.h>

char *strrev(char *str)
{
  char s[2],*t;
  if(strlen(str)==1)
    return &str[0];
  else
  {
    s[0]=str[0];
    s[1]='[B]\0[/B]';
    t=strrev((str+1));
    strcat(t,s);
    return t;
   }
}


int main (void)
{
  char str[BUFSIZ];
  char* dstr;
  printf("[B]\n[/B] Enter Input string ");
  fgets(str, BUFSIZ, stdin);
  dstr="";
  dstr=strrev(str);
  printf(" Reverse String %s",dstr);
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Dont use "gets( )" for accepting string input from user -- It is a bad programming practice and the function itself is flawed as it doesnt check for buffer overflows. Use [search]fgets( )[/search] instead.

Avoid use of globals if possible -- there is no condition where the program cant be done without using globals. Using globals prevents your algo or program being used as a part of a larger program.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Very confusing, very non standard .
A better implementation should have been pursued.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Not much to be explained here except for the thing that this code basically relies on the function mciSendString( ) . A reference to that can be found here.

Here MCI stands for Media control Interface and mmsystem.h stands for MultiMedia System Header file. BTW these two terms are specific to MS Windows only.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Also look into Commons Validator. Though it doesn't have a large tutorial collection or user base, there would certainly be a few things out there which you might find interesting.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>This has nothing to do with my JISO project (If that's what you were
> refering to)

No, I was referring to your school project which you had mentioned in an earlier thread.

>If that's true, then the graphics painted on the server side (The
>Classes that render the GamePanel in the JAR file) should appear
>on the client side as well.

That's like saying that when I hit a web server, I need to see the HTML page displayed at the server. Re-read my previous post in which I point out which things are normally placed at the server and which things are placed at the client. RMI stands for "Remote method invocation", you use remoting capabilities to invoke a method and the proxy generated gives the client an illusion of local method calls. I'd suggest reading a bit or at least understanding the architecture/rationale behind RMI before using it for a full blown project like this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

@llemes

Is this regarding the game project you were talking about? If yes, then this approach seems kinda wrong. AFAIK, in case of network games, the graphics are *never* rendered at the server and transferred to the client. The server doesn't dictate what has to be displayed but rather how things have to be displayed.

Let's take an example of a MMORPG. The way it is normally done is that when the user is first distributed a jar which already contains the view related resources i.e. images, sound files, map data etc. When the user starts the game the map on which the user is supposed to be is rendered using the local map file. But the state of the other entities like monsters, treasures etc. are pulled from the server using RMI or a custom efficient protocol. Such world updates are pushed to the client continuously and the actions by both the gamer and the other users affect the state of the visible/invisible world. In practice, there is a *lot* which goes behind the scene to make this all *work*. And given that all that I have presented till now is pure speculation/guesswork of how things should work, you need to do a bit of research by reading the code of other open source network games out there.

Of course, you can do away with the client requiring to download your JAR file by using an applet and making the browser download your latest game jars …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> python got strong typing ,but not security

I guess 'masijade' meant that Python is not statically typed like Java and hence you lose out on aggressive re-factoring and excellent IDE support.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> So I want to complain on your tolerance here, its way way way to
> low.

This isn't that bad; really. There are forums out there which close your threads or delete "both" your threads in case you double post. There are forums out there which don't answer your question in case they feel that the user is spamming the forums. There are forums out there wherein the OP is insulted for not following the rules.

This is way better, believe me. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>I personally don't give a damn about how much reputation I get
>for my posts
Most of the regulars don't, believe me. This is also one of the reasons why the rep system suck. Like I previously mentioned, the number of vote-ups is a much better measure of helpfulness than the rep system which "feeds the rich and buries the poor". ;-)

>The reputation system is a nice way to (dis)agree to someone
>without making an actual post.
This is where StackOverflow shines as compared to other forum installations; it has a real comment system which is independent of the vote-up system.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, that isn't a problem because the chances of the scenario you mentioned succeeding is pretty slim. A few points:
- Creating a profile is time consuming and way too much trouble
- Members can't vote-up unless they `earn' a few vote-ups themselves.

IMO, taking the trouble of registering and then gathering vote-ups just for the purpose of voting-up a particular person or self is way too time consuming task; esp when you gain nothing of monetary value by doing so, just a measure which says how helpful a person is...something which probably won't be done by *silly* people.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>I like the reputation system better

I personally feel that the reputation system is a complete fail and the point system introduced by StackOverflow is awesome. You get a vote-up if the answer is acceptable; a vote-down is not. The reputation generated for each vote-up/vote-down is the *same* irrespective of the number of reputation points the voter has!

Let's assume that you post a really good answer to some C# question and it's a hit with the C# developers on this site who completely agree with the reply but just happen to have recently joined Daniweb and hence don't have any reputation points to give. OTOH, someone else posts a so-so reply on the same thread with a bit of *cough* humor *ahem* in it and it gets a A-OK from one of the established members of this site. Viola, the person with a so-so reply now has 50 rep points while you have none.

Reputation should IMO depend on how many people agree with your answer rather than *who* agrees with your answer. The reputation system should focus more on avoiding blunders than trying really hard to reward acceptable answers. Lastly, as someone once said, rep system is more of a popularity contest. :-)

> because the point system would put more of a burder on
> moderators to assess each question and score it

Even normal members can vote-up answers, no? AFAIK, there is no burden on moderators whatsoever.

iamthwee commented: Stack-overflow. What is that another forum, to waste yet more of my real life, great I think I'll join asap. +23
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>Anyways, what did you think about the program (If you used it)?

Sorry, I couldn't due to time constraints.

>I tried using Eclipse in the past, and I don't think it lived up to all the hype....

I personally feel that once you start exploring Eclipse and its real power which lies in the plethora of plugins out there, there is no turning back. As a professional Java developer, I think it's worth a second try IMO.

> Why use ArrayLists when you have Vectors?

  • Because synchronization is broken in the eyes of the masses
  • Because 9 out of 10 usages of Vector is due to the fact that someone needed a simple list but the words 'thread safe' sound much cooler
  • Because 9 out of 10 people don't know what they are synchronizing
  • Because blind faith and abuse of Vectors in lieu of ArrayList results in serious performance problems
  • Because real world synchronization issues are worth more much than synchronizing a single line of code
  • Because concurrency bugs are *hard* and having a fake sense of your applications' thread safety doesn't help

Though Vectors are not necessarily evil, their ill usage has taught me better than to trust a code which prefers Vectors over ArrayLists.

For those interested in citations, please read the chapter on Threads from the book Sun Certified Programmer Java 5 by Kathy Sierra for more details.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A few observations:

  • It seems that you are using an IDE for developing this project. It would be nice if you would format the code so its easy on the eyes. If using Ecilpse, use CTRL + A to select the code and then press CTRL + SHIFT + F for formatting your code.
  • No need to manually type down the accessors(getters) and mutators(setters). If using Eclipse, use the shortcut CTRL + SHIFT + S and then R.
  • Why use Vectors when you have ArrayLists?
  • The classes lack a proper description and documentation. If you are expecting people to help you out, your code should be easy on the eyes.
  • In class HealthBar.java for line g2.drawString(label, x-12, y+10); , what does 10 and 12 signify? Avoid magic numbers and literals; give them descriptive names and declare them as static final fields.
  • Consider placing the textual entities in your code in a separate properties file [like the strings "HP" and "MP" in HealthBar.java] otherwise a small change in them would require an entire code re-compilation.
  • Rather than having 5 constructors in your Unit.java file, consider using the Builder design pattern.
  • Why does every field in the Unit class has a "default" access specifier? If your class is abstract, it makes much more sense to have "protected" fields since your class is going to be subclassed anyways.
  • When you declare a class as abstract, instead of having methods with empty body [like draw() in Unit.java] consider making the method …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hi there, welcome to Daniweb. :-)

In case you need help with any topic, consider posting in the concerned forum rather than hijacking other threads. You can ask questions related to the XHTML markup in the HTML and CSS forum.

Consider asking specific questions, something like, I've done XXX in YYY and it still isn't working. The more descriptive your question, the better.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

More eye-candy, a more stable forum software and long time bugs being fixed is what I'd bet my money on. Of course a better way to manage code snippets and blogs would be a nice to have thing. :-)

Also, since Daniweb uses vBulletin, you can read about the features of the latest vBulletin here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

IMO, the replies to the query posted by 'kaninelupus' have been a bit too harsh. After all it is the very purpose of the 'Daniweb Community Feedback' to help out the forum members regarding any sort of forum queries. Though I agree that the way the question was phrased seemed more like a demand than a query but still...

As someone once said, if one has to decide between posting a harsh reply or not posting a reply, one should rather go with the latter; avoids a lot of needless hassle IMO.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>Does everything need to be Twitified??

Maybe; who knows.

>Isn't that info available to any regular user of the site?

Not exactly; Daniweb hasn't exactly got a specialized forum for publishing daily alerts or notifications. So, if you end up subscribing to a general purpose forum like "Daniweb Community Feedback", you'd get alerts for all threads created, which might not be what a user wants.

>But if the guy has all of one post and a single follower

...and no activity.

>He obviously hasn't tried to impersonate the site or tried to defraud
>anyone

How can you be so sure?

>Sorry, but against bully-boy tactics!

Sorry, but that's how the world works. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Though I'm no Ruby expert, here are a few suggestions:

if (result.nil?)
  return Time.now
end

can also be written as:

return Time.now if result.nil?

= Instead of using @@tcMillisecondMode = "false" , why not just use @@tcMillisecondMode = false ?

= Your ASC state can be better represented using Ruby Symbols.

= In Ruby in absence of a return statement, the value of the last expression evaluated is returned hence the method:

def TimeChannels.getHTTPContent(url)
    data = open(url).read
    data
end

can be replaced by:

def TimeChannels.getHTTPContent(url)
    open(url).read
end

though as already mentioned, handling exceptions in case establishment of a connection fails should come first.

= The Ruby way of naming variables and methods is *not* to use camelCase but use under_scores; though it's a matter of taste. However it pays to follow and use the conventions used by the community in general to facilitate easier understanding of others' code and vice-versa.

In case you require a more in-depth review, feel free to post your code on the official ruby forums and you'll surely get more feedback.

HTH
-sos