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