Are the statements "If P is true then x exists" and "there exists x such that P is true" equivalent?

Consider these two statements:

1: P is true $implies$ $exists x$

2: $exists x$ such that P is true

Are they equivalent? If so, can the phrase "such that" be substituted by $impliedby$?

unity – My if statements are acting weird

I want the second statement to run if inADS is true and the Fire2
button is pressed

So both statements happen if isReloading = false and isFiring = true and ammo > 0 and hasScope = true and both statements manipulate weapon.gameObject.SetActive(state) just based on inADS.

Lets factor stuff out:

if(isFiring && !isReloading && ammo > 0 && hasScope){
        inADS = true;
        inADS = false;

So by fact, all you are doing is setting state of object just equal to inverse of inADS, we simplify to:

if(isFiring && !isReloading && ammo > 0 && hasScope){
    inADS = !inADS;

Try this, now it will be easier to debug isFiring, isReloading, ammo, hasScope variables and find out why your statements ran wrong.

refactoring – How would you refactor multiple if statements in order to follow Open/Closed princile

Suppose you want to show posts to users and let them to filter what posts they want to see:

  1. Filter by an author name
  2. Filter by a tag name
  3. Filter by a category title

Users are able to filter posts by following URLs:

This is the code that came to my mind which will violate Open/Closed principle:

function showPosts(type) {
  if (type === 'author') {
    return repository.getPostsByAuthorName();

  if (type === 'tag') {
    return repository.getPostsByTagName();
  if (type === 'category') {
    return repository.getPostsByCategoryTitle();

Another approach that came to my mind was implementing factory pattern:

function showPosts(type) {

  repository = "PostsBy" + type;

  return getPosts(new repository);

function getPosts(repository: AbstractRepository) {
  return repository.getPosts();

interface AbstractRepository {

class PostsByAuthor implements AbstractRepository {
  public getPosts() {

class PostsByTag implements AbstractRepository {
  public getPosts() {

What are your opinions and what other approaches you know to refactor this code?

#VALUE! error using excel 2016 nested IF statements

I’m unable to perform a simple nested IF statement on this data, the conditional seems perfect to me so it must be a formatting error or something else. I’m new to excel so I could be wrong.

This is the conditional.screenshot

Too many if statements? How to write better Python code?

A couple of weeks ago I had to do a coding challenge for a job interview. I did the challenge using Python, the code was working and I got the job. But I would like to know how (if possible) I can improve/refactor the code I’ve written.
The reviewer told my future employer there were too many if statements and that I could have written better code.
I guess this is an example of too many if statements:

def get_row_tax_percentage(product_name: str):
    exempt = is_exempt(product_name)
    imported = is_imported(product_name)
    if exempt and imported:
        return Decimal(".05")
    elif exempt and not imported:
        return Decimal("0")
    elif imported:
        return Decimal(".15")
        return Decimal(".1")

This is my public repo
I think this could be a chance to learn something new. I don’t need you guys to write code for me, but please point me to the right direction.
Thanks to anyone who is going to spend some time on this.

How up to date do bank statements need to be for a UK Visa reapplication?

So a month ago I applied for a UK visa, I was declined due to a simple mistake that I have now rectified around an invitation letter not specifying the dates. All my forms and supporting documents are in order however I noticed that my bank statement for my savings account is now not as recent.

When I applied last time my last transaction on said statement was October 21st, only one transaction has happened since then in the savings account however from the date of my new application (November 9th) obviously some time has passed.

The question is will the officer in charge consider the statement too old now as 19 days have passed? Will I need to travel to get another set of statements from my home branch that will provide only one very small transaction?

sql injection – Can you protect against SQLi without using prepared statements?

tl/dr: The ability to properly escape user input once does not mean
your company will do it every time. You can’t. Don’t even try.

You have 2 good answers for the specific question you asked. However, I wanted to touch on some broader issues that are very important here:

Prepared statements are a strong safeguard to SQLi, but they aren’t the solution to SQLi because prepared statements can’t solve all SQLi issues. You can’t user prepared statements when the table name or column name comes from user input, nor can you use them to specify pagination parameters on the query. As a result, they are a key security measure, but you can still have SQLi vulnerabilities when using prepared statements.

While it is certainly possible to use proper escaping methods to properly escape and build a single query, like in your example, this is not a successful long-term strategy. I know, because I’ve been personally involved in cleaning up breaches that happened because, years ago, a team decided, “We don’t need prepared statements, we’ll just use escaping!” That works fine as long as you can guarantee that every single developer who ever writes a query with user input understands perfectly how to escape user input in every injection point. This will never happen. Can you spot the SQLi vulnerability in this simple example?:

$result = mysql_query("SELECT * FROM users WHERE id=" . escapeSimple($_POST('user_id')))

The ability to properly escape user input once does not mean your company will do it every time. You can’t. Don’t even try.

Some more points:

  1. md5 for passwords died 15 years ago. PHP has password_hash. Use it.
  2. Never directly compare two hashes. This introduces potential side-channel attacks. Use password_verify.
  3. The mysql_query line of functions were deprecated a long time ago. Switch to mysqli or PDO
  4. Why are you explicitly checking if the username matches when you already did that in the query? Just exit if the query returned no results.

Is it always SQL injection possible when you do not use prepared statements?

Not sure what escapeSimple does exactly, but if it behaves like mysqli_real_escape_string then it’s ok, as long as you are not using some weird character encoding or forget to set it correctly (UTF8 should be ok by default, as far as I know).

Remember that using MD5 or any other simple hashing function is considered bad practice today, and you should use better functions which take more resources to compute (and with salts), for example bcrypt, argon2, etc.

I also don’t like that == in the comparison, you should always use === unless you have a good reason to want type juggling. Otherwise you are going to get into trouble and something like this might happen:

That said, your question was about avoiding SQL injection without prepared statements. Yes, it’s definitely possible to avoid it, if you are very careful and make sure every statement is correctly constructed and its parts correctly escaped. However in some cases it might be tricky, and to avoid any mistakes of course prepared statements are the way to go.

probability – Prove or disprove some statements about independent events.

The Question:

Given three events A,B,C. (For all this question the conditional property is well defined).
a) Knowing that:
$P(Acap Bcap C)=P(Acap B)P(C)$
And the above equality being right if we swap any event with it’s complement, for example:
$P(Acap Bcap C^c)=P(Acap B)P(C^c)$

Prove or disprove:
1- Events $A,C$ are independent.
2- Given $A$, the events $B,C$ are independent. (in other words: $P(Bcap C|A)=P(B|A)P(C|A)$).

b) Knowing that $A,C$ are independent, and $B,C$ are independent..
Prove or disprove:
1- Given $A$, the events $B,C$ are independent.
2- $P(Acap Bcap C)=P(Acap B)P(C)$

My Work:
a) 1- So the goal here is to check if $P(Acap C)=P(A)P(C)$.
I’m trying to reach that by writing: $P(Acap Bcap C) = P(B)P(A|B)P(C|Acap B)$, I’ve tried to re-adjust it to:
$P(Acap Ccap B) = P(Acap C)P(B|Acap C)$. now using the complements: $P(Acap Ccap B^c)=P(Acap C)P(B^c|Acap C)$.
And here I got stuck, I didn’t know how to reach my goal, tried to find a counter example and it was very long (since I need to care about all the complements) and it didn’t work.

2-Again tried to re-adjust again (like in (1)), but I really didn’t reach anything interesting that’s close to the goal.

b) 1- I know that $P(Acap C)=P(A)P(C)$ and $P(Bcap C)=P(B)P(C)$. gotta proof that: $P(Bcap C|A)=P(B|A)P(C|A)$.
$P(B|A)P(C|A)=frac {P(Bcap A)P(Ccap A)}{P(A)^2}=frac {P(Bcap A)P(C)P(A)}{P(A)^2}= frac{P(Bcap A)P(C)}{P(A)}$, And here I’m stuck again…

2- Tried to readjust a little and I’ve no idea how to prove or disprove.

I want to know how off is my work from the solution, I will really appreciate any hints or feedback on my work.
I have tried to think about it intuitively but it was much harder, and I’m wondering if that could help.
Thanks in advance to everyone.

What is Problem Statements

Can someone help me clarify what are the Problem Statements and Hypothesis Statements in UX Research? Do you need to do a single statement per project or multiple? What are the differences from User Stories?