variable-assignment

Shortest way to assign a default value to a variable?

我只是一个虾纸丫 提交于 2020-01-11 08:50:27
问题 I have this right now to use a cookie value if exists otherwise use a default value: $default_carat_min = "0.25"; if($_COOKIE["diamond-search_caratMin"]) { $default_carat_min = $_COOKIE["diamond-search_caratMin"]; } I am going to have to do this with a lot of variables, and its going to get really cluttered/ugly. So I am trying to come up with a cleaner way of writing this. I tried: $default_carat_min = $_COOKIE["diamond-search_caratMin"] | "0.25"; Which did not work. I can do this: $default

Python multiple assignment and references

荒凉一梦 提交于 2020-01-10 04:18:05
问题 Why does multiple assignment make distinct references for ints, but not lists or other objects? >>> a = b = 1 >>> a += 1 >>> a is b >>> False >>> a = b = [1] >>> a.append(1) >>> a is b >>> True 回答1: In the int example, you first assign the same object to both a and b , but then reassign a with another object (the result of a+1 ). a now refers to a different object. In the list example, you assign the same object to both a and b , but then you don't do anything to change that. append only

“Expression is not assignable” — Problem assigning float as sum of two other floats in Xcode?

我的未来我决定 提交于 2020-01-09 02:14:15
问题 In a piano app, I'm assigning the coordinates of the black keys. Here is the line of code causing the error. 'blackKey' and 'whiteKey' are both customViews blackKey.center.x = (whiteKey.frame.origin.x + whiteKey.frame.size.width); 回答1: The other answers don't exactly explain what's going on here, so this is the basic problem: When you write blackKey.center.x , the blackKey.center and center.x both look like struct member accesses, but they're actually completely different things. blackKey

“Expression is not assignable” — Problem assigning float as sum of two other floats in Xcode?

别说谁变了你拦得住时间么 提交于 2020-01-09 02:14:14
问题 In a piano app, I'm assigning the coordinates of the black keys. Here is the line of code causing the error. 'blackKey' and 'whiteKey' are both customViews blackKey.center.x = (whiteKey.frame.origin.x + whiteKey.frame.size.width); 回答1: The other answers don't exactly explain what's going on here, so this is the basic problem: When you write blackKey.center.x , the blackKey.center and center.x both look like struct member accesses, but they're actually completely different things. blackKey

Php inside a javascript function?

喜你入骨 提交于 2020-01-07 03:41:06
问题 I have a feature on my users inbox that allows users to check/uncheck messages in their inbox that they want to make favourite. I'm currently testing what happens when a user checks the box (clicks on the image and causes it to go from greyed out to colour meaning the box is checked). Anyway as you can see from the code below when the box ischecked this url is suppose to be loaded: http://mysite.com/messages/favourite_checked The message_id of the row the user has checked the box on is

Check if the clicked div id matches with variable

為{幸葍}努か 提交于 2020-01-06 21:02:49
问题 I'm a coding newbie and looking for a way to check in jQuery whether the name of a certain variable corresponds to the ID of a div, and if so fire some code. Unfortunately, something about my syntax is off, and I can't figure out what. For a simple example, I want to click a div and store the ID of the div as a variable, and if I click it again the variable gets cleared. Simply assigning another boolean variable is not possible due to the rest of the code, I require the ID-check-thingy or

Check if the clicked div id matches with variable

无人久伴 提交于 2020-01-06 21:02:25
问题 I'm a coding newbie and looking for a way to check in jQuery whether the name of a certain variable corresponds to the ID of a div, and if so fire some code. Unfortunately, something about my syntax is off, and I can't figure out what. For a simple example, I want to click a div and store the ID of the div as a variable, and if I click it again the variable gets cleared. Simply assigning another boolean variable is not possible due to the rest of the code, I require the ID-check-thingy or

SegFault with Producer/Consumer File Copy

不羁岁月 提交于 2020-01-06 12:37:07
问题 back with another segfault. Not sure why, as this readdir line is the same one i've been using in other file copy assignments. Below is the code I crafted in lieu of the assignment shared here. I have commented where the segfault occurs in hopes of aiding better minds find my flaw! This is copyDirs.cpp //cmd: ./a.out [#ofConsumerThreads] [src directory] [dest directory] #include "copyDirs.h" int main(int ac,char* av[]) { pthread_mutex_init(&buflock,NULL); pthread_t prodT; if(ac == 4) { int

SegFault with Producer/Consumer File Copy

核能气质少年 提交于 2020-01-06 12:36:10
问题 back with another segfault. Not sure why, as this readdir line is the same one i've been using in other file copy assignments. Below is the code I crafted in lieu of the assignment shared here. I have commented where the segfault occurs in hopes of aiding better minds find my flaw! This is copyDirs.cpp //cmd: ./a.out [#ofConsumerThreads] [src directory] [dest directory] #include "copyDirs.h" int main(int ac,char* av[]) { pthread_mutex_init(&buflock,NULL); pthread_t prodT; if(ac == 4) { int

Javascript multiple asignment re-evaluation or result passing?

好久不见. 提交于 2020-01-06 03:18:04
问题 The multiple assignment (or is it called chaining ?) that I'm talking about is assignment such as: a = b = c = 2; ...after which a , b , and c are all equal to 2; My question of optimization is, given the following code: var dom1 = document.getElementById('layout_logos'); var dom2 = document.getElementById('layout_sitenav'); ... function layout_onscroll(){ ... dom1.style.height = dom2.style.top = maxLogoHeight - scrollTop; ... } From what I've been reading, I'm afraid the code in layout