[Python] What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

Standard

In the following method definitions, what does the * and ** do for param2?

===========

The *args and **kwargs is a common idiom to allow arbitrary number of arguments to functions as described in the section more on defining functions in the Python documentation.

The *args will give you all function parameters as a tuple: Continue reading

How to return the response from an asynchronous call?

Standard

I have a function foo which makes an Ajax request. How can I return the response from foo?

I tried to return the value from the success callback as well as assigning the response to a local variable inside the function and return that one, but none of those ways actually return the response.

Continue reading

How can I prevent SQL-injection in PHP?

Standard

If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example:

That’s because the user can input something like value'); DROP TABLE table;--, and the query becomes:

INSERT INTO table (column) VALUES(‘value’); DROP TABLE table;–‘)

What can be done to prevent this from happening? Continue reading

Why is processing a sorted array faster than an unsorted array?

Standard

Here is a piece of C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes the code almost six times faster.

Continue reading