vidaj 35 Junior Poster in Training
RewriteEngine On
RewriteRule ^(.*)$ index.php?req=preview&pro_name=$1

That should (probably) do the trick. You should create a good structure for your URLs if you want to have URLs for anything else than pro_names.

/person/Rehman1234
/blabla/somethingelse

RewriteRule ^person/(.*)$ index.php?req=preview&pro_name=$1
RewriteRule ^blabla/(.*)$ index.php?req=blabla&value=$1

Please see http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html for more info on how mod_rewrite works

vidaj 35 Junior Poster in Training

It's not that weird, actually. | is a bitwise-or, so it create a result with all the bits that are set in !$_POST and !$_POST and !$_POST. If the number this creates is 0, the if won't have any effect. If the number is anything but 0, the if will kick in. (correct me if I'm wrong). But he really should use || to avoid any nasty bugs :P

Good catch, though. Didn't see it when I looked through the code.

vidaj 35 Junior Poster in Training

There's an extra '}' at line 77. Don't know if that's the problem.

You should also make use of the mysql_error() to see what's wrong.

Add this after the insert:

if (mysql_affected_rows($conn) != 1) {
    die(mysql_error());
}
vidaj 35 Junior Poster in Training

Check your httpd.conf file in the apache installation. Search for mod_rewrite and uncomment the line. Then you should be able to use it. Xammp has mod_rewrite disabled by default

vidaj 35 Junior Poster in Training

Is this what you are after?

If you change your repeat function to

def repeat(f, n):
    totalFlips = 0
    for i in range(n):
        results = ""
        while not results.endswith('hth'):
            results += f()
            totalFlips += 1
        print("It took {0} flips to find HTH".format(len(results)))
    return totalFlips

If you call this with repeat(flip, 10000) it will print out 10000 lines with "It took ..." and return the actual number of flips it took.

And by the way, the cheads and ctails in the flip-function resets for every flip. If you want to keep this, I would suggest to create a class for it.

class Flipper(object):
    def __init__(self):
        self.cheads, self.ctails = 0, 0
    
    def flip(self):
        flip = random.choice((0,1))
        if flip == 0:
            self.cheads += 1
            return 'h'
        else:
            self.ctails += 1
            return 't'

    def repeat(self, f, n):
        totalFlips = 0
        for i in range(n):
            results = ""
            while not results.endswith('hth'):
                results += f()
                totalFlips += 1
            print("It took {0} flips to find HTH".format(len(results)))
        return totalFlips

flipper = Flipper()
totalFlips = flipper.repeat(flipper.flip, 10000)
vidaj 35 Junior Poster in Training

You have to convert the string from the input to an integer.

x = int(input("Enter a value: "))

Remember you have to catch the exception that will be raised if the input is not a number.

vidaj 35 Junior Poster in Training

First off, to include a file in a different folder, you don't have to change your current working directory. A folder in python is called a package, and the file in that folder is called a module. To correctly create a package, you have to create a file called __init__.py inside that folder.

When you have created that file, all you have to do is

from lib.sprite_class import Sprite

mySpriteObject = Sprite()

If you have a programming background from java or a similair language, it's the usual practice to have each class in a separate file. In python you don't do that. You have similair classes in one module (i.e. one file) and you structure your modules in packages (i.e. folders). It's usually not a good idea to bundle each class in a separate module inside a folder (package) called lib. It's counter-intuivite. Think about which classes goes together, and bundle those in the same module.

Example from standard python library (version 3.0)
there's a package called html. That package has a module called client. The client-module has classes and functions that are related to the html-client.

There's a package called urllib. That package has a module called parse. The parse module has classes and functions that are related to parsing urls.

If you manage to structure your code like this, and try to keep each module separate, i.e. you don't have inter-dependencies in your module, your code will (probably) be easier to understand …

vidaj 35 Junior Poster in Training

If I understand your code correctly, you have two lists. One list called english_to_german where you store the words in "pairs", i.e. index 0 is the english word, and index 1 is the german translation. And the other way around in german_to_english

The way you can do this with a for loop is:

for word in phrase.split():
    position = english_to_german.index(word) + 1
    german = english_to_german[position]
    location = german_to_english.index(german) + 1
    english = german_to_english[location]
    print(english)

However, this is a quite inefficient way to do it. My choice would be using two dicitonaries instead.

english_to_german = {}
german_to_english = {}
# populate the dicitonaries
# english_to_german['english_word'] = 'deutche_wort'
# and the other way around with the german_to_english

for word in phrase.split():
    german_word = english_to_german[word]
    english_word = german_to_english[german_word]
    print(english_word)

The reason why this is better, is because dictionaries uses O(1) time to look up a value. A list uses O(n) time to look it up. As your lists grow, the code will run slower and slower, but this is not the case with dictionaries :)

vidaj 35 Junior Poster in Training

Maybe http://www.py2exe.org/ is what you are looking for?

vidaj 35 Junior Poster in Training

Well, you have to mount it properly in the OS. Then you should be able to access it like any other drive.

vidaj 35 Junior Poster in Training

From the module inspect 's documentation: inspect.getsourcelines(object) Return a list of source lines and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the original source file the first line of code was found. An IOError is raised if the source code cannot be retrieved. inspect.getsource(object) Return the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An IOError is raised if the source code cannot be retrieved.

vidaj 35 Junior Poster in Training

Here a function that creates a 3xn matrix.

def create_3n_matrix(n):
    return [[[None for x in range(n)] for x in range(n)] for x in range(n)]

calling create_3n_matrix(3) creates the following:

[[[None, None, None], [None, None, None], [None, None, None]], [[None, None, None], [None, None, None], [None, None, None]], [[None, None, None], [None, None, None], [None, None, None]]]
vidaj 35 Junior Poster in Training
final int[] fromStop = {1, 2, 3, 3, 4, 5};
final int[] toStop =   {3, 4, 5, 1, 2, 3};

List<Passenger> passengers = new ArrayList<Passenger>()
for (int i = 1; i < Main.PASSENGERS; i++) {
    bus = // get the bus you want the passenger to take
    Passenger passenger =  new Passenger(i, fromStop[i - 1], toStop[i - 1], bus);
    passengers.append(passenger);
    passenger.start()
}

// Wait for every passenger to finish
for (Passenger passenger: passengers) {
    if (passenger.isAlive()) {
         passenger.join();       
    }
}

Think that should do the trick.

vidaj 35 Junior Poster in Training

You have to implement the run() method so the thread can actually do something, or wrap your code in a Runnable and pass that to new Thread(myRunnablePassangerObject).start()

Maybe this can help you on your way: http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html

vidaj 35 Junior Poster in Training

You have to use the x and y values for it to have any effect.

Box((20 + x, 20 + y), 100 + x, 100 + y)     #the house

if Box takes x1, y1, x2, y2 as arguments the code above should work

vidaj 35 Junior Poster in Training

As you probably already know, and have been told earlier in this thread, iterative means you have to solve the problem in one function without calling the same function from within the same function (recursion)

What I would use for this is lists.

Define a list with the initial solutions, i.e for n = 0 and n = 1. Then do a loop and calculate every solution from 2 to and including n.

To start you off:

def fib(n):
    solutions = [1, 1]     # Create the list containing the initial solutions
    # Test if you already know the solution for n, if so - return the solution

    for x in range(2, n + 1):   # iterate over every value from fib(2) to fib(n) and generate the solutions
          # here you calculate the solution for fib(x) by appending (x - 1) + (x - 2) from solutions to the list

Post your function back and let's see what you got :)

-Vidaj-

vidaj 35 Junior Poster in Training

I'm guessing that you have the sourcecode for B.jar.

The first thing that the program does is to start a new thread that listens to a socket. This thread won't stop (hopefully) until the program stops executing. Whenever it detects an incoming connection on the listening port, just send a response back and terminate the connection. Rince and repeat :)

So before you call B.jar, you try to send a message on the socket. If there's no answer, start B.jar. If there is an answer, you know it's already started :)

Depending on what messages you send, you can implement different behaviour in B.jar. I.e. you can send "QUIT" and when it receives a string with that content, it terminates.

Take a look at http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html for more information on how to code a client/server pair. The server-code goes into B.jar and the client code goes into A.jar before you start the new process.

-vidaj-

vidaj 35 Junior Poster in Training

In java 1.5 they introduced the ProcessBuilder which you can use.

void jarStarter() {
    String jarFile = "B.jar";
    try {
        /* Start the jar-file. */
        final Process process startJar(jarFile, true);

        /* Get the file's output. */
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;

        /* Start reading output and print it to console. If we don't read the programs output, it won't function properly. You don't have to print it out again, but you have to read it. */
        while ((line = br.readLine()) != null) {
            System.out.println(line);

            /* Kill the other process whenever you want to :) The only thing you need in order to kill it, is the process-object and calling the #destroy-method on it. */
            if (line.equals("LOADING. DO NOT TERMINATE PROCESS OR COMPUTER.")) {
                 process.destroy();
            }
        }
   
        /* When the output becomes null, the program terminated itself. */
        System.out.println("Program terminated!");
    } catch (InterruptedException e) {
          e.printStackTrace();
    } catch (IOException e) {
          e.printStackTrace();
    }
    
}

Process startJar(String jarFile, boolean mergeStreams) throws InterruptedException,IOException  {

    /* Build the command to be executed. */
    List<String> command = new ArrayList<String>();
    command.add("java");
    command.add("-jar");
    command.add(jarFile);

    ProcessBuilder builder = new ProcessBuilder(command);
    Map<String, String> environ = builder.environment();
    builder.directory(new File(System.getenv("temp")));

    /* Merge the error-stream into the standard output-stream. */
    if (mergeStreams) {
        builder.redirectErrorStream();
    }

    /* Start the process. */
    final Process process = builder.start();
    
    return process;
  }
}

Mind that I wrote the code directly in this window, so it probably won't compile, but you'll probably figure out the …

vidaj 35 Junior Poster in Training

It all depends on what you are doing.

If you are starting B.jar from A.jar as a new process, it's quite simple. Just kill the process. If you launch the two programs seperately from the OS, I don't think you can do it in plain java. I think you can write som JNI code to interface with the OS and get the process ID for the other program and ask the OS to kill it, but it would only work on the OS you are writing JNI code for.

You could always use IPC (Inter-process communication) where B.jar listens to a socket, and when A.jar signals B.jar it gracefully shuts down.

Maybe there's a twisted way you can interface with the JVM and ask it to shut down the other process, but I doubt it.

Hope this helps

-vidaj-