conditional-statements

Return the split value if the user had entered the path else return blank

十年热恋 提交于 2019-12-25 09:04:06
问题 I need to display the name and split path of the path entered by a user dynamically. For that, I had split the path entered by the user and grab only certain part of it. For e.g. if the user enters path as: /content/mypath/myfolder/about/images/abc.jpg Then I am displaying images/abc.jpg. However, let's say the user only enters the name and doesn't enter the path, at least the name should be applied & displayed in that case. But it displays 0 everytime I enter a path. How do I fix this? $

Adding more than one string to a controller find condition?

别来无恙 提交于 2019-12-25 09:01:14
问题 I have the following code in one of my Rails (3.1) controllers: @count = Call.where(:destination => current_user.destination_id).count @count_day = Call.where('created_at > ?', 1.days.ago).count @count_month = Call.where('created_at > ?', 30.days.ago).count They are all working as expected, but I am trying to somehow merge two of them together so it shows the count of calls created in the last 1 day, but only for calls with a destination that matches the current users destination_id value. I

How do i check conditions with a list in python 3

送分小仙女□ 提交于 2019-12-25 09:01:02
问题 My name is Edwin i am new to programming but i love to learn. I have a assignment for school and i must build a program that rates passwords. but i have a litle problem now. As you can see i made 3 lists with every character. If i run this program it will not show "uw wachtwoord is Sterk" if the conditions klein and groot and nummers and symbols are true. how do i fix this? btw i can't make use of isdigit,isnumeric and such. thank you in advance! print ("Check of uw wachtwoord veilig genoeg

Does the Order of Conditions affect Performance?

不打扰是莪最后的温柔 提交于 2019-12-25 08:34:30
问题 Does it matter how I order the conditions in Python in respect to the speed of the script? In SQL e.g. it does not as the "Interpreter" assumes which condition ordering would be the fastest. In Python, as far as I know, the order of conditions will be taken as given by the interpreter. So as an example, if I chain or-conditions, is it better to order the conditions by assumed time they will consume because maybe the interpreter stops even looking for the other conditions when the first one

R: Add column with condition-check on three columns?

不羁的心 提交于 2019-12-25 08:00:03
问题 My df1 is as follows: df1 <- data.frame(A=c("a","b","c","d","e"), B=c("f","g","t","g","u"), C=c("M","NA","NA","NA","M"), D=c("A","NA","NA","NA","NA"), E=c("NA","NA","NA","NA","G"), G=c(1:5)) A B C D E G 1 a f M A NA 1 2 b g NA NA NA 2 3 c t NA NA NA 3 4 d g NA NA NA 4 5 e u M NA G 5 I want to add column based on the readings in column C, D and E. If all are NA, I want to add X to column H. If anyone of them are not NA, I want to add YES to column H. The results is as follows: A B C D E G H 1

Rails - using CSS on some condition

血红的双手。 提交于 2019-12-25 07:45:45
问题 I have a requirement to make a app that has a view. In that view I need to check a condition and if it is true, then need to color a table row appropriately. The easiest way to do this is just to use different header in the view. But how to do it if I want to keep all my styling information in CSS? 回答1: If it's just a row you want to colour then you can do it in the view, no need to mess around with headers: <tr class="<%= "blue" if some_condition %>"> <td>Your text</td> </tr> Or: <% if some

Smarty 3: if, mixed conditions & operators

岁酱吖の 提交于 2019-12-25 05:08:38
问题 well... can you tell me why this works: {if !$conta|contains:"word1" && ($product->id_category_default < 388 || $product->id_category_default > 475)} and this not: {if (!$conta|contains:"word1" || !$conta|contains:"word2") && ($product->id_category_default < 388 || $product->id_category_default > 475)} where is the syntax error? 回答1: Try this instead: {if !($conta|contains:"word1" || $conta|contains:"word2") && ($product->id_category_default < 388 || $product->id_category_default > 475)} 来源:

How to apply condition for specific page in magento?

为君一笑 提交于 2019-12-25 04:46:11
问题 I want to apply condition for specific page coming from url. It is neither a category page nor a custom cms page. Url is like localhost/project/index.php/news/blog.html. I want to apply condition for this 'news/blog.html' . News or blog is not a category and not any cms page. Can anybody help me? 回答1: It depends on the type of condition, you want to user over there. You can try with the following. 1. Try to put a observer in the relevant controller using the cheat sheet https://www.nicksays

SQL Server Conditional Foreign Key

拜拜、爱过 提交于 2019-12-25 02:34:27
问题 I have two tables in my SQL Server database, Foo and Bar. Table Foo is like so: +-------+ | Foo | +-------+ | Id | | Type | | Value | +-------+ The table has values like: +----+--------+-----------+ | Id | Type | Value | +----+--------+-----------+ | 1 | Status | New | | 2 | Status | Old | | 3 | Type | Car | | 4 | State | Inventory | | 5 | State | Sold | +----+--------+-----------+ The table Bar is like so: +----------+ | Bar | +----------+ | Id | | TypeId | | StatusId | | StateId | +--------

How to apply conditional constraints to Python Pulp function

冷暖自知 提交于 2019-12-24 23:37:13
问题 I'm setting up a linear optimization using Pulp in Python. I would like to set up a conditional constrain to the problem. Like, I want to Maximize the profit of a factory. For the cost of the material, the first 1000 units cost $5 each, any more unit cost $3. For example, if the factory order 1100 units, total cost will be 1000*5+100*3. I have a list of material: material_list , a dictionary of benchmark for the materials: benchmark_dic={material_a: 1000, material_b:2000 ....} , a dictionary