riahc3 50 Â Team Colleague

First result on Google

public static boolean isInteger(String s) 
{
    try 
    { 
        Integer.parseInt(s); 
    } 
    catch(NumberFormatException e) 
    { 
        return false; 
    }
    return true;
}

Use this and it will return true or false depending...

riahc3 50 Â Team Colleague

I dont have the slightest clue what you are trying to acomplish. That said...

You can do in your Player function:

return playerChar.split("(?!^)");

Then in your main:

String[] PeopleDoSomeWeirdShit=User.Player(1);

And it will work. To access the result:

System.out.println(PeopleDoSomeWeirdShit[0]); //Will print out "W"
System.out.println(PeopleDoSomeWeirdShit[1]); //Will print out "a"
System.out.println(PeopleDoSomeWeirdShit[2]); //Will print out "r"
System.out.println(PeopleDoSomeWeirdShit[3]); //Will print out "r"
System.out.println(PeopleDoSomeWeirdShit[4]); //Will print out "i"
System.out.println(PeopleDoSomeWeirdShit[5]); //Will print out "o"
System.out.println(PeopleDoSomeWeirdShit[6]); //Will print out "r"

For prettier stuff:

for (int i=0;i<PeopleDoSomeWeirdShit.length();i++
{
    System.out.print(PeopleDoSomeWeirdShit[i]); //Will straight out print "Warrior"
}
riahc3 50 Â Team Colleague

Also, for those who missed the notice, the code snippet competition is being extended to the end of August for submissions

:(

riahc3 50 Â Team Colleague

He was obviously being sarcastic....

Due to the fact it is not possible (in web apllications) to open a words file using Java, it is required to directly put the words string separated by a | into the string variable. Modify the string in the initGame() function in the script (line 59).

Since when? JS can do it perfectly AFAIK. Obviously we wont get into Java....

riahc3 50 Â Team Colleague

Stacktrace. I thought it was obvious that foldername was a placeholder, sorry.

riahc3 50 Â Team Colleague

Hello

Im using the FileUtils.copyDirectory method but it gives me the error of "Failed to list contents of foldername". I know the folder exists and I can write there because creating a file works.

What could be wrong?

riahc3 50 Â Team Colleague

I perfer using a normal for, not a foreach.

riahc3 50 Â Team Colleague

I perfer numeric and the values inside are

key -> vale

Nothing complicated AFAIK.

$_COOKIE is associative array. If you want to turn it to numerically indexed you can use array_values() function. But you are loosing valuable information. You can list values this way:

Ill try this.

riahc3 50 Â Team Colleague

Im testing local then deploying on shared hosting....

riahc3 50 Â Team Colleague

Hey, could I do something with libVLC?

riahc3 50 Â Team Colleague

It says XE4 is for iOS, Windows and Mac, so no Linux anyway.

Then OS X and Windows....

riahc3 50 Â Team Colleague
for ($i = 0; $i < count($_COOKIE); $i++) 
                {
                     echo ($_COOKIE[$i]);
                }

Is there a reason this doenst work?

riahc3 50 Â Team Colleague

Hello

Lets say in the localStorage object I have the following:

Apple = red
Potato = brown
Gum = blue

And I want to search thru it for the word Potato and then get its value (brown).

How could I do this?

Im thinking:

for (var i=0;i<localStorage.length();i++)
{
    if (localStorage[i]=="Potato")
    {
    var somevariable=localStorage[i].value();
    break;
    }
}

Forgive sintaxis errors as I just thought it up in 15 seconds.

riahc3 50 Â Team Colleague

The version is FireMonkey from Embarcadero.

http://www.embarcadero.com/products/firemonkey

I am imagining its the bottom link saying Delphi XE4

riahc3 50 Â Team Colleague

Hello

Im having problems setting a cookie in PHP (using the Magento platform). The page is at:

http://example.com/step1

When I click on a link here, a iframe opens up. This iframe opens up and is located at:

http://example.com/somewhereelse/index.html

I check a checkbox or I dont. If I check it, a cookie is set to true (lets say whereelse = true) else its set to false (lets say whereelse = false). This works. It sets it to true and false.

After clicking a link, that basically goes to the cart it goes to

http://example.com/step2

But I do not see the cookie at all.

Ive also tried using localstorage and that DOES WORK....but from PHP I cannot access it later.

If more information is needed, please ask and Ill try to put it if known what is asked.

Thank you.

riahc3 50 Â Team Colleague

I really doubt that there are multi-platforms drivers. I haven't seen any although that still doesn't mean there aren't any. Which Delphi are you using?

Not for me, for a colleague. No idea at all.

I explained that the only way to do this (if there is no multi-platform drivers) is to load one for each platform (only three: Linux, OS X and Windows) but the binary would be huge....

riahc3 50 Â Team Colleague

Hello

Is there some kind of multiplatform library for Delphi (with its SDK) to access webcams while programming? The goal is to take still images but Ive only found ones that are compatible with Windows.

riahc3 50 Â Team Colleague

Dani hates me :P so here you go. Updated:

private void button1_Click(object sender, EventArgs e)
        {
            string newString = "";
            var client = new RestClient("http://www.daniweb.com/api"); /*I prepare the API*/

            /*I remove whitespaces except actual spaces*/
            for (int i = 0; i < textBox1.Text.Length; i++)
            {
                if ((char.IsWhiteSpace(textBox1.Text[i])) && (!textBox1.Text[i].Equals(' ')))
                {
                    textBox1.Text = textBox1.Text.Remove(i, 1); 
                }

            }


            /*I make sure that the user name isnt empty */
            if (textBox1.TextLength==0)
            {
                MessageBox.Show("Please insert a valid member");
            }
            else
            {

            /*I call the members method of the API and pass parameters by GET. POST did not work (Why?)*/
            var request = new RestRequest("members", Method.GET);
            request.AddParameter("username", textBox1.Text);

            /*Send it and wait for reply*/
            var response = client.Execute(request);

            /*Finding where it says the post number in the response...*/
            int next = 0;
            int first = response.Content.IndexOf("\"posts_count\":\"");
                if (first==-1) /*-1 means it could not find it therefore no member exists*/
                {
                    MessageBox.Show("Member not found!"); 
                }
                else
                {
                    /*I find the next quote that actually begins the post number*/
            do
            {
                next = response.Content.IndexOf("\"", first);
                /*Not neccesary but in case Dani changes the array to something else....*/
                if (next==-1)
                {
                    break;
                }
            } while ((next==0));



            /*VERY Ugly hack to get posts numbers. Tried with largest post numbers I could find (Dani's AFAIK)*/
            string str2 = response.Content.Substring(first, (next + 21) - first);
            newString = Regex.Replace(str2, "[^.0-9]", "");

            }

             if (textBox1.TextLength == 0)
             {
                 MessageBox.Show("Please insert a valid member");
             }
             else if (first!=-1)
             {
                 MessageBox.Show(newString, "The total amount of posts this user has is:");
             } …
riahc3 50 Â Team Colleague

Because Dani hates me, the above is outdated so:

package DaniWebClient;


import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.ws.rs.core.MultivaluedMap;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;

public class DaniWebClient 
{


    public static void main(String[] args) 
    {
        /*I prepare the API*/
        Client client = Client.create();
        WebResource webResource = client.resource("http://www.daniweb.com/api/members");

        /*User introduces name*/
        System.out.println("Enter the member who's post you want to see: ");
        String user;     
        Scanner scanIn = new Scanner(System.in);
        user = scanIn.nextLine();
        StringBuilder username=new StringBuilder(user);

            /*I remove whitespaces except actual spaces*/
            for (int i=0;i<username.length();i++)
            {
                if ((Character.isWhitespace(username.charAt(i))) && (username.charAt(i)!=' '))
                        {
                            username.deleteCharAt(i);
                        }
            }
            user = username.toString();
            /*For some stupid reason, Java is stupid (no surprise there) and doesnt consider ALT+0160 a whitespace. I have to remove it manually*/
            user = user.replace("\u00A0","");

            /*I make sure that the user name isnt empty */
            if (user.length()==0)
            {
                System.out.println("Please insert a valid member");
            }
            else
            {

                /*I call the members method of the API and pass parameters by GET. POST not tested in Java*/
                MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
                queryParams.add("username", user);

                /*Send it and wait for reply*/
                String output = webResource.queryParams(queryParams).get(String.class);
                System.out.println(output);

                int first=0;
                int next=0;

                /*Finding where it says the post number in the response...*/
                //first=output.indexOf("\"posts\":\"");
                first=output.indexOf("\"posts_count\":\"");

                if (first==-1) /*-1 means it could not find it therefore no member exists*/
                {
                    System.out.println("Member not found!");
                }
                else
                {
                    do
                    {
                        /*I find the next quote that actually begins the post number*/
                        next = output.indexOf("\"",Integer.valueOf(first));

                        /*Not neccesary but in case Dani changes the array to something else....*/
                        if (next==-1)
                        {
                            break;
                        } …
riahc3 50 Â Team Colleague

I hate you Dani :P I have to update both snippets....

riahc3 50 Â Team Colleague

I think that an extension would be a good idea, the more people entering the better at the end of the day.

For DaniWeb of course. For the developer who wants $300 in Amazon, no :P

riahc3 50 Â Team Colleague

This can be done by assigning value to JAVA_OPTS variable. Look into some documentation on JAVA_OPTS as well to have more knowledge. One important information you do need to know is that each time you deploy an application on the server, the application thread will use the memory added on JAVA_OPTS. So you need to be careful if you are running multiple applications on the server.

How do I modify this in Linux?

Sometimes I update my web service JAR by deleting the old one, are you tried to use JWS(tJWS not clear from your description)

I simply delete the web service jar, wait for the undeployed message to appear, then copy the new one and wait for the deployed one to appear. Done.

riahc3 50 Â Team Colleague

dani can you increase duration of competition by 2 weeks or so.I m a bit involved in my app for now.It will take a week or two after that i will start working for this competition.Or else riahc3 ,diafol and pritaeas will take those rewards. Let me take third. :'(

Well, in fairness to other members, The API has been here about a month and so has the contest. Extending wouldnt be fair to others who have worked on the API (such as pritaeas; my entry is more of a mock as I know a code sample has no way of winning) because those others who have submitted a entry, now have to improve on their work to make sure they win...

I am seriously considering extending the competition because it seems that the first few weeks were spent learning the API and creating frameworks around it, as opposed to developing the meat of an application.

As I mentioned to IIM, pritaeas would for example better his app to make sure he wins (I dont care about my entry as its more of a mockup than anything; The more entries the better)

But if you do extend it, lets see it promoted more so we can get some people involved!

riahc3 50 Â Team Colleague

I can upload small texted file but not large ones....

Let me check for a limit...

riahc3 50 Â Team Colleague

It gets weirder and weirder....

I had some simple text in the text file I created in Notepad. Lets say "The fox"

I am able to transfer that thru PHP and it creates the file with "The fox" inside

Now lets say a text file from Java says "The fox jumped over the fence". That doesnt transfer.

What I did is I copied that text from the Java one to the Notepad one and saved it. But when I transfer now the Notepad text file it just says "The fox jumped". Nothing else.

Why?

riahc3 50 Â Team Colleague

OK, a basic txt file created in Notepad gets transfered yet a text file created by Java doesnt.....

I hate this shit.

riahc3 50 Â Team Colleague

Odd..........ftp_put gives me a warning that it cant created the file.

riahc3 50 Â Team Colleague

Well considering riahc3 and you are the only two people who have submitted entries so far, and there are going to be 3 winners, I'm pretty sure you'll be one of them based on how things stand right now.

Related to what pritaes just posted, can more than one entry per person count? Mines were just simply examples but since noone else has submitted anything....

I ask because whatever pritaes makes will obviously be better and Ill be left out of the contest...

riahc3 50 Â Team Colleague

Perhaps I'll make a run for 1, 2 and 3 :D

:(

From what diafol just posted, guess Ill be third now :(

riahc3 50 Â Team Colleague

We overwork pritaeas....

$name=$_FILES['file']['name'];
$conn_id = ftp_connect("127.0.0.1");
$login_result = ftp_login($conn_id, "user","pass"); 
ftp_pasv($conn_id, true); 
$upload = ftp_put($conn_id, $name, $_FILES['file']['tmp_name'], FTP_ASCII); 
exit;

Done.

riahc3 50 Â Team Colleague

Also, transfering the file with Windows Explorer works so its not a permissions issue....

riahc3 50 Â Team Colleague

Did some conditional ifs and all of them return true....

<?php



                $name=$_FILES['file']['name'];








                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 





                if (move_uploaded_file($_FILES["file"]["tmp_name"],getcwd()."/".$name))
                    {
                        echo ("work");


                    }
                    else
                    {
                        echo ("doesnt work");
                    }



                $fp = fopen(getcwd()."/".$name, "w");

                if ($fp==false)
                {
                    echo ("problem opening file");
                }



                echo ("hi");
                fclose($fp);



                if (ftp_put($conn_id, $name, getcwd()."/".$name, FTP_ASCII))
                {
                    echo ("working correctly");
                }
                else
                {
                    echo("problem");
                }


                exit;

BTW, this has worked in the past FTPing to this server so....

riahc3 50 Â Team Colleague

Well, Im going to continue to see what I can do with this.....

riahc3 50 Â Team Colleague

Am out of ideas right now. When I'm home I can try your code.

Thank you, Ill see them tommorow.

riahc3 50 Â Team Colleague

Im reading the documentation but I really dont see the problem..........must be something small....

riahc3 50 Â Team Colleague

Its visible, meaning I see the file; As a matter of fact, the server is next to me, I see it appear in the explorer but when I open it, it is empty when on the local side, it has text inside.

riahc3 50 Â Team Colleague

Besides, yes, I should; Remember the file is created but no content is inside.

riahc3 50 Â Team Colleague

It opens the root folder, are you sure you have write permissions there? Perhaps you need to ftp_chdir to a different folder first

Yes, theorically I should.

Its the root server to where I FTP with the user Im using all the time.

Should I chmod before it or something?

riahc3 50 Â Team Colleague
if (move_uploaded_file($_FILES["file"]["tmp_name"],getcwd()."/".$name))
                    {
                        echo ("work");


                    }
                    else
                    {
                        echo ("doesnt work");
                    }

Changed to this and it prints out work but now it says:

Warning: ftp_put() [function.ftp-put]: Could not create file. in C:\testing\page.php on line 43

Hmm....FTP server is correct AFAIK.

riahc3 50 Â Team Colleague

I suggest you do some error checking to see what exactly fails. Is the uploaded file in your current work directory? Does ftp_connect return a resource, do ftp_login and ftp_put return true?

Yup, Ill have to work if it returns true or false because there is no error message...

Ill do some if statements to print out...

riahc3 50 Â Team Colleague

WOW, for now pritaeas is going to take the first place price and Im going to take the second? :P

riahc3 50 Â Team Colleague

Well I might as well put in my code samples as entries...

riahc3 50 Â Team Colleague
<?php



                $name=$_FILES['file']['name'];


                print_r($_FILES);





                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 





                move_uploaded_file($_FILES["file"]["tmp_name"],getcwd()."/".$name);

                $fp = fopen(getcwd()."/".$name, "w");


                echo ("hi");
                fclose($fp);

                $upload = ftp_put($conn_id, $name, getcwd()."/".$name, FTP_ASCII); 


                exit;

Problably missing something obvious :(

riahc3 50 Â Team Colleague
<?php



                $name=$_FILES['file']['name'];




                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 

                move_uploaded_file($name,getcwd()."/".$name);

                $fp = fopen(getcwd()."/".$name, "w");


                fclose($fp);

                $upload = ftp_put($conn_id, $name, getcwd()."/".$name, FTP_ASCII); 


                exit;

Is this what you ment or did I understand you incorrectly? (Doenst work)

riahc3 50 Â Team Colleague
$name=$_FILES['file']['name'];




                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 

                $fp = fopen(getcwd()."/".$name, "w");


                echo ("hi");
                fclose($fp);

                $upload = ftp_put($conn_id, $name, getcwd()."/".$name, FTP_ASCII); 


                exit;

This code "works" but the location where I FTP the file TO is empty. There is no text content.

Im not sure if move_uploaded_file has anything to do with it.

riahc3 50 Â Team Colleague
<?php



                $name=$_FILES['file']['name'];




                $conn_id =  ftp_connect("127.0.0.1");

                $login_result = ftp_login($conn_id, "user","pass"); 

                ftp_pasv($conn_id, true); 

                $fp = fopen(getcwd()."/".$name.".txt", "w");

                /*I THINK I NEED SOMETHING HERE DIFFERENT THAN THE CODE IVE SEEN*/

                fclose($fp);

                $upload = ftp_put($conn_id, $name.".txt", getcwd()."/".$name.".txt", FTP_ASCII); 


                exit;

Hmmm cant quite get it...

riahc3 50 Â Team Colleague

You need to use move_uploaded_file first I think, to move the file from the temp directory to a permanent location (during your upload). If it is successful, then delete it.

Doesnt ftp_put do this?

Am not sure what kind of files you are ftp-ing, but I'd consider FTP_BINARY.

Only text nonunicode files

riahc3 50 Â Team Colleague

Sorry, my bad.

No problem. Now we are getting somewhere :)

<?php
                print_r($_FILES);
                exit;

This is the result:

Array ( [file] => Array ( [name] => filetest.txt [type] => text/plain [tmp_name] => C:\xampp\tmp\phpCB31.tmp [error] => 0 [size] => 267 ) )

OK, thats one part. Now how do I continue on to FTP that over?

Example code Ive thought up now:

$thefile=$_FILES['name'];
$conn_id = ftp_connect("127.0.0.1"); //example IP
$login_result = ftp_login($conn_id, "username","password"); 
ftp_pasv($conn_id, true); 
$fp = fopen(getcwd()."/".$thefile.".txt", "w");
/*HERE I THINK IT WOULD HAVE TO MAKE A COPY OF THE FILE WITH THE CONTENTS*/
fclose($fp);
$upload = ftp_put($conn_id, $thefile.".txt", getcwd()."/".$thefile.".txt", FTP_ASCII); 

This Ive thought up basing myself on some examples on the net. Anything wrong or different I should do???

riahc3 50 Â Team Colleague

If you could afford more memory to your JVM on the server machine. You could increase it

So how can I do this on Tomcat?

riahc3 50 Â Team Colleague

Did you search this forum (PHP) ?

Yes. Maybe the terms I used were not correct/valid so thats why it didnt show me any valid solution.