conditional-statements

Flutter/Dart - How to use Return Data from Http Post in a Conditional to avoid Duplicate upload?

旧街凉风 提交于 2020-08-10 19:15:50
问题 Upon clicking a FlatButton an audio file is uploaded to a directory on my server, renamed and the new path/name is saved to a PHP/mySQL database. I'd like to prevent the button from uploading the same file twice. But I can't use a mySQL query in a conditional as the name of the file has been changed before insertion into the database. So I've got the oldname of the file extracted from the response.body upon a successful 200 upload, but not sure how to get the oldname back to the button. Here

conditional vectorized calculation with numpy arrays without using direct masking

一笑奈何 提交于 2020-08-10 03:38:01
问题 following up on another question import numpy as np repeat=int(1e5) r_base = np.linspace(0,4,5) a_base = 2 np.random.seed(0) r_mat = r_base * np.random.uniform(0.9,1.1,(repeat,5)) a_array = a_base * np.random.uniform(0.9,1.1, repeat) # original slow approach def func_vetorized_level1(r_row, a): if r_row.mean()>2: result = np.where((r_row >= a), r_row - a, np.nan) else: result = np.where((r_row >= a), r_row + a, 0) return result # try to broadcast this func to every row of r_mat using list

Click an element if another element contains a specific text. Automated Test with Protractor

折月煮酒 提交于 2020-08-08 05:15:18
问题 I need to check which one of 3 elements contains the text "10%" but I am not sure I am getting correctly the text of the element. When I run the code I am not getting errors but the if condition is always false(also when it should be true). My javascript code inside the spec: await driver.wait(until.elementIsVisible(await driver.findElement(By.css("tr:nth-child(1) .font-weight-bold-light > span"))), 30000) await driver.wait(until.elementIsVisible(await driver.findElement(By.css("tr:nth-child

MongoDB assymetrical return of data, first item in array returned in full, the rest with certain properties omitted?

蹲街弑〆低调 提交于 2020-07-10 10:24:46
问题 I'm new to MongoDB and getting to grips with its syntax and capabilities. To achieve the functionality described in the title I believe I can create a promise that will run 2 simultaneous queries on the document - one to get the full content of one item in the array (or at least the data that is omitted in the other query, to re-add after), searched for by most recent date, the other to return the array minus specific properties. I have the following document: { _id : ObjectId(

MongoDB assymetrical return of data, first item in array returned in full, the rest with certain properties omitted?

回眸只為那壹抹淺笑 提交于 2020-07-10 10:23:44
问题 I'm new to MongoDB and getting to grips with its syntax and capabilities. To achieve the functionality described in the title I believe I can create a promise that will run 2 simultaneous queries on the document - one to get the full content of one item in the array (or at least the data that is omitted in the other query, to re-add after), searched for by most recent date, the other to return the array minus specific properties. I have the following document: { _id : ObjectId(

How can I conditionally instantiate an object?

安稳与你 提交于 2020-07-09 04:33:17
问题 I'm trying to do some conditional work like so: Type object; if (cond) { doSomeStuff(); object = getObject(); doMoreStuff(); } else { doSomeOtherStuff(); object = getDifferentObject(); doEvenMoreStuff(); } use(object); The only way I can think of solving this is the duplicate the use code (which is actually inline code in my application) and declare object in each branch of the if block. If I wanted to avoid duplicate code I'd have to wrap it in some use function, as I have above. In a real

PostgreSQL custom exception conditions

旧巷老猫 提交于 2020-07-08 04:32:09
问题 Is it possible to create custom conditions when I raise an exception? Consider the following example: BEGIN y := x / 0; EXCEPTION WHEN division_by_zero THEN RAISE NOTICE 'caught division_by_zero'; RETURN x; END; Here I use 'division_by_zero' condition to catch the exception. What I'd like to do is something like this: BEGIN [...] RAISE custom_condition; EXCEPTION WHEN custom_condition THEN [...] END; so that I don't interfere with possible standard exceptions. I could just do y:= 1 / 0; and