conversation
listlengths
2
20
[ { "from": "human", "value": "The following article from CNN describes a Michigan police officer being put on administrative leave for having KKK material at his home: https://www.cnn.com/2019/08/10/us/michigan-officer-placed-on-leave-kkk-document-house/index.html. The materials were discovered while a potential buyer was touring his house. \nAlthough I vehemently condemn the KKK, doesn't this officer have the right to display whatever he wants in his home so long as it doesn't actively and deliberately call for violence? Aren't these articles protected under the first amendment? I realize this is an extreme example, and as a police officer his job requires interacting with all races, but unless it can be shown that he's bigoted and that it negatively affected his job performance, isn't it illegal to fire him? \nEmployers can restrict speech according to company policy while at work, but we all have to go home at some point. Can those restrictions follow us after clocking out? " }, { "from": "gpt", "value": "In general, employers in the United States are free to fire you for your speech. The First Amendment does not apply to anyone except the government (other than a narrow set of circumstances where private parties act on behalf of the government or take on government roles, like when private universities employ campus police). If the officer was being fired from a job at a private company, this would not be an interesting question -- the answer would clearly be \"no, there is no First Amendment claim here.\" That’s not to say labor laws might not come into play (for instance, federal law prohibits firing an employee for organizing a union, and some states prohibit firing for off-duty political speech); however, labor law protections exist by statute and are not derived from the First Amendment.\nWhat makes this interesting is that the government is involved. Unlike private employers, government agencies are bound by the First Amendment. In Pickering v. Board of Education, the Supreme Court held that this does restrict them in their role as employer and that they can't necessarily fire an employee for speech. Pickering imposes a balancing test, where the harm to the employee's First Amendment rights is weighed against the government's interest in efficient operation. Courts have given particular leeway to police departments punishing speech that would undermine public trust and confidence in the department. A police officer expressing racist views, even privately, can seriously hamper the effectiveness of the department if the speech gets linked back to them. For instance, see Pappas v. Giuliani, where the Second Circuit upheld the firing of an NYPD officer for anonymously mailing racist diatribes from home in his off-duty time.\nAnother answer suggests that the main question is a public safety one: whether the officer could be trusted to carry out his duties without bias. But that's not the only legitimate consideration for the government employer. The courts have repeatedly held that public perception of an agency is a legitimate concern, especially when it comes to agencies (like the police) whose job requires maintaining good relations with the community. In Pappas, the officer was assigned as a computer operator who had no contact with the public, but he was still a police officer whose speech had a high potential to undermine NYPD community relations." } ]
[ { "from": "human", "value": "What does strength refer to in mathematics? Is it a formal idea?" }, { "from": "gpt", "value": "Suppose you have a theorem that says \"If $X$, then $Y$.\" There are two ways to strengthen such a theorem:\n\n* Assume less. If you can reduce the number of hypotheses, but still prove the same conclusion, then you have proved a more \"powerful\" result (in the sense that it applies in more situations).\n* Prove more. If you can keep the same hypotheses, but add more information to the conclusion, then you have also produced a more \"powerful\" result.\n\nHere is an easy example from Geometry.\n\n Let $ABCD$ be a (non-square) rectangle. Then the internal angle bisectors of the vertices intersect at four points $WXYZ$, which are the vertices of a rectangle.\n\n(You need the condition that $ABCD$ is not a square because if it is a square then all four angle bisectors coincide at a single point.)\nHere are a few ways to strengthen the theorem:\n\n* The hypothesis \"$ABCD$ is a (non-square) rectangle\" can be relaxed to the more general \"$ABCD$ is a (non-rhombic) parallelogram\". The conclusion that $WXYZ$ is a rectangle still holds.\n* Alternatively, you can keep the original hypothesis that $ABCD$ is a (non-square) rectangle, and strengthen to the conclusion to say that $WXYZ$ is not just a rectangle, but a square.\n* Having done that, you can then strengthen the conclusion of the theorem even more, by noting that the diagonal of square $WXYZ$ is equal in length to the difference of the lengths of the sides of $ABCD$.\n* Once you know that, you can now strengthen the theorem even more by (finally) removing the hypothesis that $ABCD$ is non-square, and including the case in which the four angle bisectors coincide at a single point as forming a \"degenerate\" square with a diagonal of length zero.\n" } ]
[ { "from": "human", "value": "Does vegetarianism affect life expectancy?\nIs an average vegetarian supposed to live longer just because of their diet?" }, { "from": "gpt", "value": "Yes, according to a paper by the American Society for Clinical Nutrition.\n\n> Results: Our review of the 6 studies found the following trends: 1) a very low meat intake was associated with a significant decrease in risk of death in 4 studies, a nonsignificant decrease in risk of death in the fifth study, and virtually no association in the sixth study; 2) 2 of the studies in which a low meat intake significantly decreased mortality risk also indicated that a longer duration (≥ 2 decades) of adherence to this diet contributed to a significant decrease in mortality risk and a significant 3.6-y (95% CI: 1.4, 5.8 y) increase in life expectancy; and 3) the protective effect of a very low meat intake seems to attenuate after the ninth decade. Some of the variation in the survival advantage in vegetarians may have been due to marked differences between studies in adjustment for confounders, the definition of vegetarian, measurement error, age distribution, the healthy volunteer effect, and intake of specific plant foods by the vegetarians.\n\nTL;DR:\n\n* less meat = less risk of death,\n* less meat for a longer time = an average of a 3 year longer lifespan + less risk of death,\n* after 90 years of no meat it stops decreasing your risk of death.\n\n\n> Conclusion: Current prospective cohort data from adults in North America and Europe raise the possibility that a lifestyle pattern that includes a very low meat intake is associated with greater longevity.\n\nSo yes, scientific research says that vegetarianism could help you live longer, but it primarily decreases your risk of death. (i.e. you might not live to 105, but you probably won't die at 55)" } ]
[ { "from": "human", "value": "What is the difference between an object and a companion object in a class in kotlin?\nExample:\n```class MyClass {\n object Holder {\n //something\n }\n companion object {\n //something\n }\n}\n```\nI already read that companion object shall be used, if the containing parameters/methods are closely related to its class.\nBut why is there also the possibility of declaring a normal object in the class? Because it behaves exactly like the companion, but it must have a name.\nIs there maybe a difference in its \"static\" (I'm from the java side) lifecycle? " }, { "from": "gpt", "value": "There are two different types of ```object``` uses, expression and declaration.\nObject Expression\nAn object expression can be used when a class needs slight modification, but it's not necessary to create an entirely new subclass for it. Anonymous inner classes are a good example of this.\n```button.setOnClickListener(object: View.OnClickListener() {\n override fun onClick(view: View) {\n // click event\n }\n})\n```\nOne thing to watch out for is that anonymous inner classes can access variables from the enclosing scope, and these variables do not have to be ```final```. This means that a variable used inside an anonymous inner class that is not considered ```final``` can change value unexpectedly before it is accessed.\nObject Declaration\nAn object declaration is similar to a variable declaration and therefore cannot be used on the right side of an assignment statement. Object declarations are very useful for implementing the Singleton pattern.\n```object MySingletonObject {\n fun getInstance(): MySingletonObject {\n // return single instance of object\n }\n}\n```\nAnd the ```getInstance``` method can then be invoked like this.\n```MySingletonObject.getInstance()\n```\nCompanion Object\nA companion object is a specific type of object declaration that allows an object to act similar to static objects in other languages (such as Java). Adding ```companion``` to the object declaration allows for adding the "static" functionality to an object even though the actual static concept does not exist in Kotlin. Here's an example of a class with instance methods and companion methods.\n```class MyClass {\n companion object MyCompanionObject {\n fun actsAsStatic() {\n // do stuff\n }\n }\n fun instanceMethod() {\n // do stuff\n }\n}\n```\nInvoking the instance method would look like this.\n```var myClass = MyClass()\nmyClass.instanceMethod()\n```\nInvoking the companion object method would look like this.\n```MyClass.actsAsStatic()\n```\nSee the Kotlin docs for more info." } ]
[ { "from": "human", "value": "I've rooted my phone. Now what? What do I gain from rooting?" }, { "from": "gpt", "value": "In few words, rooting an Android system means overcome the limitations that were imposed over it by the manufacturer. People may want that for different reasons, but the main one is freedom. Having a rooted phone means you've got all the control over your device.\n\nThe main reason people root phones is to install a custom ROM. Custom ROMs are often known for improvements in performance and exclusive features that are not present on manufacturer ROMs, like installing apps on sdcard or taking screenshots. Custom ROMS can also become a system update alternative for those devices that were abandoned by their manufacturers. You can see a review of popular ROMS, as an example, here.\n\nRooting Android also allows you to uninstall stock apps that you don't use or don't want, besides those that violates user's privacy (see CarrierIQ). Another main reason for doing that is to gain more space on internal storage. A rooted device lets you install almost any app that requires root access. Those apps generally aim to do something that would not be possible without that privilege. A lot of useful apps were shown on the previous answer, but you may find a lot more available on Google Play. You can find a list of good apps here." } ]
[ { "from": "human", "value": "Is there a better way to determine whether a variable in ```Pandas``` and/or ```NumPy``` is ```numeric``` or not ? \nI have a self defined ```dictionary``` with ```dtypes``` as keys and ```numeric``` / ```not``` as values." }, { "from": "gpt", "value": "You can use ```np.issubdtype``` to check if the dtype is a sub dtype of ```np.number```. Examples:\n```np.issubdtype(arr.dtype, np.number) # where arr is a numpy array\nnp.issubdtype(df['X'].dtype, np.number) # where df['X'] is a pandas Series\n```\nThis works for numpy's dtypes but fails for pandas specific types like pd.Categorical as Thomas noted. If you are using categoricals ```is_numeric_dtype``` function from pandas is a better alternative than np.issubdtype.\n```df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0],\n 'C': [1j, 2j, 3j], 'D': ['a', 'b', 'c']})\ndf\nOut:\n A B C D\n0 1 1.0 1j a\n1 2 2.0 2j b\n2 3 3.0 3j c\ndf.dtypes\nOut:\nA int64\nB float64\nC complex128\nD object\ndtype: object\n```\n\n```np.issubdtype(df['A'].dtype, np.number)\nOut: True\nnp.issubdtype(df['B'].dtype, np.number)\nOut: True\nnp.issubdtype(df['C'].dtype, np.number)\nOut: True\nnp.issubdtype(df['D'].dtype, np.number)\nOut: False\n```\nFor multiple columns you can use np.vectorize:\n```is_number = np.vectorize(lambda x: np.issubdtype(x, np.number))\nis_number(df.dtypes)\nOut: array([ True, True, True, False], dtype=bool)\n```\nAnd for selection, pandas now has ```select_dtypes```:\n```df.select_dtypes(include=[np.number])\nOut:\n A B C\n0 1 1.0 1j\n1 2 2.0 2j\n2 3 3.0 3j\n```" } ]
[ { "from": "human", "value": "I've come across the polynomial algorithm that solves 2SAT. I've found it boggling that 2SAT is in P where all (or many others) of the SAT instances are NP-Complete. What makes this problem different? What makes it so easy (NL-Complete - even easier than P)?" }, { "from": "gpt", "value": "Here is a further intuitive and unpretentious explanation along the lines of MGwynne's answer.\nWith $2$-SAT, you can only express implications of the form $a \\Rightarrow b$, where $a$ and $b$ are literals. More precisely, every $2$-clause $l_1 \\lor l_2$ can be understood as a pair of implications: $\\lnot l_1 \\Rightarrow l_2$ and $\\lnot l_2 \\Rightarrow l_1$. If you set $a$ to true, $b$ must be true as well. If you set $b$ to false, $a$ must be false as well. Such implications are straightforward: there is no choice, you have only $1$ possibility, there is no room for case-multiplication. You can just follow every possible implication chain, and see if you ever derive both $\\lnot l$ from $l$ and $l$ from $\\lnot l$: if you do for some $l$, then the 2-SAT formula is unsatisfiable, otherwise it is satisfiable. It is the case that the number of possible implication chains is polynomially bounded in the size of the input formula.\nWith $3$-SAT, you can express implications of the form $a \\Rightarrow b \\lor c$, where $a$, $b$ and $c$ are literals. Now you are in trouble: if you set $a$ to true, then either $b$ or $c$ must be true, but which one? You have to make a choice: you have 2 possibilities. Here is where case-multiplication becomes possible, and where the combinatorial explosion arises.\nIn other words, $3$-SAT is able to express the presence of more than one possibility, while $2$-SAT doesn't have such ability. It is precisely such presence of more than one possibility ($2$ possibilities in case of $3$-SAT, $k-1$ possibilities in case of $k$-SAT) that causes the typical combinatorial explosion of NP-complete problems. " } ]
[ { "from": "human", "value": "Why isn't Sectumsempra an Unforgivable Curse?" }, { "from": "gpt", "value": "Not many people knew Sectumsempra - they'd need to know it exists to ban it.\nSeverus Snape invented Sectumsempra while at Hogwarts, and wrote it down in his Potions book. He doesn't seem to have told many people about it, it's possible he didn't tell anyone at all.\n\n“Harry was about to put his book away again when he noticed the corner of a page folded down; turning to it, he saw the Sectumsempra spell, captioned ‘For Enemies’, that he had marked a few weeks previously.” - Harry Potter and the Half-Blood Prince, Chapter 24 (Sectumsempra)\n\nHis book was hidden away until Harry found it, and Harry didn't tell the rest of the wizarding world about it either. Severus himself was seen using Sectumsempra when the Order was moving seven Harrys, and Harry had used it a few times after he found it in Snape's old book. Lupin knows of it, since he described it as one of Snape's specialties.\nHowever, they are probably some of the only people who know it - it isn't widely known like the three Unforgivable Curses. No one else, either in the Death Eaters or the Order of the Phoenix, is ever said to use it. It's likely that the Ministry didn't even know of it. Therefore, the Ministry wouldn't have even been able to make the decision to classify it as an Unforgivable Curse, since they would likely not have even known it existed.\nIf the Ministry knew about it, would it be classified as Unforgivable?\nThe reason it wasn't classified as an Unforgivable Curse is because the Ministry wouldn't have known about it - they would be unable to make any decision on something they don't know exists. That, by itself, doesn't say whether the Ministry would classify it as one if they knew about it.\nNot all potentially harmful spells are classified as Unforgivable Curses.\nIt's nowhere near guaranteed, though, that if the Ministry knew about Sectumsempra, that they'd classify it as an Unforgivable Curse. There are other spells that could clearly do harm. Just to give a few examples - Confringo, Flagrante, and the creation of Fiendfyre are all potentially harmful but not Unforgivable.\nIt's never mentioned why those three curses are classified as Unforgivable and others aren't, but it seems likely that it's because there are little to no uses for them that aren't evil. The punishment for using an Unforgivable Curse is a lifetime sentence in Azkaban, so only the worst curses, that are highly unlikely to ever have a non-Dark use, would be made Unforgivable.\n\n“Now … those three curses – Avada Kedavra, Imperius and Cruciatus – are known as the Unforgivable Curses. The use of any one of them on a fellow human being is enough to earn a life sentence in Azkaban.” - Harry Potter and the Goblet of Fire, Chapter 14 (The Unforgivable Curses)\n\nNow, would Sectumsempra fit the criteria for being made an Unforgivable Curse?\nProbably not - it cuts through things like a sword. It can be used for anything a sword, knife or other cutting tool can be used for. While using it on people might be considered Unforgivable, the spell itself is simply the act of cutting. There are many things a wizard might reasonably want to cut with no malicious intent; vegetables, rope, cloth, building materials. Because of this, it seems unlikely that even if the Ministry had known about it, it would be classified as an Unforgivable Curse.\nIn addition, there is a countercurse for Sectumsempra.\n\n“Pushing Harry roughly aside, he knelt over Malfoy, drew his wand and traced it over the deep wounds Harry’s curse had made, muttering an incantation that sounded almost like song. The flow of blood seemed to ease; Snape wiped the residue from Malfoy’s face and repeated his spell. Now the wounds seemed to be knitting. - Harry Potter and the Half-Blood Prince, Chapter 24 (Sectumsempra)\n\nWhile the wounds from Sectumsempra can't be healed by simple healing spells, they can in fact be healed by the countercurse.\nSo - Sectumsempra likely wouldn't be made Unforgivable if the Ministry knew it." } ]
[ { "from": "human", "value": "How can I add a delay to a program in C#?" }, { "from": "gpt", "value": "Use a timer with an interval set to 2–3 seconds.\nYou have three different options to choose from, depending on which type of application you're writing:\n\n* ```System.Timers.Timer```\n* ```System.Windows.Forms.Timer```\n* ```System.Threading.Timer```\n\nDon't use ```Thread.Sleep``` if your application need to process any inputs on that thread at the same time (WinForms, WPF), as ```Sleep``` will completely lock up the thread and prevent it from processing other messages. Assuming a single-threaded application (as most are), your entire application will stop responding, rather than just delaying an operation as you probably intended. Note that it may be fine to use Sleep in pure console application as there are no \"events\" to handle or on separate thread (also ```Task.Delay``` is better option).\nIn addition to timers and ```Sleep``` you can use ```Task.Delay``` which is asynchronous version of ```Sleep``` that does not block thread from processing events (if used properly - don't turn it into infinite sleep with ```.Wait()```). \n``` public async void ClickHandler(...)\n {\n // whatever you need to do before delay goes here\n await Task.Delay(2000);\n // whatever you need to do after delay.\n }\n```\nThe same ```await Task.Delay(2000)``` can be used in a ```Main``` method of a console application if you use C# 7.1 (Async main on MSDN blogs).\nNote: delaying operation with ```Sleep``` has benefit of avoiding race conditions that comes from potentially starting multiple operations with timers/```Delay```. Unfortunately freezing UI-based application is not acceptable so you need to think about what will happen if you start multiple delays (i.e. if it is triggered by a button click) - consider disabling such button, or canceling the timer/task or making sure delayed operation can be done multiple times safely." } ]
[ { "from": "human", "value": "I'm trying to write a Bash script that will overwrite an existing directory. I have a directory ```foo/``` and I am trying to overwrite ```bar/``` with it. But when I do this:\n```cp -Rf foo/ bar/\n```\na new ```bar/foo/``` directory is created. I don't want that. There are two files in ```foo/```; ```a``` and ```b```. There are files with same names in ```bar/``` as well. I want the ```foo/a``` and ```foo/b``` to replace ```bar/a``` and ```bar/b```." }, { "from": "gpt", "value": "If you want to ensure ```bar/``` ends up identical to ```foo/```, use ```rsync``` instead:\n```rsync -a --delete foo/ bar/\n```\nIf just a few things have changed, this will execute much faster than removing and re-copying the whole directory.\n\n* ```-a``` is 'archive mode', which copies faithfully files in ```foo/``` to ```bar/```\n* ```--delete``` removes extra files not in ```foo/``` from ```bar/``` as well, ensuring ```bar/``` ends up identical\n* If you want to see what it's doing, add ```-vh``` for verbose and human-readable\n* Note: the slash after ```foo``` is required, otherwise ```rsync``` will copy ```foo/``` to ```bar/foo/``` rather than overwriting ```bar/``` itself.\n\n* (Slashes after directories in rsync are confusing; if you're interested, here's the scoop. They tell rsync to refer to the contents of the directory, rather than the directory itself. So to overwrite from the contents of ```foo/``` onto the contents of ```bar/```, we use a slash on both. It's confusing because it won't work as expected with a slash on neither, though; rsync sneakily always interprets the destination path as though it has a slash, even though it honors an absence of a slash on the source path. So we need a slash on the source path to make it match the auto-added slash on the destination path, if we want to copy the contents of ```foo/``` into ```bar/```, rather than the directory ```foo/``` itself landing into ```bar/``` as ```bar/foo```.)\n\n```rsync``` is very powerful and useful, if you're curious look around for what else it can do (such as copying over ssh)." } ]
[ { "from": "human", "value": "Is there a particular reason the elves die off so fast? After the first war against Sauron, I recall the elves being decimated, to the point that they're almost useless army-wise in the trilogy. But I'm guessing men suffered equal or greater losses as well.\nAnyways, other races just seem much more capable of repopulating, while is seems like there are incredibly few (if any?) elven children. Considering the fact that elves are immortal, wouldn't their population be the fastest to grow? Also the seem to be perpetually 40 years old, so aren't they eternally fertile as well? Why don't they have more kids and build bigger societies?" }, { "from": "gpt", "value": "Tolkien himself addresses this in an essay called "Laws and Customs Among the Eldar". There are essentially two problems:\n\n* Elvish libido diminishes over time. Contrary to popular belief (and outward appearance, from a human perspective), Elves do age; and as they get older, they get less interested in procreation.\n* Having children is exhausting. The Elves believe that their child-bearing process draws a heavier physical and spiritual toll on them, compared to what it does to humans. They're understandable reluctant to have a lot of kids, because what's the point in having a dozen kids if doing so might literally kill you?\n\nFrom "Laws and Customs":\n\nIt might be thought that, since the Eldar do not (as Men deem) grow old in body, they may bring forth children at any time in the ages of their lives. But this is not so. For the Eldar do indeed grow older, even if slowly: the limit of their lives is the life of Arda, which though long beyond the reckoning of Men is not endless, and ages also. Moreover their body and spirit are not separated but coherent. As the weight of the years, with all their changes of desire and thought, gathers upon the spirit of the Eldar, so do the impulses and moods of their bodies change. [...]\nAlso the Eldar say that in the begetting [conceiving], and still more in the bearing of children, greater share and strength of their being, in mind and in body, goes forth than in the making of mortal children. For these reasons it came to pass that the Eldar brought forth few children; and also that their time of generation was in their youth or earlier life, unless strange and hard fates befell them.\nHistory of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar\n\nThat last point about the toll on their mind and body is worth expanding on, and fortunately Tolkien does this later in the essay:\n\n[A]ll the Eldar, being aware of it in themselves, spoke of the passing of much strength, both of mind and of body, into their children, in bearing and begetting. Therefore they hold that the fëa [soul], though unbegotten, draws nourishment directly from the fëa of the mother while she bears and nourishes the hrondo [body; later changed to the word hroä], and mediately but equally from the father, whose fëa is bound in union with the mother's and supports it.\nHistory of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar\n" } ]
[ { "from": "human", "value": "Reasons for being vegetarian or vegan other than ethical reasons?" }, { "from": "gpt", "value": "There are multiple reasons why people are/become Vegetarian/Vegan apart from ethics, including but not limited to\n\n* Religion/Culture - most of the worlds Vegetarians reside in India, mainly due to culture/personal beliefs but often interlinked with some of their major religions (Hinduism/Sikhism/Jainism etc) which promote the diet. Some strains of Buddhism also look positively at not eating meat, as does the Seventh-day Adventist Church.\n* Environment - reducing land degradation, climate change, reducing harm to bio-diversity etc. Animal agriculture causes a huge amount of problems to our planet and environment. \n* Health - another major point. Being Vegetarian or Vegan won't automatically improve your health of course (it's easy to live off junk food, believe me), but there are lots of scientifically proven benefits to eat a plant based diet over a standard Western diet including a lower risk of heart disease, lower BMI, lower cholesterol etc.\n* Political - a slightly less common reason but still; some people go Vegetarian or Vegan based on their political beliefs once they realise how much the two share intersectional values (e.g. from Anarchism to Veganarchism)\n" } ]
[ { "from": "human", "value": "My mom has a green card that expires 2028 but has been out of the US in the UK for over a year due to COVID travel restrictions. Can she enter now?" }, { "from": "gpt", "value": "Assuming she doesn't have a valid Re-entry Permit, she technically doesn't have one of the accepted documents for entry of a returning immigrant, as listed in 8 CFR 211.1(a). A green card is not one of the accepted documents after an absence of more than 1 year, and she doesn't have any of the other documents, like a Re-entry Permit or an immigrant visa.\n\nHowever, under 8 CFR 211.1(b)(3) and 8 CFR 211.4, the immigration officers at the port of entry have the authority to waive her failure to meet the documentary requirements, if they determine that she has not abandoned residence. They often will grant the waiver if it's the first time, the absence is not too much over a year, and/or there is a good reason for not returning earlier (e.g. COVID-19). So if she manages to make it to a US port of entry, there is a good chance they will just let her in, perhaps with a warning.\n\nThe officer could deny her entry, and pressure her to voluntarily sign I-407 to relinquish her permanent residency. This is voluntary, and she can refuse. If she refuses, they will give her a Notice to Appear for removal proceedings in immigration court at a later date. There, she will be able to present her case to the immigration judge, and if the immigration judge determines that she has not abandoned residence, the immigration judge can grant the waiver for her failure to meet the documentary requirements (think of it as a second opinion on the immigration officer's decision).\n\nThe other option to all this is that she can apply for an SB1 returning resident visa at a US consulate (which will meet the documentary requirements since it is an immigrant visa). However, this requires showing that she could not return any earlier due to circumstances beyond her control (which may be harder to prove than showing that she did not abandon residence). Also, there is no appeal for visa denials." } ]
[ { "from": "human", "value": "What is the LXX and why is it so noteworthy that there is a Greek translation of the OT? Wouldn't it be better to directly reference manuscripts in the original languages?" }, { "from": "gpt", "value": "Before 1947, a good case could be made that the Septuagint represented a more ancient tradition than the Masoretic versions of the Tanakh. Since the Septuagint was produced before 132 BCE (and probably in the 3rd century BCE) and the earliest known Masoretic manuscripts date to the 10th century CE, the Greek translation might have fossilized an early rendering of the Scriptures while the Hebrew continued to be copied and potentially altered. To further support the primacy of the Septuagint, the early Christian and Hellenistic Jewish texts, tended to use that translation rather go back to Hebrew sources.\nAn interesting counter-argument arises from the observation that during the 600 years from Jerome's translation into Latin (the Vulgate) to the earliest Masoretic manuscripts, the Hebrew seems to have been faithfully copied. That suggests that Jewish scribes were exceptionally careful to duplicate their scriptures.\nAfter 1947, the evidence changed. According to Wikipedia:\n\n [Most] of the Qumran fragments can be classified as being closer to the Masoretic text than to any other text group that has survived. According to Lawrence Schiffman, 60% can be classed as being of proto-Masoretic type, and a further 20% Qumran style with bases in proto-Masoretic texts, compared to 5% proto-Samaritan type, 5% Septuagintal type, and 10% non-aligned. Joseph Fitzmyer noted the following regarding the findings at Qumran Cave 4 in particular: \"Such ancient recensional forms of Old Testament books bear witness to an unsuspected textual diversity that once existed; these texts merit far greater study and attention than they have been accorded till now. Thus, the differences in the Septuagint are no longer considered the result of a poor or tendentious attempt to translate the Hebrew into the Greek; rather they testify to a different pre-Christian form of the Hebrew text\".\n\nAnother another article describes the meaning of the categories in detail.\nA few caveats are in order:\n\n* Surveying the Qumran about religious texts seems something akin to surveying a hippie commune about political issues—you're likely to experience some bias. If we could obtain a similar collection from Jerusalem, we'd likely find more agreement and likely the side of MT. Given the diversity in non-Scriptural texts, 60% seems quite solid support.\n* While it's unlikely, there exists a chronological possibility the scrolls associated with the Septuagint-aligned Hebrew were influenced by the Greek. (Any references one way or the other would be appreciated.) \n\nWhat remains therefore is a window into the community of Alexandrian Jews that produced the translation. For those who are interested in the development of Jewish belief, that can be extremely useful. N. T. Wright's book, The Resurrection of the Son of God, shows that the LXX translators chose to interpret key texts from Daniel and Ezekiel about the resurrection as literal rather than metaphorical. He argues from this that belief in bodily resurrection was more common in Jesus' day than other scholars assert." } ]
[ { "from": "human", "value": "I have to disable inputs at first and then on click of a link to enable them.\nThis is what I have tried so far, but it doesn't work.\nHTML:\n```\n```\njQuery:\n```$(\"#edit\").click(function(event){\n event.preventDefault();\n $('.inputDisabled').removeAttr(\"disabled\")\n});\n```\n\nThis shows me ```true``` and then ```false``` but nothing changes for the inputs:\n```$(\"#edit\").click(function(event){\n alert('');\n event.preventDefault();\n alert($('.inputDisabled').attr('disabled'));\n $('.inputDisabled').removeAttr(\"disabled\");\n alert($('.inputDisabled').attr('disabled'));\n});\n```" }, { "from": "gpt", "value": "Always use the ```prop()``` method to enable or disable elements when using jQuery (see below for why).\nIn your case, it would be:\n```$("#edit").click(function(event){\n event.preventDefault();\n $('.inputDisabled').prop("disabled", false); // Element(s) are now enabled.\n});\n```\njsFiddle example here.\n\n\nWhy use ```prop()``` when you could use ```attr()```/```removeAttr()``` to do this?\n\nBasically, ```prop()``` should be used when getting or setting properties (such as ```autoplay```, ```checked```, ```disabled``` and ```required``` amongst others).\nWhile what you want to do can technically be done using ```attr()```/```removeAttr()```, it doesn't mean it should be done - and can cause strange/problematic behaviour, as in this case.\n\n"The difference between attributes and properties can be important in\nspecific situations. Before jQuery 1.6, the ```.attr()``` method sometimes\ntook property values into account when retrieving some attributes,\nwhich could cause inconsistent behavior. As of jQuery 1.6, the ```.prop()```\nmethod provides a way to explicitly retrieve property values, while\n```.attr()``` retrieves attributes."\n"Properties generally affect the dynamic state of a DOM element without\nchanging the serialized HTML attribute. Examples include the ```value```\nproperty of input elements, the ```disabled``` property of inputs and\nbuttons, or the ```checked``` property of a checkbox. The ```.prop()``` method\nshould be used to set ```disabled``` and ```checked``` instead of the ```.attr()```\nmethod. The ```.val()``` method should be used for getting and setting\n```value```." - jQuery documentation for prop()\n\nPre-jQuery 3.0 (before 2016)\nThe reason why you should use ```prop``` over ```removeAttr()``` is that ```removeAttr()``` completely removes the ```disabled``` attribute itself - as this method would simply set the corresponding property name to ```false```:\n\nPrior to jQuery 3.0, using .removeAttr() on a boolean attribute such\nas checked, selected, or readonly would also set the corresponding\nnamed property to false. This behavior was required for ancient\nversions of Internet Explorer but is not correct for modern browsers\nbecause the attribute represents the initial value and the property\nrepresents the current (dynamic) value. - jQuery 3.0 Breaking Changes\n\nWhile ```prop()``` merely sets the property's underlying boolean value to false." } ]
[ { "from": "human", "value": "I'm no expert in darkroom photography, but it seems a little odd that there is a type of light that doesn't affect film or developing paper etc. So why is a dark-room safelight safe?" }, { "from": "gpt", "value": "Photo films and papers are made from salts of silver that naturally only darken when exposed to violet or blue light. In the early days of photography, this was all that was available. Therefore these films and papers are able to be handled under any light source that does not radiate blue light. By the way, the violet and blue frequencies of light are the shortest, and are the most energetic when it comes to inducing a chemical change. These early films and papers could all be be handled safely under red light as well as yellow light. These lamps do not emit violet or blue. \n\nThese blue-sensitive-only films did an OK job, with some exceptions. Women’s faces with cosmetics, like lipstick and rouge on the cheeks, came out weird. Warm tones reproduced super dark, and most times lips and cheeks turned black, void of detail on the finished picture. The bottom line is, many colors in nature reproduced incorrectly with this early blue-sensitive-only film. \n\nThe cure was accidental. Professor Hermann Vogel at Berlin Technical was trying to solve the problem of halation. This results when taking a picture of bright objects, like light sources or gemstones and the like. These objects play on the film with lots of light energy. This energy often goes completely through the film and hits something behind the film. The light is then reflected back into the film. The result is a halo around bright objects. The professor had one of his students dye the silver salts yellow, thinking the yellow dye would filter out the annoying reflected blue from the rear. He tried this dyed film and it did the trick, plus the film gained sensitivity to green light. He named this blue/green sensitive film orthochromatic (Latin for correct color). The year was 1857, and the quality of film reproducing the colors of nature moved forward by a big leap. \n\nA few years later, one of his graduate students, experimenting with different dyes, discovered how to make films sensitive to blue, green and red light. This film was called panchromatic (the pan prefix in Greek means \"all\"). Thus panchromatic film reproduces all colors found in nature with high accuracy. The bad news was, the darkroom folks were forced to give up the red and yellow safelight. A super dim green safelight could be used for a short period of time during developing. \n\nPhoto papers remained insensitive to red for the most part - no need, as they work OK with just blue and green sensitivity. Modern variable contrast photo papers have two sensitive coats, one for blue light and one for green light. We can use a safelight on these papers; it is amber with reduced brilliance. \n\nFilms and papers that make color pictures are panchromatic, and most safelights are not safe. We can use infrared lamps with a specialized night vision infrared scope to view and handle most panchromatic films and papers, because these materials have low sensitivity to infrared." } ]
[ { "from": "human", "value": "With the command:\n```ls -la *\n```\nI can list all my symbolic links. \nHow can I remove all symbolic links which are linked to a special folder?\nFor example:\nIn my directory ```usr/local/bin``` I have the following entries:\n```lrwxrwxrwx 1 root root 50 Apr 22 14:52 allneeded -> /usr/local/texlive/2011/bin/x86_64-linux/allneeded\nlrwxrwxrwx 1 root root 47 Apr 22 14:52 amstex -> /usr/local/texlive/2011/bin/x86_64-linux/amstex\nlrwxrwxrwx 1 root root 24 Apr 23 19:09 arara -> /home/marco/.arara/arara\n```\nNow I want to remove all links with the path ```/usr/local/texlive/```" }, { "from": "gpt", "value": "Please make sure to read the alternative answer. It's even more to the point although not voted as high at this point.\nYou can use this to delete all symbolic links:\n```find -type l -delete\n```\nwith modern ```find``` versions.\nOn older find versions it may have to be:\n```find -type l -exec rm {} \\;\n# or\nfind -type l -exec unlink {} \\;\n```\nTo limit to a certain link target, assuming none of the paths contain any newline character:\n``` find -type l | while IFS= read -r lnkname; do if [ \"$(readlink '$lnkname')\" == \"/your/exact/path\" ]; then rm -- \"$lnkname\"; fi; done\n```\nor nicely formatted\n``` find -type l |\n while IFS= read -r lnkname;\n do\n if [ \"$(readlink '$lnkname')\" = \"/your/exact/path\" ];\n then\n rm -- \"$lnkname\"\n fi\n done\n```\nThe ```if``` could of course also include a more complex condition such as matching a pattern with ```grep```.\n\nTailored to your case:\n```find -type l | while IFS= read -r lnk; do if (readlink \"$lnk\" | grep -q '^/usr/local/texlive/'); then rm \"$lnk\"; fi; done\n```\nor nicely formatted:\n```find -type l | while IFS= read -r lnk\ndo\n if readlink \"$lnk\" | grep -q '^/usr/local/texlive/'\n then\n rm \"$lnk\"\n fi\ndone\n```" } ]
[ { "from": "human", "value": "Did Aztecs know how many continents there are on earth?" }, { "from": "gpt", "value": "Do you know how many continents there are on Earth? Is Europe a separate continent from Asia? Is Australia the biggest island or the smallest continent? Is Antarctica an ice-locked archipelago or a continent? Are the Americas one continent or two? (All of those questions can be answered reasonably either way.)\n\nThe separation of Europe from Asia into two continents happened because, from the point of view of the Greek Mediterranean world, all of Asia that mattered was across the sea from all of Europe that mattered. They knew that Europe and Asia were connected north of the Black Sea (though they didn't know how big a connection) but they didn't care, because for their purposes, they were separate continents.\n\nThe idea of a continent is more a cultural thing than anything else.\nFrom a proper scientific point of view continents are probably better defined by tectonic plates so now you're dealing with twenty or so. Maybe a continent is a tectonic plate with dry land attached? That still leaves quite a few. (And how much dry land is needed? And is Los Angeles on a separate continent from New York?)\n\nIf the Aztecs knew the geography of the whole Earth it would still be very surprising if they had counted continents the same way the Ancient Greeks have led us to do. And there's no evidence they knew the geography of the whole Earth and considerable evidence that they didn't." } ]
[ { "from": "human", "value": "What did the Soviet Union and Russia bring to the ISS?" }, { "from": "gpt", "value": "Initially, everything. The ISS started out as Mir-2 with some extra modules added soon afterwards. Then lots more over the next 10 years.\nThe initial modules, Zarya and Zvezda, which housed living quarters, reboost, attitude control, solar power, life support, and docking modules.\nEach additional component and module made the system better, but the ISS is still dependent on the Russian operating segment.\nEach function that the Russian segment supplied initially was enhanced or replaced by the US side (solar power, life support, etc.). The major component this is mostly still Russian is half the crew quarters and reboost/attitude control (beyond what the control gyros can handle).\nInitially the Shuttle and Soyuz provided crew services, and now only Soyuz (till SpaceX/ULA get their acts together in 2019) provides crew. Initially the Russians provided cargo (as did the Shuttle till retirement), but specifically Progress could refuel the engines on the ISS for reboost.\nThe Russian theoretical plan is that the next two modules they launch (if ever, now, after being so delayed) Nauka and the UM will be able to separate from the ISS and form the core of their next space station. One of those theories was to take Zarya and Zvezda (or just one) with them as well." } ]
[ { "from": "human", "value": "What utility can move my Windows boot partition over to another hard drive?\nMy preference is that it would be really easy. \n\n* Boot into Windows\n* Pick drive to move\n* Pick target drive\n* It copies everything over, and reboots to the correct partition." }, { "from": "gpt", "value": "## DriveImage XML\nDriveImage XML will do the job. It runs from within Windows and it can copy directly from drive to drive. A lot of people rave about it after good experiences with the software.\n\nDriveImage XML is an easy to use and reliable program for imaging and backing up partitions and logical drives.\nImage creation uses Microsoft's Volume Shadow Services (VSS), allowing you to create safe "hot images" even from drives currently in use. Images are stored in XML files, allowing you to process them with 3rd party tools. Never again be stuck with a useless backup! Restore images to drives without having to reboot. DriveImage XML is now faster than ever, offering two different compression levels.\n\n\n## EASEUS Disk Copy\nEASEUS Disk Copy is a great alternative if you don't want to go for a 'hot' backup that runs from within Windows. Good review at lifehacker and on a par with DriveImage XML. They quite clearly state that it is ideal for moving from one disk to a larger one. Like other suggestions, this requires that you create a boot CD.\n\n> EASEUS Disk Copy is a potent freeware providing sector-by-sector disk/partition clone regardless of your operating system, file systems and partition scheme by creating a bootable CD. The sector-by-sector method assures you a copy 100% identical to the original. Disk Copy can be used for copy, cloning, or upgrading your original small hard drive to a new larger drive. Simply speaking, it can copy anything from the old hard drive including the deleted, lost files and inaccessible data. So, the freeware is a perfect tool for Data Recovery Wizard to recover files from a backup disk." } ]
[ { "from": "human", "value": "What's the difference between ASCII and Unicode?" }, { "from": "gpt", "value": "ASCII has 128 code points, 0 through 127. It can fit in a single 8-bit byte, the values 128 through 255 tended to be used for other characters. With incompatible choices, causing the code page disaster. Text encoded in one code page cannot be read correctly by a program that assumes or guessed at another code page.\n\nUnicode came about to solve this disaster. Version 1 started out with 65536 code points, commonly encoded in 16 bits. Later extended in version 2 to 1.1 million code points. The current version is 6.3, using 110,187 of the available 1.1 million code points. That doesn't fit in 16 bits anymore.\nEncoding in 16-bits was common when v2 came around, used by Microsoft and Apple operating systems for example. And language runtimes like Java. The v2 spec came up with a way to map those 1.1 million code points into 16-bits. An encoding called UTF-16, a variable length encoding where one code point can take either 2 or 4 bytes. The original v1 code points take 2 bytes, added ones take 4. \n\nAnother variable length encoding that's very common, used in *nix operating systems and tools is UTF-8, a code point can take between 1 and 4 bytes, the original ASCII codes take 1 byte the rest take more. The only non-variable length encoding is UTF-32, takes 4 bytes for a code point. Not often used since it is pretty wasteful. There are other ones, like UTF-1 and UTF-7, widely ignored.\nAn issue with the UTF-16/32 encodings is that the order of the bytes will depend on the endian-ness of the machine that created the text stream. So add to the mix UTF-16BE, UTF-16LE, UTF-32BE and UTF-32LE.\n\nHaving these different encoding choices brings back the code page disaster to some degree, along with heated debates among programmers which UTF choice is \"best\". Their association with operating system defaults pretty much draws the lines. One counter-measure is the definition of a BOM, the Byte Order Mark, a special codepoint (U+FEFF, zero width space) at the beginning of a text stream that indicates how the rest of the stream is encoded. It indicates both the UTF encoding and the endianess and is neutral to a text rendering engine. Unfortunately it is optional and many programmers claim their right to omit it so accidents are still pretty common." } ]
[ { "from": "human", "value": "Reasons why healthy people would intentionally want to get infected?" }, { "from": "gpt", "value": "Because some self-proclaimed health guru claims that it's good for you to have that disease.\n\nThe miracle-virus causes your body to absorb free cosmic energies. Your constantly raising body temperature is proof that it works.\nThe headache you feel is because your brain is reconfiguring itself to become more effective. When the process is over, you will be far more intelligent. Some of our patients even gained psychic powers.\nThe vomiting, blood-coughing, explosive diarrhea and the open sores you have all over your body are actually all the poisons your body accumulated over your life which are now leaving your body.\nThe weakness you feel and the periodical blackouts are also part of the cleansing process. Your body is concentrating all its energy on cleaning you. That's in fact a good sign and shows that it works. Some of us were even able to communicate with alien angel-spirits during these intensive cleaning phases.\n\nAll of that is of course bullshit. The infected are simply sick. The guru just claims all those pseudo-scientific benefits exist to get people to pay them ridiculous amounts of money for infecting them with the disease.\n\nSounds ridiculous? Then you might want to take a look at the community of people drinking bleach." } ]
[ { "from": "human", "value": "In The Avengers, the Council contacted Nick Fury and supposedly, they want to nuke Manhattan. Nick didn't agree so they contacted a S.H.I.E.L.D. operative to nuke Manhattan.\nWhen they found out that an unauthorized jet was trying to fly, Nick grabbed a rocket launcher and fired it at the jet, which was a decoy and the real jet was able to escape. \nHowever, why would he do that? If that was the real plane carrying a nuke enough to level Manhattan, wouldn't the nuke explode and destroy the base along with them if he fired a rocket launcher at it?" }, { "from": "gpt", "value": "\nIf that was the real plane carrying a nuke enough to level Manhattan, wouldn't the nuke explode and destroy the base along with them if he fired a rocket launcher at it?\n\nNo.\nDetonating a modern nuclear device is, in fact, incredibly difficult and merely shooting down the aircraft carrying it would not be sufficient.\nIn fact, several aircraft carrying older nuclear devices have either crashed or otherwise been lost without the device on board detonating.\nIt's likely that the crash might cause a release of nuclear material but detonation is practically impossible.\nIn 1966...\n\n...another B-52 carrying four hydrogen bombs crashed near the Spanish town of Palomares on Spain’s southeast coast after colliding with a refueling tanker. One of the four bombs was recovered virtually intact, according to The Washington Post, but two others released plutonium when their explosive triggers detonated. A fourth bomb fell into the sea, prompting a search that involved thousands of uniformed personnel, millions of dollars and 20 ships that ranged from submarines to minesweepers.\nThe fourth bomb was eventually recovered, but radiation released by the damaged weapons required a U.S.-led effort to decontaminate 640 acres of topsoil in the farmland around Palomares, Tad Sczulc reported in the Times. Military personnel initially wore face masks and gloves as they removed the soil, according to Sczulc’s account, and more than 1,600 tons of contaminated soil were sealed in steel drums and shipped to the U.S. for disposal.\nWashington Post\n\n1964\n\nIn 1964, a B-52 carrying two unarmed atomic bombs crashed in western Maryland. In 1961, two nuclear-laden B-52s went down — one near Yuba City, Calif., and another north of Goldsboro, N.C. The bombs survived both crashes without detonating\n" } ]
[ { "from": "human", "value": "Since I created my repository it appears that the tags I have been\ncreating are not pushed to the repository. When I do ```git tag``` on the\nlocal directory all the tags are present, but when I logon to the\nremote repository and do a ```git tag```, only the first few show up.\nWhat could the problem be?." }, { "from": "gpt", "value": "In default git remote configuration you have to push tags explicitly (while they are fetched automatically together with commits they point to). You need to use\n\n```\n$ git push <remote> tag <tagname>\n```\nto push a single tag,\n```\n$ git push <remote> --tags\n```\nto push all tags (or ```git push --tags``` to push to default remote, usually ```origin```).\n\nThis is very much intended behavior, to make pushing tags explicit. Pushing tags should be usually conscious choice." } ]
[ { "from": "human", "value": "How do I add Git submodule to a sub-directory?" }, { "from": "gpt", "value": "You go into ~/.janus and run:\n\n```git submodule add <git@github ...> snipmate-snippets/snippets/```\n\nIf you need more information about submodules (or git in general) ProGit is pretty useful." } ]
[ { "from": "human", "value": "Given that Kohn-Sham DFT is strictly a ground-state method (at 0 K), how is it sufficient to describe materials in real-life applications?" }, { "from": "gpt", "value": "These are a few extra points to complement Andrew Rosen's comprehensive response:\n\n* To be absolutely clear, typical DFT calculations are not performed at 0K, a better description of what happens is that they are performed \"for a static crystal\". Static crystal means that the atoms are fixed at their crystallographic positions (which is what a typical DFT calculation does), but this situation is different from 0K. Even at 0K, the atomic nuclei move due to quantum zero-point motion (also called quantum fluctuations). This quantum zero-point motion is very small for compounds containing heavy elements, which means that in these cases \"0K\" and \"static crystal\" are almost the same and many people use the terms interchangeably. However, quantum zero-point motion can be very large for light elements, for example in solid hydrogen (the lightest of all compounds) it dominates even at room temperature. To perform a calculation at 0K (as opposed to a static crystal calculation), the strategy that Andrew Rosen proposed would still work if you use quantum statistics. For example, solving the vibrational problem within the harmonic approximation at the quantum mechanical level with give you the zero-point energy as the ground state of a quantum harmonic oscillator. A good reference for hydrogen is this review article.\n* Although Andrew Rosen is correct in that the potential energy surface is largely temperature independent, there are a few situations in which the potential energy surface does vary significantly with temperature. An example of this is provided by many perovskite crystals (e.g. $\\ce{BaTiO_3}$), which undergo a series of temperature-induced structural phase transitions. For example, at very high temperatures the structure is cubic, and this structure sits at a minimum of the potential free energy surface. However, if you calculated the potential energy surface (instead of the free energy surface), then it has a double-well shape and the cubic structure is at the saddle point, so the structure will lower its energy by distorting and going to one of the minima. This is precisely what happens at low temperatures because the corresponding free energy surface acquires a double-well shape, and the system undergoes a structural phase transition. A good early DFT reference for this is this paper.\n* As already pointed out by others, the differences between DFT and TDDFT or $GW$-BSE are not related to the inclusion or exclusion of temperature. In this language, both TDDFT and $GW$-BSE have no temperature for the behaviour of the nuclei, and you could incoporate it in a similar fashion to what Andrew Rosen described for DFT.\n" } ]
[ { "from": "human", "value": "I don't really get the difference between gain and volume boost.\n\nSo if I understand correctly, gain directly boosts a signal from a line or input while volume handles the output. Volume isn't really for boosting either.\nWould this mean, in most settings, getting 'close to' as much gain as possible without any hiss/background noise is ideal?" }, { "from": "gpt", "value": "Here's a brief overview to get you started. Hopefully this helps!\n\n* 'Gain' controls are typically used to get a good input level. So for example if you had a microphone with a very low output signal, you would boost the gain to get a better level into your mixing desk or audio interface. If you had a synthesizer plugged in you might need to turn the gain down to stop the signal distorting. Gain controls are often controlling an amplifier behind the scenes - i.e. your signal can 'gain' strength after going through the gain stage of your audio equipment. So gain is usually the first control in the signal path of your recording equipment. \n\n* 'Volume' controls on the other hand tend to be at the end of the signal chain and are more likely to be attenuating rather than amplifying the signal. So on a mixing desk, having got a good level from each input at the gain stage, you use the volume faders to adjust the relative volumes of each channel to achieve a good mix. You are not typically amplifying those signals any more though.\n\nA guitar amp is a good example of how this works. The first control is often called \"Gain\" or 'drive' and guitarists often deliberately turn this really high to get a nice distorted sound from a tube preamp. However, the final control is called Volume and governs simply how loud the sound coming out of your speaker is. With gain right up and volume low you can play distorted sounds without annoying the neighbours. With gain low and volume high you get a loud sound but no distortion." } ]
[ { "from": "human", "value": "I recently had someone claim (on an unrelated SE site I won't link to) that it is the responsibility of a player to correctly identify their hand, that what you &quot;call&quot; your hand determines the winner:\n\nFor example, you have an Ace, King, Queen, Jack, and Ten. You call your hand and say, &quot;I have a Straight!&quot;\nBut that was a bad move on your part because you are a novice player and you did not notice that all of your cards are Spades. You actually had a Straight Flush, but now you have lost because one of the remaining players had a Full House.\nYour hand has not been determined until you call your hand.\n\nIs this true? Clearly you might play your hand differently if you misunderstand what you have, but I always thought that the cards speak for themselves once they are revealed.\nOr would it depend on the specific poker variation/house rules?" }, { "from": "gpt", "value": "Casinos in the US generally have the \"cards speak\" rule. That is, when a hand is properly tabled--exposed to everyone at showdown--it is the responsibility of all players, the dealer, floormen, and anyone else present to see that the pot is awarded to the best hand shown, regardless of what the players might say.\n\nSome players object to this rule: they believe that if a player or railbird says \"Wait, Bob has a flush\", that's unfairly helping a player. But the rule is clear: once the hand is tabled, others have not only the right but the obligation to help ensure the pot is awarded correctly.\n\nThere are a couple of caveats: if a player only shows his hand to another player, or to the dealer, or to any other person, without properly tabling it for everyone, that player has no rights yet and those to whom the hand was shown should remain silent to protect other players' properly shown hands. But once the hand is tabled, it's fair game and everyone can and should assist in reading the hands.\n\nFinally, in some cases, if a floorman feels that a player has deliberately overcalled his hand to induce a player with a better hand to fold, he may penalize that player by awarding the pot to someone else, even possibly to a folded hand. Some California lowball clubs even had a rule that a player who remained silent rather than explicitly calling out a pair could be ruled against in this way." } ]
[ { "from": "human", "value": "How to get the first item from an associative PHP array?" }, { "from": "gpt", "value": "PHP \nIf you don't know enough about the array (you're not sure whether the first key is foo or bar) then the array might well also be, maybe, empty.\nSo it would be best to check, especially if there is the chance that the returned value might be the boolean FALSE:\n```$value = empty($arr) ? $default : reset($arr);\n```\nThe above code uses ```reset``` and so has side effects (it resets the internal pointer of the array), so you might prefer using ```array_slice``` to quickly access a copy of the first element of the array:\n```$value = $default;\nforeach(array_slice($arr, 0, 1) as $value);\n```\n\nAssuming you want to get both the key and the value separately, you need to add the fourth parameter to ```array_slice```:\n```foreach(array_slice($arr, 0, 1, true) as $key => $value);\n```\nTo get the first item as a pair (```key => value```):\n```$item = array_slice($arr, 0, 1, true);\n```\nSimple modification to get the last item, key and value separately:\n```foreach(array_slice($arr, -1, 1, true) as $key => $value);\n```\nperformance\nIf the array is not really big, you don't actually need ```array_slice``` and can rather get a copy of the whole keys array, then get the first item:\n```$key = count($arr) ? array_keys($arr)[0] : null;\n```\nIf you have a very big array, though, the call to ```array_keys``` will require significant time and memory more than ```array_slice``` (both functions walk the array, but the latter terminates as soon as it has gathered the required number of items - which is one).\nA notable exception is when you have the first key which points to a very large and convoluted object. In that case ```array_slice``` will duplicate that first large object, while ```array_keys``` will only grab the keys.\nPHP 7.3+\nPHP 7.3 onwards implements ```array_key_first()``` as well as ```array_key_last()```. These are explicitly provided to access first and last keys efficiently without resetting the array's internal state as a side effect.\nSo since PHP 7.3 the first value of ```$array``` may be accessed with\n```$array[array_key_first($array)];\n```\nYou still had better check that the array is not empty though, or you will get an error:\n```$firstKey = array_key_first($array);\nif (null === $firstKey) {\n $value = &quot;Array is empty&quot;; // An error should be handled here\n} else {\n $value = $array[$firstKey];\n}\n```" } ]
[ { "from": "human", "value": "Why do people write #!/usr/bin/env python on the first line of a Python script?" }, { "from": "gpt", "value": "In order to run the python script, we need to tell the shell three things:\n\n* That the file is a script\n* Which interpreter we want to execute the script\n* The path of said interpreter\n\nThe shebang ```#!``` accomplishes (1.). The shebang begins with a ```#``` because the ```#``` character is a comment marker in many scripting languages. The contents of the shebang line are therefore automatically ignored by the interpreter.\nThe ```env``` command accomplishes (2.) and (3.). To quote &quot;grawity,&quot;\n\n> A common use of the ```env``` command is to launch interpreters, by making use of the fact that env will search $PATH for the command it is told to launch. Since the shebang line requires an absolute path to be specified, and since the location of various interpreters (perl, bash, python) may vary a lot, it is common to use: ```#!/usr/bin/env perl``` instead of trying to guess whether it is /bin/perl, /usr/bin/perl, /usr/local/bin/perl, /usr/local/pkg/perl, /fileserver/usr/bin/perl, or /home/MrDaniel/usr/bin/perl on the user's system... \n\n> On the other hand, env is almost always in /usr/bin/env. (Except in cases when it isn't; some systems might use /bin/env, but that's a fairly rare occassion and only happens on non-Linux systems.)" } ]
[ { "from": "human", "value": "Nowadays each graphic card has some driver in operating system that translates some (typically) standard API such as OpenGL, so that programmers use some standardized API code to tell graphics cards how and what they want to render. (Actually that's already a bit hard-core most programmers really use various game engines that do this for them). In times of old computers - how was this done? Did every programmer of every game implemented all possible various API's that old graphic cards supported? Or did the old game studios from MS-DOS times had their own \"game engines\" that provided some abstraction when it came to these graphic cards? I remember there were many various card vendors and I remember old games asked me which one I have - so I suppose these games contained code / drivers for all these cards?" }, { "from": "gpt", "value": "> Did every programmer of every game implemented all possible various API's that old graphic cards supported?\n\nYes - but it went even deeper than that. Early graphics cards had virtually no callable code associated with them at all, the concept of \"drivers\" had not quite become a reality yet. There was the concept of a Video BIOS, which were extensions to the ```INT 10h``` BIOS video services, that were effectively limited to initialization and switching video modes. \nInstead, graphics cards, at least in DOS land, all had memory mapped display RAM, and extensive documentation was available about exactly how setting various bits in display RAM would affect the pixels that appeared on the screen. There were no drawing APIs to call, if you wanted something to appear on the screen (whether it be a pixel, a character, a line, a circle, a sprite, etc) you would write the code to move the bytes into the right places in display RAM. Entire books were written about how to write efficient code to draw graphics.\nThere were some systems like the Borland Graphics Interface that abstracted graphics drawing primitives into an API with different drivers that one could call to draw things on different graphics cards. However, these were typically slower than what would be required for building action type games.\nAn action game would typically be optimized for a particular graphics display mode on a particular card. For example, a popular display mode was VGA 640x480 with 16 colors. This would be listed in the software requirements, and you needed to have the right hardware to support the game. If you bought a VGA game but you only had an EGA card, then the game would not work at all. As you said, some games would ask what you had and you had to know what the right answer was, otherwise the game would not work." } ]
[ { "from": "human", "value": "Why is it \"behead\" and not \"dehead\"?" }, { "from": "gpt", "value": "We didn’t use de-head because we already had a verb behead by the time we started using de- to create verbs: behead was a verb in Old English, behéafdian. \n\nSo behead was already used long before the de- privative prefix came to be used productively in English. That didn’t happen until Modern English with a few productive examples in the 17ᵗʰ century but most coming from the 19ᵗʰ century or after. As Janus mentions in comments, the de- word meaning the same thing, decapitate, was imported in full with the de- already there, from Latin via French, in the 17ᵗʰ century.\n\nThere are many different possible senses of be- in verbs; the OED lists six different primary senses with subsenses. This here in behead is one of the rarer ones. Under be- sense 6c, it says that this privative sense of be- used to create behead is an ancient sense that means bereave of:\n\n \nForming trans. verbs on substantives used in an instrumental relation; the primary idea being; \n* a. To surround, cover, or bedaub with, as in becloud, to put clouds about, cover with clouds, bedew. Thence, by extension,\n* b. To affect with in any way, as in benight, beguile, befriend. In both sets there is often an accompanying notion of ‘thoroughly, excessively,’ as in 2.\n* c. An ancient application, no longer in living use, was to express the sense of ‘bereave of,’ as in behead, belimb, etc., q.v. Cf. 3, above.\n\nAlthough 6a and 6b are still productive, 6c no longer is so in the living language. Another Old English verb formed using 6c was belandian, meaning to deprive of one’s land. However, this verb did not survive into Modern English.\n\nEl destierro\nApropos de nada, the Spanish equivalent of the obsolete verb beland still very much exists in the verb desterrar, which combines the privative des‑ prefix with the noun tierra meaning land then puts that into an infinitive verb form. This is normally translated as “exile” in English, but sometime as “expel” or as a noun “expulsion”. There is also a substantive version, destierro, is famously found in “Cantar del destierro”, which is the title of the first canto from that most ancient of Castilian epic poems, El Cantar de Mio Cid. \n\nTruly, el Cid was belanded of his lands by the King." } ]
[ { "from": "human", "value": "Why do many vinyl albums of classical music have Sides 1 / 4 on the first record and 2 / 3 on the second? An example of this is the RCA Red Seal recording of Beethoven's 9th Symphony by the Boston Symphony Orchestra." }, { "from": "gpt", "value": "Many phonographs were able to play multiple records in sequence with a mechanism that would hold one or more records on the turntable, and one or more additional records elevated on the center post.\nAt the end of one record, the mechanism sensed the tone arm reaching close to the center of the record, and then lifted it, pulled it out beyond the edge of the records. The system then dropped the bottom record of those on the center post, leaving the rest of them. Then the tone arm mechanism moved the tone arm to the outside of the record and lowered it to the record.\nThe mechanism was pretty ingenious, but it couldn't flip records over. So, to play a long piece, it would play one side of each record until the stack was exhausted. Then it was up to a person to flip the stack to play the opposite sides in sequence.\nSo, when playing records 1A/1B, 2A/2B, 3A/3B, 4A/4B in such a mechanism, the play order would be 1A, 2A, 3A, 4A, (flip), 4B, 3B, 2B, 1B. The \"B\" sides would go the other way because flipping the whole stack would put them in the opposite order.\nPurists would take offense at the idea of letting records drop like that, but it was an irresistible convenience to people who could tolerance slightly quicker wear of their records." } ]
[ { "from": "human", "value": "Why isn't the market dropping like a stone with all the bad news?" }, { "from": "gpt", "value": "Market reactions to information are not always timely, proportional, or rational. \nWe don't know the full impact of our current situation; we're feeling it out.\n\n* Some people (bulls), believe that the initial dip was an over-reaction, that the government response will prevent further decline, and/or that things will go back to normal pretty quickly, so they are buying the dip.\n* On the other side you have people (bears) that believe the initial reaction was just a start but not enough to price-in the full impact, that the government can't prop up the economy, and/or that this will drag on for a long while, so they are betting on further decline. \n\nThe problem with this idea of information being priced-in is that we all know there's a global pandemic, but there are very different opinions about how much that should affect the market.\nConsider unemployment levels: We have projections about unemployment rate potentially hitting a peak over 30%. Meanwhile, the current unemployment rate is 4.4% and projected to hit double digits in April. The only way all of that information could be appropriately priced in is if everyone agreed about the reasonableness of the projections and had the economic prowess to understand the actual impact of those figures.\nInstead, what happens is that some people will see the actual April unemployment numbers as surprising new information to react to, while others will see it as old information in line with their expectations. Add in thousands of other pieces of information about which people have conflicting opinions, and it becomes pretty much impossible to know in advance if that information was all priced in appropriately.\nThe most recent comparable event is the subprime mortgage crash. Many people thought bottom was hit around November 2008 and there was a brief counter-trend rally before actual bottom was hit around March 2009. We don't know at this time if the market has bottomed out yet or not; nor do we know how long recovery could take." } ]
[ { "from": "human", "value": "What are Null Pointer Exceptions (```java.lang.NullPointerException```) and what causes them?\n\nWhat methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?" }, { "from": "gpt", "value": "There are two overarching types of variables in Java:\n\n1. Primitives: variables that contain data. If you want to manipulate the data in a primitive variable you can manipulate that variable directly. By convention primitive types start with a lowercase letter. For example variables of type `int` or `char` are primitives.\n\n2. References: variables that contain the memory address of an `Object` i.e. variables that refer to an `Object`. If you want to manipulate the `Object` that a reference variable refers to you must dereference it. Dereferencing usually entails using `.` to access a method or field, or using `[` to index an array. By convention reference types are usually denoted with a type that starts in uppercase. For example variables of type `Object` are references.\n\nConsider the following code where you declare a variable of primitive type `int` and don't initialize it:\n```\nint x;\nint y = x + x;\n```\nThese two lines will crash the program because no value is specified for `x` and we are trying to use `x`'s value to specify `y`. All primitives have to be initialized to a usable value before they are manipulated.\n\nNow here is where things get interesting. Reference variables can be set to `null` which means \"I am referencing nothing\". You can get a `null` value in a reference variable if you explicitly set it that way, or a reference variable is uninitialized and the compiler does not catch it (Java will automatically set the variable to `null`).\n\nIf a reference variable is set to null either explicitly by you or through Java automatically, and you attempt to dereference it you get a `NullPointerException`.\n\nThe `NullPointerException` (NPE) typically occurs when you declare a variable but did not create an object and assign it to the variable before trying to use the contents of the variable. So you have a reference to something that does not actually exist.\n\nTake the following code:\n```\nInteger num;\nnum = new Integer(10);\n```\nThe first line declares a variable named `num`, but it does not actually contain a reference value yet. Since you have not yet said what to point to, Java sets it to `null`.\n\nIn the second line, the `new` keyword is used to instantiate (or create) an object of type `Integer`, and the `reference` variable `num` is assigned to that `Integer` object.\n\nIf you attempt to dereference `num` before creating the object you get a `NullPointerException`. In the most trivial cases, the compiler will catch the problem and let you know that \"`num may not have been initialized`,\" but sometimes you may write code that does not directly create the object.\n\nFor instance, you may have a method as follows:\n```\npublic void doSomething(SomeObject obj) {\n // Do something to obj, assumes obj is not null\n obj.myMethod();\n}\n```\nIn which case, you are not creating the object `obj`, but rather assuming that it was created before the `doSomething()` method was called. Note, it is possible to call the method like this:\n```\ndoSomething(null);\n```\nIn which case, `obj` is `null`, and the statement `obj.myMethod()` will throw a `NullPointerException`.\n\nIf the method is intended to do something to the passed-in object as the above method does, it is appropriate to throw the `NullPointerException` because it's a programmer error and the programmer will need that information for debugging purposes.\n\nIn addition to `NullPointerException`'s thrown as a result of the method's logic, you can also check the method arguments for `null` values and throw NPEs explicitly by adding something like the following near the beginning of a method:\n```\n// Throws an NPE with a custom error message if obj is null\nObjects.requireNonNull(obj, \"obj must not be null\");\n```\n\nNote that it's helpful to say in your error message clearly which object cannot be `null`. The advantage of validating this is that 1) you can return your own clearer error messages and 2) for the rest of the method you know that unless `obj` is reassigned, it is not null and can be dereferenced safely.\n\nAlternatively, there may be cases where the purpose of the method is not solely to operate on the passed in object, and therefore a null parameter may be acceptable. In this case, you would need to check for a null parameter and behave differently. You should also explain this in the documentation. For example, `doSomething()` could be written as:\n```\n/**\n * @param obj An optional foo for ____. May be null, in which case\n * the result will be ____.\n */\npublic void doSomething(SomeObject obj) {\n if(obj == null) {\n // Do something\n } else {\n // Do something else\n }\n}\n```\n\nFinally, how to pinpoint the exception & cause using Stack Trace:\n\n> What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?\n\nSonar with find bugs can detect NPE. Can sonar catch null pointer exceptions caused by JVM Dynamically\n\nNow Java 14 has added a new language feature to show the root cause of NullPointerException. This language feature has been part of SAP commercial JVM since 2006. In Java 14, the following is a sample NullPointerException Exception message:\n\n> in thread \"main\" java.lang.NullPointerException: Cannot invoke \"java.util.List.size()\" because \"list\" is null" } ]
[ { "from": "human", "value": "In Raiders of the Lost Ark, at the Ark opening ceremony the Nazi troops brings the Ark of the Covenant to the top of the mountain as Belloq said something before opening the Ark. Then they took the sand from the Ark and suddenly spirits coming out from the Ark and they're all killed (except Indy and Marion) by the freed-spirits which came from the Ark. Meanwhile, Indy asks Marion to keep her eyes shut. They didn't see the Ark when it was opened, so they're survived. In that scene what I don't understand is how did Indy know not to look into the Ark when it was opened?" }, { "from": "gpt", "value": "There was a deleted scene that explained it:\n\n A plot element involving the Ark of the Covenant was cut from the film and is only hinted at during the finale when the Ark is opened. \n Basically, there were 2 rules about the Ark not mentioned in the final cut of the film:\n \n * If you touch the Ark, you die \n * If you look at the Ark when it is opened, you die \n \n This is first explained in additional dialogue for the scene when Indy and Sallah visit Imam. Before translating the writings on the headpiece that give the height of the Staff of Ra, Imam warns Indy not to touch the Ark or look at it when it is opened.\n [Source]\n The next scene involving this Ark subplot is when Sallah and Indy remove the Ark from the Well of the Souls. When Sallah first sees it he reaches out to touch it. Indy stops him before he does and reminds him of Imam's warning. Then they insert long poles through each side of the Ark to lift it out of its crypt.\n [Source]\n Notice that nobody ever touches the Ark throughout the rest of the film until the finale.\n\nAnd from the Bible (King James Version):\n\n 1 Samuel 6:19:\n And he smote the men of Bethshemesh, because they had looked into the ark of the Lord, even he smote of the people fifty thousand and threescore and ten men...\n 2 Samuel 6:6-7\n And when they came to Nachon's threshingfloor, Uzzah put forth his hand to the ark of God, and took hold of it; for the oxen shook it. And the anger of the Lord was kindled against Uzzah; and God smote him there for his error; and there he died by the ark of God.\n" } ]
[ { "from": "human", "value": "What is likely to happen when you plug two ends of a network cable to a single switch/router? Will this create problems on the network, or just be ignored?" }, { "from": "gpt", "value": "It depends on the router/switch. \nIf it's \"Managed\" - Like decent Netgear, Cisco or HP Procurve, or has STP (Spanning Tree Protocol) or one of its variants enabled, there's a few seconds of absolute insanity, then the switch realises that there's a loop in the network topology, and blocks one of the ports. \n(I've only described the STP re-convergence as \"absolute insanity\" because if you're using old-style, slow, STP then re-convergence can take 30s or more, depending on network complexity. Vendor specific STP extensions such as BackboneFast and so on will decrease this, but you might still end up with a short period of a slightly unstable network. Rapid STP is a lot quicker to converge, due to a different algorithm)\nIf it's \"Unmanaged\"- Like pretty much all SOHO grade gear, and a fair proportion of small 4-8 port switches, then all hell breaks loose, as you've just created a loop in a network, and all the traffic tends to just bounce about inside the loop. \nThe reason this happens is because switches rely on a process of MAC address learning to map MAC addresses to physical ports. In a non-looped network, one MAC address will only be visible to the switch on a given physical port. If you have a loop, then the switch will see multiple paths to the same MAC address, and possibly multiple MAC addresses on multiple ports, so instead of the traffic being switched efficiently, it will be broadcast to wherever it sees the MACs. This is known as a \"Broadcast Storm\".\nThis can quickly use up all of a switch's CPU power, fill the transmit and receive buffers, as well as polluting the MAC address table.\nBasically, if you create a loop in the network, you'll know about it, either through monitoring (detecting a change in the STP topology [you do have monitoring, right?]), or in everything falling over dramatically. \nIf you look at a switch that has a broadcast storm on it, you tend to find that all of the port activity lights are blinking all at the same time." } ]
[ { "from": "human", "value": "What command do I use to find the size of all the files (recursively) in a Linux or Mac OS X directory?" }, { "from": "gpt", "value": "The BSD version of ```du``` used in OS X reports size with 512-byte blocks -- the sizes are essentially rounded up to the next 512-byte value. This tells you the space on disk, which is larger than the amount of data. If you have a lot of small files, the difference can be large.\nHere's an example.\nThis is the value with regular ```du```. It's in 512-byte blocks:\n```$ du -s\n248 .\n```\nThe ```-h``` flag results in a more readable number, in kilobytes. As expected, it's half the number of 512-byte blocks:\n```$ du -hs\n124K .\n```\nFinally, you can use ```find``` and ```awk``` to give you the sum of actual bytes in the files. This is kind of slow, but it works:\n```$ find . -type f -exec ls -l {} \\; | awk '{sum += $5} END {print sum}'\n60527\n```\nThis value matches exactly the number reported by Finder's Get Info window. (There are no weird forks or xattrs in this set of files.) It's significantly smaller than the value reported by ```du```.\nHere's how it works: it gets a list of all the files, and passes them to ```ls -l```; then ```awk``` is used to count up the bytes. The ```-type f``` flag is there so that only files (and not directories) get sent to ```ls```. Without that flag, it'll also send directory names to ```ls```, and each file will be listed twice : once as an individual file, and once as an item in the directory.\nThe GNU version of ```du``` can give values in actual bytes instead of blocks. It's unfortunate that the BSD version of ```du``` is not as flexible." } ]
[ { "from": "human", "value": "I've been writing C and C++ code for almost twenty years, but there's one aspect of these languages that I've never really understood. I've obviously used regular casts i.e.\n```MyClass *m = (MyClass *)ptr;\n```\nall over the place, but there seem to be two other types of casts, and I don't know the difference. What's the difference between the following lines of code?\n```MyClass *m = (MyClass *)ptr;\nMyClass *m = static_cast(ptr);\nMyClass *m = dynamic_cast(ptr);\n```" }, { "from": "gpt", "value": "## static_cast\n\n`static_cast` is used for cases where you basically want to reverse an implicit conversion, with a few restrictions and additions. `static_cast` performs no runtime checks. This should be used if you know that you refer to an object of a specific type, and thus a check would be unnecessary. Here is an example:\n\n```\nvoid func(void *data) {\n // Conversion from MyClass* -> void* is implicit\n MyClass *c = static_cast<MyClass*>(data);\n ...\n}\n\nint main() {\n MyClass c;\n start_thread(&func, &c) // func(&c) will be called\n .join();\n}\n```\nIn this example, you know that you passed a `MyClass` object, and thus there isn't any need for a runtime check to ensure this.\n\n## dynamic_cast\n\n`dynamic_cast` is useful when you don't know what the dynamic type of the object is. It returns a null pointer if the object referred to doesn't contain the type casted to as a base class (when you cast to a reference, a `bad_cast` exception is thrown in that case).\n\n```\nif (JumpStm *j = dynamic_cast<JumpStm*>(&stm)) {\n ...\n} else if (ExprStm *e = dynamic_cast<ExprStm*>(&stm)) {\n ...\n}\n```\nAn \"up-cast\" (cast to the base class) is always valid with both `static_cast` and `dynamic_cast`, and also without any cast, as an \"up-cast\" is an implicit conversion (assuming the base class is accessible, i.e. it's a `public` inheritance).\n\n## Regular Cast\n\nThese casts are also called C-style cast. A C-style cast is basically identical to trying out a range of sequences of C++ casts, and taking the first C++ cast that works, without ever considering `dynamic_cast`. Needless to say, this is much more powerful as it combines all of `const_cast`, `static_cast` and `reinterpret_cast`, but it's also unsafe, because it does not use `dynamic_cast`.\n\nIn addition, C-style casts not only allow you to do this, but they also allow you to safely cast to a private base-class, while the \"equivalent\" `static_cast` sequence would give you a compile-time error for that.\n\nSome people prefer C-style casts because of their brevity. I use them for numeric casts only, and use the appropriate C++ casts when user defined types are involved, as they provide stricter checking." } ]
[ { "from": "human", "value": "Why don't toilets use saltwater?" }, { "from": "gpt", "value": "The main answer is logistical. Building a network of pipes to convey water to houses is a major effort, and most places where that's been done found it extremely expensive. Providing a second set of pipes to bring salt water to houses would probably cost about the same. Except that cities go to considerable lengths to put their water reservoirs above the city as far as possible so they don't have to use as much energy for pumping. The few cities with seawater above them pay a lot to pump water out.\nA minor secondary problem is that sewage treatment plants are fairly heavily biological. They grow things in the sewage to break it down. But most of those things won't grow in salt water. It's already a challenge keeping toxic chemicals out of the sewage. For this to work it might be necessary to add a second set of sewer pipes to carry the water away, and develop new methods of treating that salty sewage (the treated sewage couldn't be spread on farmland, for example).\nIt would be far simpler, cheaper and more reliable to simply buy everyone a composting toilet to replace each toilet they currently have. As a halfway measure, mandating more economical toilets would help, as would education campaigns like the ones encouraging people not to flush at all when they urinate. Even with a sensible cistern that has a 2 litre &quot;half flush&quot;, that's two litres wasted every time someone pees.\nAdditionally, salt is not good for pipes. A lot of pipes, even today, are clay or concrete, and salt water is bad for both of these. It's not impossible to get around that, just expensive." } ]
[ { "from": "human", "value": "How do I modify fields inside the new PostgreSQL JSON datatype?" }, { "from": "gpt", "value": "With Postgresql 9.5 it can be done by following-\n```UPDATE test\nSET data = data - 'a' || '{\"a\":5}'\nWHERE data->>'b' = '2';\n```\nOR\n```UPDATE test\nSET data = jsonb_set(data, '{a}', '5'::jsonb);\n```\n\nSomebody asked how to update many fields in jsonb value at once. Suppose we create a table:\n```CREATE TABLE testjsonb ( id SERIAL PRIMARY KEY, object JSONB );\n```\nThen we INSERT a experimental row:\n```INSERT INTO testjsonb\nVALUES (DEFAULT, '{\"a\":\"one\", \"b\":\"two\", \"c\":{\"c1\":\"see1\",\"c2\":\"see2\",\"c3\":\"see3\"}}');\n```\nThen we UPDATE the row:\n```UPDATE testjsonb SET object = object - 'b' || '{\"a\":1,\"d\":4}';\n```\nWhich does the following:\n\n* Updates the a field\n* Removes the b field\n* Add the d field\n\nSelecting the data:\n```SELECT jsonb_pretty(object) FROM testjsonb;\n```\nWill result in:\n``` jsonb_pretty\n-------------------------\n { +\n \"a\": 1, +\n \"c\": { +\n \"c1\": \"see1\", +\n \"c2\": \"see2\", +\n \"c3\": \"see3\", +\n }, +\n \"d\": 4 +\n }\n(1 row)\n```\nTo update field inside, Dont use the concat operator ```||```. Use jsonb_set instead. Which is not simple:\n```UPDATE testjsonb SET object =\njsonb_set(jsonb_set(object, '{c,c1}','\"seeme\"'),'{c,c2}','\"seehim\"');\n```\nUsing the concat operator for {c,c1} for example:\n```UPDATE testjsonb SET object = object || '{\"c\":{\"c1\":\"seedoctor\"}}';\n```\nWill remove {c,c2} and {c,c3}.\nFor more power, seek power at postgresql json functions documentation. One might be interested in the ```#-``` operator, ```jsonb_set``` function and also ```jsonb_insert``` function." } ]
[ { "from": "human", "value": "I find that the survivability and general performance of my party increases massively from levels 1 to 2. At times, level 1 feels like a completely different game from level 2. However, I can't fathom how or why. I think that the availability of healing has something to do with it. From a mechanical perspective, is there any deep reason why level 1 and level 2 seem so radically different? Furthermore, why I do find no similar differences between later levels, such as 6 and 7?" }, { "from": "gpt", "value": "Welcome to Rusty Dagger Shanktown!\nWhat you have noticed is very widely commented upon—1st level is often called “rusty dagger shanktown.” It’s hyper-lethal, rather than the kind of heroic fantasy Dungeons & Dragons pitches itself as. It is very, very difficult for 1st-level PCs to actually really adventure at all. Many, many groups avoid 1st for this reason (many skip 2nd too, even though it is already dramatically different). Personally, I’ll include 1st level often, but the PCs basically always level-up to 2nd almost entirely on roleplaying XP.\nNote that this isn’t unique to 3.5e; it goes back to the earliest days of D&D. Pathfinder, of course, inherited it from 3.5e (I don’t know about PF 2e). It’s also very much still true in 5e—after 4e actually managed to avoid it, which may mean that this is considered a “feature” by some, enough that Wizards of the Coast felt the need to restore it as part of 5e’s general “return to form” after the divisive fourth edition.\nAnyway, the primary causes of rusty dagger shanktown:\nHit points\nAlmost anyone can one-shot almost any 1st-level character. It’s very, very easy to have 6 hp in a world where a decent, but basic, weapon’s base damage averages 7. Even smaller weapons can easily deal that much damage, either through luck or skill. We expect 1st-level characters to often go down in one hit.\nA 2nd-level character can have nearly twice as much hp. Actually, could easily be twice as much, if they multiclass from a small-HD class to a large-HD class. That drastically changes the game, because suddenly you can feel reasonably confident that you aren’t going to just suddenly die before anyone can do anything. Healing actually becomes relevant, where at 1st it’s often too little, too late.\nNotably, this only has this effect because damage doesn’t grow at the same rate. The base damage of weapons is fixed, and ability scores start at double digits but grow very slowly from there. That’s the biggest chunk of early damage for most characters. Even beyond that, a lot of damage boosts—inspire courage, rage, sneak attack—come at 1st anyway. And monsters tend to kind of mirror these trends.\nSo what ends up happening is that a 1st-level character can’t really take a chance in order to get something accomplished. A 2nd-level character can feel reasonably comfortable taking a chance at least once. That dramatically affects the style of play. At 2nd-level D&D literally feels like a different game. Really, it is a different game.\nWealth\nCharacters start with less than 200 gp worth of gear. That’s not enough for a masterwork weapon, not enough even for non-masterwork medium or heavy armors, definitely not enough for any kind of magic item beyond maybe an extremely basic consumable. No 1st-level character has even their complete basic kit yet.\nThe expected wealth of a 2nd-level character is 900 gp. That can afford masterwork armor of anything short of full-plate, and for many armors leave enough left over for a masterwork weapon. Most importantly, that is enough money for a party of 4 to trivially afford a wand of cure light wounds. A wand of cure light wounds is a game-changer. It means you can easily start every fight at full hp. And with 2nd-level hp, that means you can actually take a few risks.\n2nd-level features\nThis varies considerably from one class to the next, but several classes get major class features at 2nd level. The paladin’s 2nd-level feature, divine grace, might be the single greatest class feature in the game (assuming we don’t count “spells” and the like as a singular feature). Rangers don’t get their combat style until 2nd. Bards get 1st-level spells at 2nd (though inspire courage from 1st level is probably more important). Outside of core, meldshapers don’t get any chakra binds until 2nd, which can leave them with zero offense at 1st. Swordsages don’t get Wis-to-AC until 2nd.\nBut plenty of characters are fine from 1st, so this can vary a lot." } ]
[ { "from": "human", "value": "In my table view I have to scroll to the top. But I cannot guarantee that the first object is going to be section 0, row 0. May be that my table view will start from section number 5.\nSo I get an exception, when I call:\n```[mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];\n```\nIs there another way to scroll to the top of table view?" }, { "from": "gpt", "value": "Possible Actions: \n1 \n```func scrollToFirstRow() {\n let indexPath = NSIndexPath(forRow: 0, inSection: 0)\n self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: true)\n}\n```\n2 \n```func scrollToLastRow() {\n let indexPath = NSIndexPath(forRow: objects.count - 1, inSection: 0)\n self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true)\n}\n```\n3 \n```func scrollToSelectedRow() {\n let selectedRows = self.tableView.indexPathsForSelectedRows\n if let selectedRow = selectedRows?[0] as? NSIndexPath {\n self.tableView.scrollToRowAtIndexPath(selectedRow, atScrollPosition: .Middle, animated: true)\n }\n}\n```\n4 \n```func scrollToHeader() {\n self.tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated: true)\n}\n```\n5 \n```func scrollToTop(){\n self.tableView.setContentOffset(CGPointMake(0, UIApplication.sharedApplication().statusBarFrame.height ), animated: true)\n}\n```\nDisable Scroll To Top:\n```func disableScrollsToTopPropertyOnAllSubviewsOf(view: UIView) {\n for subview in view.subviews {\n if let scrollView = subview as? UIScrollView {\n (scrollView as UIScrollView).scrollsToTop = false\n }\n self.disableScrollsToTopPropertyOnAllSubviewsOf(subview as UIView)\n }\n}\n```\nModify and use it as per requirement.\nSwift 4\n``` func scrollToFirstRow() {\n let indexPath = IndexPath(row: 0, section: 0)\n self.tableView.scrollToRow(at: indexPath, at: .top, animated: true)\n }\n```" } ]
[ { "from": "human", "value": "While in Phd I developed a lot of code that I want to turn into start-up. Can I do this?" }, { "from": "gpt", "value": "I'm not aware of any blanket prohibition, anywhere, that say that you can't use code developed during a PhD for a commercial venture - but most Universities in the US will have some kind of intellectual property agreement in place to state what the process is for doing this. You will need to check with officials at your University to see what agreements you are subject to - but you should go a step farther than this. Specifically, you should see what departments might exist that can actually help you.\n\nIn the US at least - and I'm sure many other institutions around the world - there are departments specializing in intellectual property, \"knowledge transfer\", corporate spin-offs, start-ups, entrepreneurship, etc. These can be a rich source of support and networking, if they are available to you, even if you have intellectual property agreements that assign various rights to the University. \n\nUniversities want to earn money for these projects, as I'm sure you do as well, and 100% of $0 is $0. Universities often heavily facilitate the process of converting this work into money, and it is not abnormal for even a place that has heavily restricted intellectual rights assignments agreements to assign use rights and royalty agreements that have zero cost for the first $200,000+ US dollars in income. There are often even startup grants available, accelerators (even if they are not called that - places that provide space and equipment to help starting businesses), introductions to investors, showcases, and more. You won't know until you ask and look for them, as where they are located tends to vary heavily by institution. \n\nFor the exact nature of the agreements that apply to you, we can't say; I've seen everything from \"the student owns their own work\" to \"anyone funded assigns all rights and ownership to the University\", and I'm sure there are agreements everywhere in between. You are right to check them out in advance of a major decision, but this is so specific that you'll need to talk with multiple people are your specific institution to see what applies to you. You may also need to speak with an outside legal professional (lawyer experienced in this area, etc) to verify, but your local administrators are your best first point of contact to see how things work." } ]
[ { "from": "human", "value": "I have heard multiple times in photography, the words Bokeh, and Gaussian Blur. To me, it seems that the words are used almost interchangeably, but in some instances, I have heard them contrasted. What's the difference, and what are the definitions of each of them?" }, { "from": "gpt", "value": "Bokeh is specifically the out-of-focus areas of an image. Gaussian blur is an algorithm to fog selected image areas, to hide details or make them look out of focus.\nThe main differences:\n\n* bokeh is created optically, gaussian blur in post-production;\n* in bokeh, the amount of how wide an out-of-focus point will be smeared is determined by its relative distance from focal plane, whereas gaussian blur is applied to a two-dimensional image where no distance information is present, thus all points are smeared equally;\n* in bokeh, the smearing characteristics depend on configuration and aperture shape of the lens, whereas gaussian blur is always smooth;\n* a small light source will be rendered as an aperture-shaped figure with quite well-defined edges in bokeh; but gaussian blur renders it as a spot with fading edges;\n* in bokeh, noise is present at the same level as in in-focus parts of image with same luminance; gaussian blur kills noise, so there'll be less noise than in non-blurred parts of image;\n* in bokeh, light areas will dominate over dark ones, while gaussian blur gives preserves the ratio of dark-light areas.\n\nSo, all in all, you can use one to fake another, but the result will be similar only for low-noise bokeh containing items on roughly a plane parallel to focal plane, not including any significantly lighter areas or light sources, and taken with a lens that has a smooth bokeh." } ]
[ { "from": "human", "value": "In 1969, NASA not only went to the moon, but broadcast the whole thing live on TV.\nHow did they achieve the TV broadcast? What technology did they need to use to send a video and audio signal from the moon to earth? Was there much of a lag?" }, { "from": "gpt", "value": "Apollo 11 mission had two modules\n\n* Lunar module - which descent to moon carrying two astronauts\n* command / service module- CSM was designed to return astronauts from the lunar surface on a direct-descent mission to earth and splash down.\n\nDirect telecast from the Command service module is not possible but CSM stored the recording of conversation which is transmitted by LM (which occur once in a rotation because the LM is stationary while CSM is orbiting the moon) then CSM sents to earth.\n\nRegarding the actual camera used in Apollo \n\n > Originally, these slow-scan television (SSTV) cameras, running at 10 frames-per-second (fps), produced only black and white pictures and first flew on the Apollo 7 mission in October 1968. \n\nNASA states as\n\n > The equipment onboard the Apollo Command Module that was used to make the recordings was called the Data Storage Equipment (DSE). Its contents were transmitted to the ground periodically during the mission. Also, the Command Module DSE had the capability to record data live during certain periods from the Lunar Module as it flew separately in lunar orbit. The equipment used aboard the Lunar Module to make the recordings was called the Data Storage Electronics Assembly (DSEA). It made recordings onboard the Lunar Module, but the DSEA flown on the Eagle during Apollo 11 malfunctioned. As a result, many of its recordings are barely, if at all, audible, with a constant high-pitched background tone. In the attached database, the recordings that are virtually inaudible are highlighted, but they are available on the web to ensure a complete release of the recordings made during the mission.\n\nand \n\n > The portion of the broadcast spectrum traditionally used for video was sending vital ship data to Earth, and there was no room left for the standard black-and- white video format of the era: 525 scan lines of data at 30 frames per second, transmitted at 4.5 MHz. So Lebar helped devise a smaller \"oddball format\" – 320 scan lines at 10 fps, transmitted at a meager 500 kHz. Tracking stations back on Earth would take this so-called slow-scan footage, convert it for TV broadcast, and beam it to Mission Control, which would send it out for the world to see. \n\nTransmission stations\n\n > To ensure a direct transmission signal from the moon, NASA had to maintain stations in three continents – two in Australia (the Honeysuckle Creek Tracking Station near Canberra and the Parkes Radio Observatory surrounded by sheep paddocks west of Sydney); one at the Goldstone Deep Space Communications Complex in the Mojave Desert of California; and one at the Madrid Manned Flight Tracking Site in Spain........ the tracking stations with a direct line on the Apollo 's signal were the ones in Australia. The 200-foot-diameter radio dish at the Parkes facility manag to withstand freak 70 mph gusts of wind and successfully captured the footage, which was converted and relayed to Houston. " } ]
[ { "from": "human", "value": "Why does \"elite\" rhyme with \"beet\" rather than \"bite\"?" }, { "from": "gpt", "value": "This has everything to do with the following:\n\n* The language of origin of the word and\n* The point at which the word entered the English language.\n\nThe reason that the words &quot;light&quot; and &quot;might&quot; and &quot;site&quot; have a diphthong is because they were present in spoken English during the Great Vowel Shift, which started in the 1400s and continued for a few hundred years. So words that had already entered the English language underwent that change in pronunciation. Those words could be of Anglo-Saxon, Norman French, or Latin origin. We see it across the board.\nHowever, the word elite entered English towards the end of the period of the Great Vowel shift. The first attestation is in the mid 1700s (1738 in the OED). This is probably further complicated by the fact that French has long been the language of nobility, so there are certain pressures to maintain the pronunciation patterns of the origin language.\n&quot;Elite&quot; joined the party a little bit late, so its pronunciation remained rather stable.\nAs Rjpond points out, elite is a modern borrowing. Words like crime, sublime, mime, etc. are older borrowings.\nTo note: There are early occurrences of the word &quot;elite&quot; in around 1400, with the meaning of a &quot;bishop elect&quot;. This sense of the word died out and is now marked as archaic. So when &quot;elite&quot; was re-introduced (directly from French) in the 1700s, there was no existing pronunciation.\n\nSmall addendum:\nAlready existing in English is another word that already occupies the same lexical space that elite would occupy, if the pronunciation were analogized to bite: alight, which dates back to Old English. (It's a lovely word.)\nYou might say that there is some linguistic pressure to avoid creating homophones: elite vs. alight." } ]
[ { "from": "human", "value": "A lot of ShaderToy demos share the Ray Marching algorithm to render the scene, but they are often written with a very compact style and i can't find any straightforward examples or explanation.\nSo what is Ray Marching? Some comments suggests that it is a variation of Sphere Tracing. What are the computational advantages of a such approach?" }, { "from": "gpt", "value": "## TL;DR\nThey belong to the same family of solvers, where sphere tracing is one method of ray marching, which is the family name.\n\n## Raymarching a definition\nRaymarching is a technique a bit like traditional raytracing where the surface function is not easy to solve (or impossible without numeric iterative methods). In raytracing you just look up the ray intersection, whereas in ray marching you march forward (or back and forth) until you find the intersection, have enough samples or whatever it is your trying to solve. Try to think of it like a newton-raphson method for surface finding, or summing for integrating a varying function.\n\nThis can be useful if you:\n\n* Need to render volumetrics that arenot uniform\n* Rendering implicit functions, fractals\n* Rendering other kinds of parametric surfaces where intersection is not known ahead of time, like paralax mapping\netc.\n\n\n## Sphere tracing\nSphere tracing is one possible Ray marching algorithm. Not all raymarching uses benefit form this method, as they can not be converted into this kind of scheme.\n\nSphere tracing is used for rendering implicit surfaces. Implicit surfaces are formed at some level of a continuous function. In essence solving the equation\n```F(X,Y,Z) = 0\n```\n\nBecause of how this function can be solved at each point, one can go ahead and estimate the biggest possible sphere that can fit the current march step (or if not exactly reasonably safely). You then know that next march distance is at least this big. This way you can have adaptive ray marching steps speeding up the process." } ]
[ { "from": "human", "value": "Is martial arts training 'inadequate' for the real world?" }, { "from": "gpt", "value": "Yes, depending on your definitions of martial arts, inadequate, and real world.\nNo, depending on your definitions of martial arts, inadequate, and real world.\n\nSurviving an attack (or combat) is all about stacking the deck in your favour: martial arts (arts of Mars, the God of War) do help, so do guns, team mates, artillery, the police, not being there, body armour, etc... \nThere is no such thing as a typical real world violent attack. For example, urban warfare is not the same thing as a bar brawl and both require very different skill sets to survive. The no prior warning is utter rubbish. There are always signs that something is about to happen. Sure, one may not notice those and a skilled attacker will be trained in camouflaging those signs but they always are. Police officers, body guards, soldiers, etc... are all trained in recognise those signs. \nMaking general sweeping statements about violence and how to survive it generally indicate either bad research or an agenda. \nFor a good site about self defence, especially the section on martial arts, see MacYoung's no nonsense self defense. But this is about civilian self defence in a stable country. If you were in a civil war zone, the advise would be very different." } ]
[ { "from": "human", "value": "Make a single page landscape in Google Documents" }, { "from": "gpt", "value": "Currently a single Google Document can only be either Landscape or Portrait not both. Changing page orientation is done by selecting File and then Page setup.\n\nIt is currently recommended to separate the Landscape and Portrait pages into different documents. A good place to get more information that might help is at Google Products Forums.\n\nNote that an additional option might be to have three files in Google Docs. The Portrait, The Landscape, and Microsoft Word Doc which integrates the two layouts into the correct sequence (this document would be Read Only when viewed in Google Docs).\n\nA Microsoft Word document may allow multiple orientations of the Page Layout, but if it is converted to a Google Document the Page Layout for each page will revert to the first Orientation found in the document.\n\nAlso, creating multiple Orientations in Word isn't as straight forward as one might want either.\n\nFor those wanting to do this in Word: Use portrait and landscape orientation in the same document\n\n1. Select the pages or paragraphs that you want to change to portrait or landscape orientation.\nNOTE: If you select some but not all of the text on a page to change to portrait or landscape orientation, Word places the selected text on its own page, and the surrounding text on separate pages. \n2. On the Page Layout tab, in the Page Setup group, click Margins.\n3. Click Custom Margins. (This is the important part)\n4. On the Margins tab, click Portrait or Landscape.\n5. In the Apply to list, click Selected text..\nNOTE: Microsoft Word automatically inserts section breaks before and after the text that has the new page orientation. If your document is already divided into sections, you can click in a section (or select multiple sections), and then change the orientation for only the sections that you select." } ]
[ { "from": "human", "value": "PHP is writing this error in the logs: \"Notice: Use of undefined constant\".\nError in logs:\n```PHP Notice: Use of undefined constant department - assumed 'department' (line 5)\nPHP Notice: Use of undefined constant name - assumed 'name' (line 6)\nPHP Notice: Use of undefined constant email - assumed 'email' (line 7)\nPHP Notice: Use of undefined constant message - assumed 'message' (line 8)\n```\nRelevant lines of code:\n```$department = mysql_real_escape_string($_POST[department]);\n$name = mysql_real_escape_string($_POST[name]);\n$email = mysql_real_escape_string($_POST[email]);\n$message = mysql_real_escape_string($_POST[message]);\n```\nWhat does it mean and why am I seeing it?" }, { "from": "gpt", "value": "The error message is due to the unfortunate fact that PHP will implicitly declare an unknown token as a constant string of the same name.\nThat is, it's trying to interpret this (note the missing quote marks): \n```$_POST[department]\n```\nThe only valid way this would be valid syntax in PHP is if there was previously a constant ```department``` defined. So sadly, rather than dying with a Fatal error at this point, it issues this Notice and acts as though a constant had been defined with the same name and value:\n```// Implicit declaration of constant called department with value 'department'\ndefine('department', 'department');\n```\nThere are various ways you can get this error message, but they all have the same root cause - a token that could be a constant.\nStrings missing quotes: ```$my_array[bad_key]```\nThis is what the problem is in your case, and it's because you've got string array keys that haven't been quoted. Fixing the string keys will fix the bug:\nChange:\n```$department = mysql_real_escape_string($_POST[department]);\n...(etc)...\n```\nTo:\n```$department = mysql_real_escape_string($_POST['department']);\n...(etc)...\n```\nVariable missing dollar sign: ```var_without_dollar```\nAnother reason you might see this error message is if you leave off the ```$``` from a variable, or ```$this->``` from a member. Eg, either of the following would cause a similar error message:\n```my_local; // should be $my_local\nmy_member; // should be $this->my_member\n```\nInvalid character in variable name: ```$bad-variable-name```\nA similar but more subtle issue can result if you try to use a disallowed character in a variable name - a hyphen (```-```) instead of an underscore ```_``` would be a common case.\nFor example, this is OK, since underscores are allowed in variable names:\n```if (123 === $my_var) {\n do_something();\n}\n```\nBut this isn't:\n```if (123 === $my-var) {\n do_something();\n}\n```\nIt'll be interpreted the same as this:\n```if (123 === $my - var) { // variable $my minus constant 'var'\n do_something();\n}\n```\nReferring to a class constant without specifying the class scope\nIn order to refer to a class constant you need to specify the class scope with ```::```, if you miss this off PHP will think you're talking about a global ```define()```.\nEg:\n```class MyClass {\n const MY_CONST = 123;\n public function my_method() {\n return self::MY_CONST; // This is fine\n }\n public function my_method() {\n return MyClass::MY_CONST; // This is fine\n }\n public function my_bad_method() {\n return MY_CONST; // BUG - need to specify class scope\n }\n}\n```\nUsing a constant that's not defined in this version of PHP, or is defined in an extension that's not installed\nThere are some system-defined constants that only exist in newer versions of PHP, for example the mode option constants for ```round()``` such as ```PHP_ROUND_HALF_DOWN``` only exist in PHP 5.3 or later.\nSo if you tried to use this feature in PHP 5.2, say:\n```$rounded = round($my_var, 0, PHP_ROUND_HALF_DOWN);\n```\nYou'd get this error message:\n\n Use of undefined constant PHP_ROUND_HALF_DOWN - assumed\n 'PHP_ROUND_HALF_DOWN' Warning (2): Wrong parameter count for round()\n" } ]
[ { "from": "human", "value": "I'm from a very rural area and love to garden, however, for work I just moved into an apartment in the city. I miss being able to grow vegetables and so I attempted to start some leaf lettuce indoors, however, almost every plant died quickly. I'm just curious, does anyone have experience growing vegetables indoors? What are the best ones for this? What sort of planter do you use? Do they need to be directly next to a window? How often should they be watered? I'm not used to not having Mother Nature help me out with my plants Any tips that can be provided would be much appreciated, thanks!" }, { "from": "gpt", "value": "Indoor gardening is a bit more difficult then the regular outdoor gardening, there are several factors but in most cases it boils down to: Temperature, Humidity, Light, The air in your apartment. \n\nYou didn't mention exactly where your dying plants are being placed. Do you have a fan within the apartment? Plants need air whether it is natural or even if it is coming from a fan. What type of lighting is inside the apartment? Are you only using natural light? These are important factors to aide the growth of the plant as well. How is the temperature within the apartment? If you notice a lot of temp ups / downs in the area you are gardening than it is probably worth moving the garden or choosing another spot. With apartments that becomes all the more difficult.\n\nYour plant also probably came from some nice greenhouse, an english gardens, a ray weigands, etc etc...They have plenty of light, they also have plenty of means of water and the temperature well most of this is all outside, so they have the advantage of using mother nature. Your plant needs to adjust to these conditions. You should try to begin to place your plants in a very lit area with as much natural wind / fan as possible, these plants need to breath. If your plants are not conditioned for this type of environment you run the risk that they give up and die.\n\nWhen potting the plant ensure the actual pot is cleaned up to remove any unnecessary plant diseases from prior plants. Look on the bottom of the actual pot, are you getting drainage? If not drill a hole in the bottom of the pot if you can, if not toss that pot out and get you a pot that has a good amount of drainage. Overwatering plants will destroy them, and without nature (wind, temperature, etc) the water sitting there takes all the longer to dry out.\n\nWhen it comes to veggies Tomatoes need a ton of sunlight and humidity is great for them as well. Herbs are probably the simpliest to get going but I'm not sure if this is what you are after. Cucumbers and squash don't need as much sunlight as tomatoes." } ]
[ { "from": "human", "value": "What are the advantages of studying words by their frequency?" }, { "from": "gpt", "value": "The main advantage is that by learning higher frequency words, you get a greater \"bang for your buck\" - that is, if you know the most frequent words of the language, you'll be able to understand more of the words you encounter, and therefore you gain the greatest benefit by studying those frequent words first.\nAccording to Nation & Waring (1997), text coverage in the Brown corpus is as follows:\n\n* Most frequent 1000 words: 72.0%\n* Most frequent 2000 words: 79.7%\n* Most frequent 3000 words: 84.0%\n* Most frequent 4000 words: 86.8%.\n\nSo by learning the top 1000 words, you'll know 72% of the words in the average text you read. But after that, there are diminishing returns: the next 1000 words gives you another 7.7% of a typical text, and the next 1000 words allows you to understand just 4.3% more. After that, the returns on memorizing by frequency decrease even more, so learning from frequency lists becomes less useful.\nNote that text coverage (the percentage of words that you know in an average text) is important. We don't need to understand every single word in a text in order to understand the general meaning. Some research has investigated what percentage of words we do need to understand. Laufer and Sim (1985) suggested 65-70% should be understood as an absolute minimum for comprehension, but Laufer (1989) (as described in Hu and Nation (2000)) suggests 95% should be known for solid comprehension. Hu and Nation (2000) suggest that 98% of words should be known for unaided comprehension. \nAlthough learning high-frequency words is a good idea, especially when you first start learning a language, frequency is not the only consideration when choosing words to learn. Barker (2007) suggests that \"cost\" and \"benefit\" be the primary considerations when choosing words to learn; benefit is partially defined by frequency, but also on personal needs. \nSo it's good to learn the \"technical\" vocabulary of your major or field, and it's also useful to learn words related to your interest. It's also beneficial to learn words with a lower \"cost\" - words that are familiar, that you've encountered a lot recently, or that just seem easy.\nAlso, although memorizing words has benefits, it is best to combine this with real exposure to words, so that you learn them naturally in real contexts." } ]
[ { "from": "human", "value": "I have heard many people saying, “Hah! I beat Stockfish,” and one saying, “I am the best chess player ever! I beat Stockfish.” So I wonder if it is possible, just to know whether I should try to beat it. I tried to play it once; I barely played 25 moves." }, { "from": "gpt", "value": "The answer is that they either played it on some very handicapped mode, they took back A LOT of moves, or they are probably lying.\n\nStockfish 11 is currently rated about 3607, and that is in standard chess. Computer programs are typically even HARDER to beat for humans at even faster controls.\n\nThere is a reason elite humans have not played matches against computers for a long time: even the Carlsens of the world cannot beat them any more. According to the ELO winning expectancy calculator, there is currently a 745 point difference between Stockfish 11 and Carlsen, and per the chart, that gives the computer a 99.5439696% chance of winning.\n\nNote: The ratings used above are from different rating pools, and thus, are not truly directly comparable, but used as a rough estimate of what would happen between the computer and Carlsen." } ]
[ { "from": "human", "value": "How to decrypt Jenkins passwords from credentials.xml?" }, { "from": "gpt", "value": "There is a `hudson.util.Secret.decrypt()` function which can be used for this, so:\n\n1. In Jenkins, go to: `/script` page.\n2. Run the following command:\n```println(hudson.util.Secret.decrypt(\"{XXX=}\"))\n```\nor\n```\nprintln(hudson.util.Secret.fromString(\"{XXX=}\").getPlainText())\n```\nwhere `{XXX=}` is your encrypted password. This will print the plain password.\n\nTo do the opposite, you can run:\n```\nprintln(hudson.util.Secret.fromString(\"some_text\").getEncryptedValue())\n```\n\nAlternatively check the following scripts: `tweksteen/jenkins-decrypt`, `menski/jenkins-decrypt.py`." } ]
[ { "from": "human", "value": "I'm pretty disappointed with my horse. He wasn't cheap -- 1000g -- but he just doesn't seem that fast. To make things worse, he's a bit of a wolf magnet and every time I get attacked I have to tediously dismount, blast the wolf, and then remount.\nIs the speed of a horse actually significantly faster than normal running speed? If so, how much faster?" }, { "from": "gpt", "value": "Don't forget that you can sprint with a horse. It might be that you know that you can sprint on your character, but not on your horse. Please note that your horse is also able to sprint using stamina. You can do this using the default Alt key.\n\nHorses are indeed faster, transportation was simplified.\nSince Oblivion, they took Acrobatics and Athletics skills away, thus you can't improve your speed in such way anymore that it would be faster than a horse. The speed improvements by not being Fatigued and not being overweight are not enough to be significant.\n\nAll horses in Skyrim have the same speed and hardiness, they are all draft types that resemble a Clydesdale, and all cost 1000 septims.\n— Wikia - Elder Scrolls V: Skyrim - Horse\n\nAll horses in Skyrim are the same, seems that they wanted to simplify the whole transportation idea.\n\nRestrictions apply on both your character and horse.\nWithout mods, a horse can't be used inside a city. If you do a lot of role-playing within cities having a horse might not be useful. At the same time, characters are limited in Skyrim as Raven Dreamer noted; while you can get over some mountains by jumping left and right trying to get over a rock, a horse will be more superior in performing this task as it is less restricted by physics. You can however be smart enough to choose your path right, rather than trying to work against the physics..." } ]
[ { "from": "human", "value": "Other than rust, corrosion, and other reactions with air that would make the use of a metal unfavorable, how do different metals affect the performance?\nLet's give Yagi an example:\nLet's say I use 4 different metals for the directors\n, reflector, and driven element.\nOne antenna made out of copper, one made out of aluminum, and one made out of a higher resistance conductor, let's say graphite (I know it would snap, I'm just talking theoretical), and iron \nOther then the metal variations, the antennas are identical.\nSo, do different metals with different conductivity and permiability affect the performance of an antenna including gain, efficiency, impedance, elevation, or any other characteristic other then mechanical strength, and chemical reliability in open air. " }, { "from": "gpt", "value": "Considering just electrical properties, the most significant parameter for your selection of antenna conductor is resistance. You want to keep the resistance to a minimum, because when current flows through a resistance, the electrical power is converted to heat, according to Joule heating:\n$$ P = I^2 R $$\nAny energy you use to make heat is energy you aren't using to make electromagnetic waves.\nSo first, you should consider the resistivity ($\\rho$) of various metals. A lower resistivity means you will need less of a metal to reduce the resistance to an acceptable target. Here's a selection, ordered from lowest to highest resistivity in nano-ohm-meters (nΩm), of some metals you might consider using in an antenna:\n\n* Silver: 15.9\n* Copper: 16.8\n* Gold: 24.4\n* Aluminium: 26.2\n* Zinc: 59.0\n* Nickel: 69.9\n* Iron: 100\n* Tin: 109\n\nI'm not going to list stainless steel because there are so many kinds, but generally stainless steels are not great conductors, being over 100 on this scale.\nA high resistivity isn't bad in itself, because you can compensate by making the conductor thicker, and end up with the same resistance. Thus, you might think copper is the best choice (ruling out silver due to high cost), but when you start making mechanical and cost considerations, you may find aluminium is better. This is because for a sample of copper and another of aluminium of equal resistance, the aluminium sample will be bigger, but stiffer, lighter, and cheaper. \nThere's another effect to consider here: with increasing frequency, currents like to flow on the surfaces of conductors. This is called the skin effect. The current flowing only on the skin of a conductor effectively reduces the cross-sectional area, and thus the conductance.\nSince most of the RF current is only on the surface, it often makes sense to build antennas from tubing for antennas requiring rigid elements (a 440 MHz Yagi), or copper-clad steel for wire antennas requiring tensile strength (a 40 meter dipole). This saves weight and cost for a negligible increase in loss.\nMagnetic permeability is a factor in skin depth. With increasing permeability, the skin depth decreases, increasing loss. Of the metals listed above, only iron and nickel have significantly higher permeability. Iron by a factor of about 5000, and nickel by 100 to 600. You could compensate for the reduced skin depth by increasing the surface area of the conductor, but when you consider cost and mechanics, it usually makes more sense to simply avoid iron and nickel and alloys containing them." } ]
[ { "from": "human", "value": "Windows in its earliest days was simply a shell that ran on top of MS-DOS, which means that Windows 3.1 itself was actually just a standard MS-DOS application like any other.\nYet, MS-DOS is not a multitasking operating system, and at the same time, Windows applications were compiled native-code binaries that ran without any form of managed environment. So, how exactly was multitasking of Windows binaries achieved if Windows 3.1 was simply a regular old MS-DOS program itself? Are there any old technical documents still floating around that describe the early Windows architecture internally?" }, { "from": "gpt", "value": "For Win16 programs, Windows implemented co-operative multitasking. Its implementation was based upon the &quot;message loop&quot; architecture of every Windows program.\n\nThe duty of every program was to endlessly run in a loop in which a call to the ```GetMessage``` function was performed. This function call looks whether a message to this process is in the queue. If there is one, it is retrieved (```GetMessage```), optionally translated (```TranslateMessage```, done to convert keyboard shortcuts into menu actions) and finally, passed to the window procedure (```DispatchMessage```).\n\nIf there is no message available in the queue, Windows suspends the current task and gives the CPU to another task. This task will try to retrieve a message from its queue as well, yielding the CPU to another task if no message is present and so on.\n\nIf a program needed to perform background tasks while there were no pending messages in its queue, it would call ```PeekMessage``` instead of ```GetMessage```. This didn't make the task relinquish the CPU, as ```PeekMessage``` would immediately return to the caller task to inform it whether a message is available or not. This was used to time-multiplex message processing with another time-consuming task (think of a 3D program rendering but letting the user cancel that render by pressing a &quot;Cancel&quot; button).\n\nIf this time-consuming task was actually very time-consuming, a well-behaved program should call the ```Yield``` function from time to time, to relinquish the CPU and let other tasks run. A badly-behaved program could easily hog the CPU by not retrieving messages too often or by spending too much time in a window procedure function.\n\nThe situation was quite different for MS-DOS boxes. They ran using the V8086 mode of the 80386 (if Windows was running in enhanced mode). Windows-aware programs ran in the so-called System VM (Virtual Machine 1). DOS boxes ran from VM 2 upwards. DOS programs usually were badly-behaved programs, so Windows assigned each DOS box a different virtual machine. Virtual machines used pre-emptive multitasking in Windows 3.1, so each DOS box could run concurrently to others and to any Windows-aware program." } ]
[ { "from": "human", "value": "I'm working on 2 different branches: release and development. \nI noticed I still need to integrate some changes that were committed to the release branch back into the development branch. \nThe problem is I don't need all of the commit, only some hunks in certain files, so a simple \n```git cherry-pick bc66559\n```\ndoes not do the trick. \nWhen I do a\n```git show bc66559\n```\nI can see the diff but don't really know a good way of applying that partially to my current working tree. " }, { "from": "gpt", "value": "The core thing you're going to want here is ```git add -p``` (```-p``` is a synonym for ```--patch```). This provides an interactive way to add in content, letting you decide whether each hunk should go in or not, and even letting you manually edit the patch if necessary.\nTo use it in combination with cherry-pick:\n```git cherry-pick -n # get your patch, but don't commit (-n = --no-commit)\ngit reset # unstage the changes from the cherry-picked commit\ngit add -p # make all your choices (add the changes you do want)\ngit commit # make the commit!\n```\n``git-cherry-pick``` has a ```--no-commit``` option, and you need to do ```git reset```. If you only want to leave a few things out of the commit, you could use ```git reset ...``` to unstage just those files.)\nYou can provide specific paths to ```add -p``` if necessary. If you're starting with a patch you could replace the ```cherry-pick``` with ```apply```.\n\nIf you really want to ```git cherry-pick -p ``` (that option does not exist), you can use\n```git checkout -p \n```\nThat will diff the current commit against the commit you specify, and allow you to apply hunks from that diff individually. This option may be more useful if the commit you're pulling in has merge conflicts in part of the commit you're not interested in. (Note, however, that ```checkout``` differs from ```cherry-pick```: ```checkout``` tries to apply ``````'s contents entirely, while ```cherry-pick``` applies the diff of the specified commit from it's parent. This means that ```checkout``` can apply more than just that commit, which might be more than you want.)" } ]
[ { "from": "human", "value": "In Civilization V, you attain a cultural victory by accumulating enough culture to purchase at least 36 social policies, and then building a wonder. The catch is that the more cities you build, the more culture you need to generate before you hit the next \"plateau\" of culture.\nWhat is the ideal number of cities for a cultural victory? Does it change over time? " }, { "from": "gpt", "value": "The question you're really asking is &quot;When does the combined culture / turn of an additional city outstrip the increase in social policy cost incurred by founding that city?&quot;\nThe short answer is...\nWe know that adding another city increases the culture costs by approximately 30% of the base cost (that of 1 city). Therefore:\nIf your maximum potential culture / turn won't increase by at least 30% due to the new city, you are hurting, not helping, the time till your next social policy.\n(This may be slightly hard to calculate, and if you take too long to reach your &quot;maximum potential culture / turn&quot; you're actually wasting turns.)\nThe long answer is...\nIt depends\nTo begin with, we need to make some assumptions:\n\n* When you found a new city, you can get its culture / turn maximized within a single turn by buying the necessary building improvements (monument, etc).\n\n* Ignore city-states, leader specific abilities, +culture social policies, and wonders. These all help produce culture, and will shift the &quot;ideal city count&quot; down, but do so inconsistently. To produce an &quot;ideal&quot; city count, we limit ourselves by era and improvements alone.\n\n* This list of social policy costs is accurate for the given parameters: medium map and normal speed.\n\nAnd now, some math.\nThe 1st social policy costs 25 points with a single city. In the ancient era, your cities can generate 2 culture / turn due to the monument. (Remember, we're ignoring the palace for now)\nThis means that it will take 13 turns (Ceiling(25/2) to enact the policy, or 9 turns (ceiling (45/4) with two cities. We can continue this extrapolation -- 8 turns with 3 cities, 7 turns with 4 cities, 6 turns with 5 cities, and we finally reach diminishing returns at city 6 (also 6 turns).\nFor the second social policy, the ramifications of the # of cities gets magnified due to a larger starting value: One city takes 23 turns, two cities take 15 turns, three cities take 13 turns, four cities take 12, five cities take 10, and again, we run into diminishing returns cap out at at six cities (10 turns).\nIt is not until the 4th social policy that this trend is broken and diminishing returns end at the NINTH! city.\nRemember -- this assumes that each city has a monument the minute it is founded.\nNow let's say we've reached the classical age, and have temples in addition to monuments. Each city is now generating 5 culture.\nThe first policy takes 5 turns with a single city, 4 turns with two, and 3 with three.\nWhat (hopefully) becomes clear is that we reached diminishing returns (4 cities as opposed to 6 cities) much faster when each individual city's contribution is higher. The more culture any one city is capable of producing, the more incentive there is to produce more cities. Even if you don't manage to build every +culture improvement immediately, you're still likely to come out ahead (as long as you're pre-diminishing returns).\nSo while the optimal number of cities changes due to any number of factors, you can probably safely not shoot yourself in the foot if you stay between three and six cities, with six being on the high end." } ]
[ { "from": "human", "value": "How to find if a customer is logged in or not in Magento 2.\nIf the customer is logged in then how to get customer data from a session?" }, { "from": "gpt", "value": "It is possible via ```Magento\\Framework\\App\\Http\\Context``` or via ```Magento\\Customer\\Model\\Session```. However, the result may be different:\n\n* HTTP context is initialized earlier than the customer session (but it does not matter since both are initialized in action controllers)\n* When the ```PageCache``` module is on (probably always on production), keep in mind that as soon as layout generation started, the customer session will be cleared by ```\\Magento\\PageCache\\Model\\Layout\\DepersonalizePlugin::afterGenerateXml``` on all cacheable pages. It means that if you now check if the customer is logged in via the HTTP context, it will still say 'yes, but customer data will not be available in customer sessions anymore. So double-check is necessary before trying to access data in customer sessions. This can easily happen in the block, while is unlikely in action controller since you are not expected to generate layout manually there, it will be generated after-action controller returns an instance of ```ResultInterface```\n\nTo eliminate any risk of described inconsistencies when PageCache is on, consider using customer session if it is already initialized (true for action controllers). Else use the HTTP context." } ]
[ { "from": "human", "value": "I have a 9 year old daughter that has expressed some interest in manga, but I'm having trouble locating series that are appropriate for her age. No one at our local bookstore could offer any advice. Is there a kid-friendly imprint or other resource I could use to help her find something appropriate? My preference is for physical books but I'm willing to explore digital options." }, { "from": "gpt", "value": "The content deemed acceptable for Japanese children generally differs from the concept in other countries; manga contains all genres of stories, so one cannot responsibly presume that just because a title was marketed at Japanese kids, that you would likewise consider it appropriate for your kid of the same age.\n\nAs one example:\nThe popular girl's series Sailor Moon was published in the manga magazine Nakayoshi, which was marketed toward elementary school-age girls (1st through 6th grade). This series includes strong language, bullying, violence, death, war, genocide, refugees, lovers' suicide (more than once), non-consensual kisses (forced while awake, while asleep, while drunk), a father fondling his adult daughter while brainwashed, human/animal romance, demonic-style alien possession of human bodies, nudity, cross-dressing, a non-monogamous lesbian couple, and non-graphic sex resulting in teen pregnancy (the 90s anime version, also marketed toward children, also added wrist/ankle restraints for a rape-like, pain-inducing entering of victims).\n\nThere are many manga reviews on the web, including those that specifically for parents and teen/preteen/kid readers on what sort of possibly objectionable content is included in the title (such as strong language, violence, nudity, gender-bending, innuendo, sexual content, etc.) and what sort of general content you can expect (for example: horror, potty humor, serious themes like depression/body image/sexual orientation/prostitution/parental abandonment/bullying/suicide) and let you as the parent or the reader use your own judgment about whether a title fits what you deem appropriate at what age. Browsing reviews also allows you to seek out titles that reinforce and contribute to your family's values (such as traits of selflessness, generosity, celebration of uniqueness, etc.).\n\nSome good starting places are:\n\n* A Parent's Guide to Anime\n* Good Manga for Kids at Manga Bookshelf\n* Good Comics for Kids at School Library Journal\n* Kids Manga at No Flying No Tights\n\nSince you have a daughter, she may be especially interested in shoujo manga, which was written with the target audience of Japanese girls. Within shoujo, nearly all genres of stories are included; some titles are very cheerful and innocuous and teach a moral-of-the-day, others are dark and heavy. Good starting places to get informed are:\n\n* What is Shoujo Manga?, What Shoujo Manga Are and Are Not, and Recommended Shoujo Manga by Matt Thorn, a professor in the Faculty of Manga at Kyoto Seika University (one of the world's experts on shoujo manga)\n* What is Shoujo? at Energetic Heartbeats\n\nSome shoujo manga review sites are:\n\n* The Classics at Shoujo Corner\n* Emily's Random Shoujo Manga Page (despite its unassuming name, contains many detailed reviews)\n* Heart of Manga\n* Shoujo Savvy\n* Shoujo Manga Recommendations\n* Romance Manga Reviews\n* Shoujo Manga Reviews\n* Shoujo Manga with Anime at Anime Manga Reviews\n\nMore general review websites include MangaBlog and Kuriousity, and a Google search will find you many more." } ]
[ { "from": "human", "value": "I'm looking for a precise piece of information in a database which I have no knowledge about. The database is on a separate machine, but I can log into it, and launch a ```psql``` command line, with administrator rights.\nIt's a third-party product, and they are slow to answer questions. I know the data is inside that database, so I want to do a little bit of reverse-engineering.\nGiven a table name, is it possible to get a list of the names of the columns in that table?\nFor example, in SQL Server, it's possible to dump a table into a reusable ```CREATE``` statement, which textually lists all the columns the table is composed of." }, { "from": "gpt", "value": "The information schema is the slow and sure way: it is standardized and largely portable to other databases that support it. And it will keep working across major versions.\nHowever, views in the information schema often join many tables from the system catalogs to meet a strictly standardized format - many of which are just dead freight most of the time. This makes them slow.\nThe Postgres developers aren't making promises, but basics (like what is needed here) aren't going to change across major versions.\nMore detailed assessment:\n\n* Query to output names and data types of a query, table or view\n\n```psql``` (the native command-line interface) takes the fast lane, of course, and queries the source directly. If you start ```psql``` with the parameter ```-E```, the SQL behind backslash commands like ```\\d``` is displayed. Or ```\\set ECHO_HIDDEN on``` from the psql command line. Starting from there you can build an answer to your question.\n\nGiven one table, is it possible to have a list of the names of the columns for this table.\n\n```SELECT attrelid::regclass AS tbl\n , attname AS col\n , atttypid::regtype AS datatype\n -- more attributes?\nFROM pg_attribute\nWHERE attrelid = 'myschema.mytable'::regclass -- table name optionally schema-qualified\nAND attnum > 0\nAND NOT attisdropped\nORDER BY attnum;\n```\nFaster than querying ```information_schema.columns```. Try ```EXPLAIN ANALYZE``` to see for yourself. Still hardly matters for a one-time look-up. But might make a difference if used in a query / function that's repeated many times.\nThere are also subtle differences in visibility. The following artical has detailed comparison:\n\n* How to check if a table exists in a given schema\n" } ]
[ { "from": "human", "value": "I am using Visual Studio Code and have a fairly common project structure:\n```├── client/\n│ ├── tsconfig.json\n├── shared/\n├── server/\n│ ├── tsconfig.json\n├── project.json\n```\nThe two tsconfig files have different settings (e.g. the one under ```client/``` targets ES5, the one under ```server/``` targets ES6). Note that there is no tsconfig in the root directory.\nThe problem is that I want the shared directory to be included in both projects. I can't do this using tsconfig because the ```exclude``` option won't let me include a folder that is in a higher directory than the tsconfig.json, and using ```files``` I have to constantly keep the list of files up to date as it doesn't support globs.\nNote that I can compile fine by adding the shared folder into tsc, what I want is for the Visual Studio Code IDE to recognise the shared code for intellisense etc.\nIs the only option to wait for filesGlob?" }, { "from": "gpt", "value": "These days it is much easier as vscode has better support for this.\nYou can use this directory structure so all the code is independent:\n```├── frontend/\n│ ├── src/\n│ │ ├── \n│ ├── package.json\n│ ├── tsconfig.json\n├── shared/\n│ ├── package.json\n├── backend/\n│ ├── src/\n│ │ ├── \n│ ├── package.json\n│ ├── tsconfig.json\n```\nThen in both the backend and frontend ```tsconfig.json```:\n```{\n &quot;compilerOptions&quot;: {\n &quot;paths&quot;: {\n &quot;~shared/*&quot;: [&quot;../shared/*&quot;]\n },\n &quot;rootDirs&quot;: [\n &quot;./src&quot;,\n &quot;../shared&quot;\n ]\n }\n}\n```\nTo allow access to the shared code e.g.:\n```import { Foo } from '~shared/foo';\n```" } ]
[ { "from": "human", "value": "I have the following method to save an Object to a file:\n```// Save an object out to the disk\npublic static void SerializeObject(this T toSerialize, String filename)\n{\n XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());\n TextWriter textWriter = new StreamWriter(filename);\n xmlSerializer.Serialize(textWriter, toSerialize);\n textWriter.Close();\n}\n```\nI confess I did not write it (I only converted it to a extension method that took a type parameter).\nNow I need it to give the xml back to me as a string (rather than save it to a file). " }, { "from": "gpt", "value": "Use a `StringWriter` instead of a `StreamWriter`:\n\n```\npublic static string SerializeObject<T>(this T toSerialize)\n{\n XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());\n\n using(StringWriter textWriter = new StringWriter())\n {\n xmlSerializer.Serialize(textWriter, toSerialize);\n return textWriter.ToString();\n }\n}\n```\n\nNote, it is important to use `toSerialize.GetType()` instead of `typeof(T)` in XmlSerializer constructor: if you use the first one the code covers all possible subclasses of `T` (which are valid for the method), while using the latter one will fail when passing a type derived from `T`. There is some example code on Ideone that motivates this statement, with XmlSerializer throwing an `Exception` when `typeof(T)` is used, because you pass an instance of a derived type to a method that calls SerializeObject that is defined in the derived type's base class.\n\nAlso, Ideone uses Mono to execute code; the actual `Exception` you would get using the Microsoft .NET runtime has a different `Message` than the one shown on Ideone, but it fails just the same." } ]
[ { "from": "human", "value": "I have a problem with the embedded bitcode term.\nWhat is embedded bitcode?\nWhen to enable, ```ENABLE_BITCODE``` in new Xcode?\nWhat happens to the binary when enabled, ```ENABLE_BITCODE``` in Xcode 7? " }, { "from": "gpt", "value": "> What is embedded bitcode?\nAccording to docs:\n\n> Bitcode is an intermediate representation of a compiled program. Apps you upload to iTunes Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the store.\n\nThis phrase in \"New Features in Xcode 7\" made me to think for a long time that Bitcode is needed for Slicing to reduce app size: \n\n When you archive for submission to the App Store, Xcode will compile your app into an intermediate representation. The App Store will then compile the bitcode down into the 64 or 32 bit executables as necessary.\n\nHowever that's not true, Bitcode and Slicing work independently: Slicing is about reducing app size and generating app bundle variants, and Bitcode is about certain binary optimizations. I've verified this by checking included architectures in executables of non-bitcode apps and founding that they only include necessary ones.\nBitcode allows other App Thinning component called Slicing to generate app bundle variants with particular executables for particular architectures, e.g. iPhone 5S variant will include only arm64 executable, iPad Mini armv7 and so on.\n\n> When to enable ENABLE_BITCODE in new Xcode?\n\n For iOS apps, bitcode is the default, but optional. If you provide bitcode, all apps and frameworks in the app bundle need to include bitcode. For watchOS and tvOS apps, bitcode is required.\n\n> What happens to the binary when ENABLE_BITCODE is enabled in the new Xcode?\nFrom Xcode 7 reference: \n\n> Activating this setting indicates that the target or project should generate bitcode during compilation for platforms and architectures which support it. For Archive builds, bitcode will be generated in the linked binary for submission to the app store. For other builds, the compiler and linker will check whether the code complies with the requirements for bitcode generation, but will not generate actual bitcode. " } ]
[ { "from": "human", "value": "In Dupire's local volatility model, the volatility is is a deterministic function of the underlying price and time, chosen to match observed European option prices.\nTo be more specific, given a smooth surface $(K,T)\\mapsto C(K,T)$ where K is the strike and T is time to maturity. Dupire equation implies that there exits an unique continuous function $\\sigma_{loc}$ defined by\n$$\\sigma_{loc}^{2}(K,T)=\\frac{\\partial_{T}C(K,T)+rK\\partial_{K}C(K,T)}{\\frac{1}{2}K^{2}\\partial_{KK}C(K,T)}$$ for all $(K,T)\\in(0,\\infty)\\times(0,\\infty)$ such that the solution to the stochastic differential equation $dS_{t}/S_{t}=rdt+\\sigma(t,S_{t})dW_{t}$ exactly generates the European call option prices.\nWhat do the dynamics of the local volatility mean? Are dynamics equivalent to the volatility surface? Why the dynamics of local volatility model is highly unrealistic?" }, { "from": "gpt", "value": "A general model (with continuous paths) can be written\n$$\n \\frac{dS_t}{S_t} = r_t dt + \\sigma_t dW_t^S\n$$\nwhere the short rate $r_t$ and spot volatility $\\sigma_t$ are stochastic processes. \nIn the Black-Scholes model both $r$ and $\\sigma$ are deterministic functions of time (even constant in the original model). This produces a flat smile for any expiry $T$. And we have the closed form formula for option prices\n$$\n C(t,S;T,K) = BS(S,T-t,K;\\Sigma(T,K))\n$$\nwhere $BS$ is the BS formula and $\\Sigma(T,K) = \\sqrt{\\frac{1}{T-t}\\int_t^T \\sigma(s)^2 ds}$. This is not consistent with the smile observed on the market. In order to match market prices, one needs to use a different volatility for each expiry and strike. This is the implied volatility surface $(T,K) \\mapsto \\Sigma(T,K)$. \nIn the local volatility model, rates are deterministic, instant volatility is stochastic but there is only one source of randomness\n$$\n \\frac{dS_t}{S_t} = r(t) dt + \\sigma_{Dup}(t,S_t) dW_t^S\n$$\nthis is a special case of the general model with\n$$\n d\\sigma_t = (\\partial_t \\sigma_{Dup}(t,S_t) + r(t)S_t\\partial_S\\sigma_{Dup}(t,S_t) + \\frac{1}{2}S_t^2\\partial_S^2\\sigma_{Dup}(t,S_t)) dt + \\frac{1}{2}S_t\\partial_S\\sigma_{Dup}(t,S_t)^2 dW_t^S\n$$\nWhat is appealing with this model is that the function $\\sigma_{Dup}$ can be perfectly calibrated to match all market vanilla prices (and quite easily too). \nThe problem is that while correlated to the spot, statistical study show that the volatility also has its own source of randomness independent of that of the spot. Mathematically, this means the instant correlation between the spot and vol is not 1 contrary to what happens in the local volatility model. \nThis can be seen in several ways:\n\n1. The forward smile. Forward implied volatility is implied from prices of forward start options: ignoring interest rates,\n$$\n C(t,S;T\\to T+\\theta,K) := E^Q[(\\frac{S_{T+\\theta}}{S_{T}}-K)_+] =: C_{BS}(S=1,\\theta,K;\\Sigma(t,S;T\\to T+\\theta,K))\n$$\nAlternatively, it is sometimes defined as the expectation of implied volatility at a forward date. In a LV model, as the maturity $T$ increases but $\\theta$ is kept constant, the forward smile gets flatter and higher. This is not what we observe in the markets where the forward smile tends to be similar to the current smile.\n\nThis is because the initial smile you calibrate the model too has decreasing skew:\n$$\n\\partial_K \\Sigma(0,S;T,K) \\xrightarrow[T\\to +\\infty]{} 0\n$$ \n\n2. Smile rolling. In a LV model, smile tends to move in the opposite direction of the spot and get higher independently of the direction of the spot.\nThis is not consistent with what is observed on markets. See Hagan and al. Managing Smile Risk for the derivation. This means that\n$\\partial_S \\Sigma_{LV}(t,S;T,K)$ often has the wrong sign so your Delta will be wrong which can lead to a higher hedging error than using BS. \n3. Barrier options. In FX markets, barrier options like Double No Touch are liquid but a LV model calibrated to vanilla prices does not reproduce these prices. This is a consequence of the previous point. \n\nThe LV model is a static model. Its whole dynamic comes from the volatility surface at time 0. But the vol surface has a dynamic that is richer than that.\nThere are alternatives using multiple factors like SV models, LSV models (parametric local vol like SABR or fully non parametric local vol), models of the joint dynamic of the spot and vol surface etc... but the LV model remains the default model in many cases due to its simplicity, its ability to calibrate the initial smile perfectly and its numerical efficiency. " } ]
[ { "from": "human", "value": "Can you explain why we need a large number of trees in random forest when the number of predictors is large? How can we determine the optimal number of trees?" }, { "from": "gpt", "value": "Random forest uses bagging (picking a sample of observations rather than all of them) and random subspace method (picking a sample of features rather than all of them, in other words - attribute bagging) to grow a tree. If the number of observations is large, but the number of trees is too small, then some observations will be predicted only once or even not at all. If the number of predictors is large but the number of trees is too small, then some features can (theoretically) be missed in all subspaces used. Both cases results in the decrease of random forest predictive power. But the last is a rather extreme case, since the selection of subspace is performed at each node.\n\nDuring classification the subspace dimensionality is $\\sqrt{p}$ (rather small, $p$ is the total number of predictors) by default, but a tree contains many nodes. During regression the subspace dimensionality is $p/3$ (large enough) by default, though a tree contains fewer nodes. So the optimal number of trees in a random forest depends on the number of predictors only in extreme cases. \n\nThe official page of the algorithm states that random forest does not overfit, and you can use as much trees as you want. But Mark R. Segal (April 14 2004. \"Machine Learning Benchmarks and Random Forest Regression.\" Center for Bioinformatics & Molecular Biostatistics) has found that it overfits for some noisy datasets. So to obtain optimal number you can try training random forest at a grid of ```ntree``` parameter (simple, but more CPU-consuming) or build one random forest with many trees with ```keep.inbag```, calculate out-of-bag (OOB) error rates for first $n$ trees (where $n$ changes from $1$ to ```ntree```) and plot OOB error rate vs. number of trees (more complex, but less CPU-consuming)." } ]
[ { "from": "human", "value": "I believe artificial intelligence (AI) term is overused nowadays. For example, people see that something is self-moving and they call it AI, even if it's on autopilot (like cars or planes) or there is some simple algorithm behind it.\nWhat are the minimum general requirements so that we can say something is AI?" }, { "from": "gpt", "value": "It's true that the term has become a buzzword, and is now widely used to a point of confusion - however if you look at the definition provided by Stuart Russell and Peter Norvig, they write it as follows:\n\n> We define AI as the study of agents that receive percepts from the environment and perform actions. Each such agent implements a function that maps percept sequences to actions, and we cover different ways to represent these functions, such as reactive agents, real-time planners, and decision-theoretic systems. We explain the role of learning as extending the reach of the designer into unknown environments, and we show how that role constrains agent design, favoring explicit knowledge representation and reasoning.\n\nArtificial Intelligence: A Modern Approach - Stuart Russell and Peter Norvig\n\nSo the example you cite, \"autopilot for cars/planes\", is actually a (famous) form of AI as it has to use a form of knowledge representation to deal with unknown environments and circumstances. Ultimately, these systems also collect data so that the knowledge representation can be updated to deal with the new inputs that they have found. They do this with autopilot for cars all the time\n\nTo answer your question, for something to be considered as \"having AI\", it needs to be able to deal with unknown environments/circumstances in order to achieve its objective/goal, and render knowledge in a manner that provides for new learning/information to be added easily. There are many different types of well defined knowledge representation methods, ranging from the popular neural net, through to probabilistic models like bayesian networks (belief networks) - but fundamentally actions by the system must be derived from whichever representation of knowledge you choose for it to be considered as AI." } ]
[ { "from": "human", "value": "I have some questions regarding the usage and significance of the ```synchronized``` keyword. \n\n* What is the significance of the ```synchronized``` keyword?\n* When should methods be ```synchronized```?\n* What does it mean programmatically and logically?" }, { "from": "gpt", "value": "The ```synchronized``` keyword is all about different threads reading and writing to the same variables, objects and resources. This is not a trivial topic in Java, but here is a quote from Sun:\n\n> ```synchronized``` methods enable a simple strategy for preventing thread interference and memory consistency errors: if an object is visible to more than one thread, all reads or writes to that object's variables are done through synchronized methods.\n\nIn a very, very small nutshell: When you have two threads that are reading and writing to the same 'resource', say a variable named ```foo```, you need to ensure that these threads access the variable in an atomic way. Without the ```synchronized``` keyword, your thread 1 may not see the change thread 2 made to ```foo```, or worse, it may only be half changed. This would not be what you logically expect.\n\nAgain, this is a non-trivial topic in Java. To learn more, explore topics about:\n\n* Concurrency\n* Java Memory Model\n\nKeep exploring these topics until the name \"Brian Goetz\" becomes permanently associated with the term \"concurrency\" in your brain. " } ]
[ { "from": "human", "value": "I am using the ```$http``` service of AngularJS to make an Ajax request. \nHow can a spinner GIF (or another type of busy indicator) be shown while the Ajax request is executing?" }, { "from": "gpt", "value": "This really depends on your specific use case, but a simple way would follow a pattern like this:\n\n```\n.controller('MainCtrl', function ( $scope, myService ) {\n $scope.loading = true;\n myService.get().then( function ( response ) {\n $scope.items = response.data;\n }, function ( response ) {\n // TODO: handle the error somehow\n }).finally(function() {\n // called no matter success or failure\n $scope.loading = false;\n });\n});\n```\n\nAnd then react to it in your template:\n```\n<div class=\"spinner\" ng-show=\"loading\"></div>\n<div ng-repeat=\"item in items>{{item.name}}</div>\n```" } ]
[ { "from": "human", "value": "Let's say that we have a gaseous or liquidus compound (I don't know if elements or compounds make a difference, take this as a thought experiment), and we have a tungsten or steel block that's 5cm (or less, you choose) thick. Is there any physical method for that gas or liquid to pass through that thick heavy metal block (not by drilling etc.)?" }, { "from": "gpt", "value": "Yes, some gases can diffuse into and through metal. It is the bane of the high-vacuum engineer's life. Hydrogen is the worst because it tends to dissociate into atoms at the surface and the nucleus, a single proton, can then leave its electron behind and wander through the metal lattice until it picks up another electron when it leaves.\n\nFor example Mu-metal, favoured for some applications, typically has to be annealed in hydrogen at high temperature. Once that is over, it can take weeks or months for the residual hydrogen to diffuse out of the metal before a high enough vacuum can be achieved and the work proceed.\n\nA &quot;virtual leak&quot; occurs where a small bubble of gas is embedded in the material inside a vacuum chamber. The leak usually happens because a tiny hole exists for the gas to diffuse out through, but sometimes the &quot;hole&quot; is no more than an ultra-thin skin of metal (invisible to the frustrated technician) and the gas diffuses through it. These little horrors can keep going for months or even years and generally mean replacing suspected parts and pumping down over and over again until the dodgy one is finally stumbled on.\n\nHelium is both monatomic and the physically smallest atom. It can diffuse more easily than any other neutral atom or molecule, making certain metal foils unsuitable as say gas-tight liners for airships. As noted in another answer, in quantity it can also affect the bulk properties of the metal.\n\nOn a more energetic scale, hydrogen and helium nuclei (protons and alpha particles) can pass through thin metal foils if fired with sufficient energy, and this has been used to establish the crystalline structures of some metals and alloys (where, for whatever reason, electrons were unsuitable).\n\nOther gases have much larger atoms (neon and other noble gases) or molecules (nitrogen and other diatomic molecules, water and other hydrides), but they can still diffuse extremely slowly through some metals. This can limit the lifetime of some microchips. A related phenomenon occurs where there is a defect in the lattice at the surface, such as a grain boundary, and a gas atom attaches to it. Defects are sometimes quite mobile and can migrate through the lattice; the gas atom will stabilise the defect and may be able to hitch a ride.\n\nQuantum processes such as tunnelling are not really relevant, as they work over distances smaller than the atomic wavelength, which in turn is typically far smaller than the thickness of any metal atom or foil. The probability of a gas atom tunnelling across is so infinitesimal as to be effectively zero." } ]
[ { "from": "human", "value": "Once, I boarded a plane, went to my designated seat and tried to put my bag in the overhead bin. However, it was full, and other adjacent overhead bins were full too. Because I had a seat next to the emergency exit, which I paid for, I had to hand over my bag to someone else in order to take off. \nDo I have any rights over the overhead bin above my seat?\nCould I ask the flight attendant to remove some of the bags to make room for me?\nI cannot imagine that the bins were full because there was not enough space. I think this happened because some people were ignorant enough to bring more bags than is allowed inside the airplane instead of sending them to cargo. If this is the case why doesn't the airline enforce the bag limit inside the airplane?" }, { "from": "gpt", "value": "You have no right to the bin above your seat. For those exit rows where you cannot put anything beneath the seat in front of you, flight attendants will generally try to help find some space somewhere for at least your small personal item, but any passenger may be required to check their bags rather than put them in the overhead bin.\nIt is entirely possible that the airline didn't enforce the bag limit, but the overhead bins can easily fill up even when the limit is strictly enforced. If every passenger, or even most passengers, brings a regulation sized carry-on on a full flight, it is obvious that many of the bags will not fit in the bins and will have to be checked.\nIn some cases, overhead bins may be marked as reserved for first class or premium economy passengers (or safety equipment, or pillows and blankets). Even in such cases, cabin crew may fill these bins with other bags in an attempt to accommodate as many passengers as possible, and a late-boarding passenger may be caught out with no space.\nIt is hard to imagine that they are likely to remove and check someone's bag so you may have that space. Overhead bin space is typically first-come first served, and at some point, they will declare the bins full and start checking bags (sometimes even before the bins are actually full). Note that if your bag must be checked, you should ensure you remove any essential items (medication, passports, keys, etc...) and any valuables, along with any hazardous material that cannot be checked, namely spare (uninstalled) lithium batteries including external power packs. \nBoarding as early as possible (which, on some airlines, could require frequent flyer status or paying an extra fee) will help secure you overhead bin space." } ]
[ { "from": "human", "value": "The Canon EF 40mm f/2.8 has a designation of STM on the lens. What does this mean? What are the advantages of having it and does it replace an older technology?\n" }, { "from": "gpt", "value": "STM stands for Stepper Motor and is a applied to a new range of Canon lenses which feature a new design of focus motors which, along with a new iris mechanism are designed to eliminate (auditory) noise during video recording. \nCanon haven't revealed any information about how the new design works but it's probably the same type of motor used in mirrorless camera lenses. It's a more precise version of a regular DC motor but still has the same direct connection to the lens focus group, which means manual focus has to be implemented using a focus-by-wire arrangement whereby moving the focus ring by hand sends a signal to the motor to move the focus group. \nIn comparison an ultrasonic motor (like Canon's USM) consists of a pair of concentric rings which vibrate at high frequency to rotate back and forth, an arrangement which permits the user to move the focus ring to directly move the lens element, achieving full time manual focus without damaging the motor.\nStepper motors are better at producing smooth, precise incremental movements, such as those required by contrast detect AF, and AF during video. Ultrasonic motors are better at jumping to the right focus point as part of a phase detection system." } ]
[ { "from": "human", "value": "I'm trying to set get id of all elements in an ```HTMLCollectionOf```. I wrote the following code:\n```var list = document.getElementsByClassName(\"events\");\nconsole.log(list[0].id);\nfor (key in list) {\n console.log(key.id);\n}\n```\nBut I got the following output in console:\n```event1\nundefined\n```\nwhich is not what I expected. Why is the second console output ```undefined``` but the first console output is ```event1```?" }, { "from": "gpt", "value": "You can't use ```for```/```in``` on ```NodeList```s or ```HTMLCollection```s. However, you can use some ```Array.prototype``` methods, as long as you ```.call()``` them and pass in the ```NodeList``` or ```HTMLCollection``` as ```this```.\nSo consider the following as an alternative to jfriend00's ```for``` loop:\n```var list= document.getElementsByClassName(\"events\");\n[].forEach.call(list, function(el) {\n console.log(el.id);\n});\n```\nThere's a good article on MDN that covers this technique. Note their warning about browser compatibility though:\n\n [...] passing a host object (like a ```NodeList```) as\n ```this``` to a native method (such as ```forEach```) is not guaranteed to work in\n all browsers and is known to fail in some.\n\nSo while this approach is convenient, a ```for``` loop may be the most browser-compatible solution.\nUpdate (Aug 30, 2014): Eventually you'll be able to use ES6 ```for```/```of```!\n```var list = document.getElementsByClassName(\"events\");\nfor (const el of list)\n console.log(el.id);\n```\nIt's already supported in recent versions of Chrome and Firefox." } ]
[ { "from": "human", "value": "I am 21 years old and living in a large city in Germany where smalltalk in local markets is not a common thing.\nA new cashier joined my local food shop. She’s always at the checkout and never doing stuff like sorting products or cleaning the floor where I could actually ask her out. I am quite new to relationships, but the signs she gave me are promising.\nMy question is how I can ask for her number, or ask her out for coffee while she is only sitting at the checkout? I mean there are always like 5 people before and after me, and I think it would be awkward if we are changing numbers while customers are waiting behind us. Or even worse if I read the signs wrong and she rejects me? Since the store is just 5 min away from my place I visit regularly and don't want to leave a bad impression there." }, { "from": "gpt", "value": "Asking her out directly seems like a bad idea.\nInstead, in these situations, I've found something that works much better for both of you. During your conversation with her, mention some place you're planning to be in the future so she can find you there if she chooses.\nFor example: &quot;I like to grab lunch here before going to [Public Event You Enjoy]&quot;\nThis could be almost anything, but here are some examples:\n\n* A place your band plays\n* A public dance\n* A painting/pottery class\n* A wine tasting\n\nThis should be something you actually enjoy, so be sure to let your excitement about your hobby be apparent when you mention it. Ex: &quot;I enjoy that they let you try lots of different wines from all around the world!&quot;\nIf she expresses interest in the activity as well, tell her more about it so she can attend: &quot;Yeah, it's really fun. They do it every Tuesday and Thursday at 7pm - the admission fee is 5 Euro. You should check it out sometime!&quot;\nIf she is interested in you and has time, she will probably arrange to come to the event some time and you will see her there. This is preferable because she is not under obligation to behave professionally for her work and you can spend some time chatting as equals.\nAnd if that goes well, then you have created a good opportunity to ask her on a real date. And if she doesn't come, well, you were planning to go there anyways so it's not a real loss on your part - you just spent an afternoon/evening doing something you already enjoy." } ]
[ { "from": "human", "value": "You start with the number 1536. Your mission is to get to 1 in as few steps as possible. At each step, you may either multiply or divide the number you have, by either 2 or 3; but, only if the result is a whole number whose first digit is 1, 3, 4, or 9. That is all." }, { "from": "gpt", "value": "As Jo has already shown, this can be accomplished in \n\n 28 steps. This is minimal, and it can be proven.\n\nTo help visualize this problem, we can imagine: \n\n A two-dimensional grid/chart where each point is a number of the form $3^x2^y$, with $(x,y)$ as the relevant co-ordinates. We want to find a path from $(1,9)$ to $(0,0)$ while making only one step up/down/left/right at a time, and ensuring that the numbers we step on have their most significant digit in the set {1,3,4,9}.\n Here is what the chart looks like for the range $(0,0)$ to $(10,10)$. The dashes represent numbers that do not begin with {1,3,4,9}, and so are unusable in our path.\n ```1024 3072 9216 ---- ---- ---- ---- ---- ---- ---- ---- .```\n ```---- 1536 4608 13824 41472 124416 373248 1119744 3359232 10077696 30233088 .```\n ```---- ---- ---- ---- ---- ---- 186624 ---- 1679616 ---- 15116544 .```\n ```128 384 1152 3456 10368 31104 93312 ---- ---- ---- ---- .```\n ```---- 192 ---- 1728 ---- 15552 46656 139968 419904 1259712 3779136 .```\n ```32 96 ---- ---- ---- ---- ---- ---- ---- ---- 1889568 .```\n ```16 48 144 432 1296 3888 11664 34992 104976 314928 944784 .```\n ```---- ---- ---- ---- ---- 1944 ---- 17496 ---- 157464 472392 .```\n ```4 12 36 108 324 972 ---- ---- ---- ---- ---- .```\n ```---- ---- 18 ---- 162 486 1458 4374 13122 39366 118098 .```\n ```1 3 9 ---- ---- ---- ---- ---- ---- 19683 ---- .```\n From here, we can see two different routes of 28 steps each: (1536->373248->93312->384->48->3888->972->36->9->1) and (1536->373248->46656->3779136->944784->3888->972->36->9->1). \n\nProving minimality: \n\n Since a path of length 28 exists (we've found two), we can rule out anything that's too far away to be used in a shortest path.\n Moving from (1,9) to (0,0) must take at least ten steps on its own, so we can move at most nine steps completely out of the way (and nine steps back) in a shortest route. That limits us to only considering x-coordinates up to 10; any further would require making at least ten '*3' steps, eleven '÷3' steps, and at least nine '÷2' steps, putting the route definitely longer than 28.\n With our x-coordinate limited to [0,10], we now look at the bottlenecks.\n It should be clear that any shortest route must start by going from 1536 to 93312 in seven steps, and must end by going from 3888 to 1 in nine steps. These are both forced by unique bottlenecks; there is only one way to step from $(x,7)$ to $(x,6)$ and only one way to step from $(x,3)$ to $(x,2)$ in this range.\n This leaves at most twelve steps to go from 93312 to 3888. Either by observation or by pointing out that there are only two ways to go from $(x,6)$ to $(x,5)$, we can see that there are exactly two shortest routes from 93312 to 3888, and both require all twelve steps.\n Therefore, the shortest route is 28 steps, and there are exactly two ways to do so, both of which are described in Jo's solution and below the chart. \n" } ]
[ { "from": "human", "value": "I want to create a simple bit of JS code that creates an image element in the background and doesn't display anything. The image element will call a tracking URL (such as Omniture) and needs to be simple and robust and work in IE 6 = ```var oImg = document.createElement(\"img\"); oImg.setAttribute('src', 'http://www.testtrackinglink.com'); oImg.setAttribute('alt', 'na'); oImg.setAttribute('height', '1px'); oImg.setAttribute('width', '1px'); document.body.appendChild(oImg); ``` Is this the simplest but most robust (error free) way to do it?" }, { "from": "gpt", "value": "```oImg.setAttribute('width', '1px');\n```\n```px``` is for CSS only. Use either:\n```oImg.width = '1';\n```\nto set a width through HTML, or:\n```oImg.style.width = '1px';\n```\nto set it through CSS.\nNote that old versions of IE don't create a proper image with ```document.createElement()```, and old versions of KHTML don't create a proper DOM Node with ```new Image()```, so if you want to be fully backwards compatible use something like:\n```// IEWIN boolean previously sniffed through eg. conditional comments\nfunction img_create(src, alt, title) {\n var img = IEWIN ? new Image() : document.createElement('img');\n img.src = src;\n if ( alt != null ) img.alt = alt;\n if ( title != null ) img.title = title;\n return img;\n}\n```\nAlso be slightly wary of ```document.body.appendChild``` if the script may execute as the page is in the middle of loading. You can end up with the image in an unexpected place, or a weird JavaScript error on IE. If you need to be able to add it at load-time (but after the `````` element has started), you could try inserting it at the start of the body using ```body.insertBefore(body.firstChild)```.\nTo do this invisibly but still have the image actually load in all browsers, you could insert an absolutely-positioned-off-the-page `````` as the body's first child and put any tracking/preload images you don't want to be visible in there." } ]
[ { "from": "human", "value": "Why is %s better than + for concatenation in python?" }, { "from": "gpt", "value": "There are several benefits of using ```%s``` over ```+``` for string concatenation in Python:\n* Readability. The format string syntax is more readable, as it separates style from the data. Also, in Python, ```%s``` syntax will automatically coerce any non ```str``` types to ```str```; while concatenation only works with ```str```, and you can't concatenate ```str``` with ```int```.\n* Performance. In Python ```str``` is immutable, so the left and right string have to be copied into the new string for every pair of concatenation. If you concatenate four strings of length 10, you will be copying (10+10) + ((10+10)+10) + (((10+10)+10)+10) = 90 characters, instead of just 40 characters. And things gets quadratically worse as the number and size of the string increases. Java optimizes this case some of the times by transforming the series of concatenation to use ```StringBuilder```, but CPython doesn't.\n* For some use cases, the logging library provide an API that uses format string to create the log entry string lazily (```logging.info(\"blah: %s\", 4)```). This is great for improved performance if the logging library decided that the current log entry will be discarded by a log filter, so it doesn't need to format the string.\n" } ]
[ { "from": "human", "value": "I had an interview with an employer working on a software-based vehicle solution.\nBefore going further in the interview process, he gave me a task to find out if a potential customer (automotive OEMs) is interested.\nMy question is, how can I approach a potential customer and arrange some time together to present to them the solution?. I'm intending to use Linkedin, but I'm not sure how to proceed.\n\n* Who to contact (I mean the person position in the company)\n* How to formulate the request?\n" }, { "from": "gpt", "value": "Run (and run fast) - here are just a few points to consider:\n\n* That's a very unorthodox task for somebody still in the interviewing stage.\n* How you going to present a solution you aren't familiar with?\n* Since you aren't an employee of said company yet you have no grounds to represent them or even hustle their products.\n* You aren't on their payroll yet so why should you waste your time looking for customers?\n* There are a bunch of legal issues arising from such a 'task' (think NDA etc..).\n* How will your potential employer determine if your task has been carried out successfully?\n* Any CEO/CTO or even higher management of any automotive company will NOT engage in such a conversation with a random stranger.\n* Such an unprofessional approach is extremely disrespectful of the prospective customer's time.\n\nThese are all major red flags and should lead any mentally sane person to the conclusion that the person asked for such tasks is unreasonable and has no clue about business in general.\nAdditionally - what kind of impression do you think they will have of you or your potential, future employer considering the above mentioned points?\nThank them for their time and continue applying elsewhere because this company is a nut-house." } ]
[ { "from": "human", "value": "When an expendable booster rocket stage nears the end of its burn, does the guidance computer shut the engine(s) off at a certain velocity/altitude for the mission, or does the stage completely exhaust its propellants?" }, { "from": "gpt", "value": "First stages are generally run to depletion (though not complete depletion). First stage ascents often use a preprogrammed, open loop guidance system to get out of the atmosphere with a good chunk of downrange velocity. Because winds aloft and other factors may vary, first stage performance also varies somewhat.\nUpper stage guidance is almost always closed loop, targeting a specific position and velocity combination. As a result, upper stages of boosters are shut down when that target is reached, with some amount of reserve propellants left to cover dispersions during ascent and a disposal burn.\nLiquid fueled first stages are not run dry. Cutoff is triggered with some amount left in the tank. This is because the turbopumps operate at ridiculous velocities and need something to pump, at a specific inlet pressure. The heat source (gas generator, expander, or preburner) that drives the pump is downstream of the inlet in the flow path, so cutoff has to happen by cutting off the drive force to the pump before the inlet loses pressure or runs dry. \nIf that pressure drops below minimum specifications or if the inlet goes dry, you will get cavitation and/or overspeed conditions, both of which would result in a violent reconfiguration of the hardware.\nSolid lower stages are much simpler in this regard. At some point, the thrust will tail off until the booster no longer supports its own weight. At that point, it is jettisoned." } ]
[ { "from": "human", "value": "Is &quot;ima&quot; an informal spelling of &quot;I must&quot;?\n\nMegaCharizardZord Replying to @nytimes about COVID-19 vaccine:\ni just hope when i take it don't die lol. i trust the government in Canada, but if I do get something ima sue the shit out of em lol.\n\n\nSource: Twitter\n" }, { "from": "gpt", "value": "Ima is an informal contraction of I'm going to when it's used in going-to future construction - not in sentences like I'm going to London etc. It's also written i'ma or imma in informal conversations.\nHow did I'm going to come to be pronounced/spelt that way?\nIn casual speech, we tend to drop consonants that require more effort to articulate, assimilate nearby consonants, drop weak vowels etc., for the ease of articulation. Grammatical words that don't have any meaning on their own (function words?) like have to, going to (not present continuous), has, is, was, will etc., are highly susceptible to these sound changes. For instance, have to is often pronounced hafta, trying to is pronounced tryna, want to is wanna etc etc. The same thing happened to the phrase I'm going to.\n\nThere are a few processes involved in the reduction of I'm going to to ima.\n\n* I'm going to → I'm gonna: the consonant t is often dropped in many other clusters and grammatical constructions as well (as in tryna, wanna etc). Here it's dropped and the vowel of to—which is usually a schwa [ə]—is linked with the preceding word; going to → gonna: [ˈɡəʊɪ̃ŋtə] → [ˈgə̃nə]\n\n* Deletion of the /g/: plosives (/g t d k/ etc) require great effort to articulate (the air is completely blocked and then released), so people dropped the plosive /g/ to make its articulation easier: [aɪ̃m gə̃nə] → [aɪ̃m ə̃nə] (i'm ana)\n\n* linking I'm and gonna: In causal and connected speech, consonants and vowels are often linked by a process called liaison, so both I'm and gonna join together and become [aɪ̃mə̃nə] (i'mana).\n\n* Syncope of the vowel in the second syllable: Unstressed schwas are often lost through syncope (for example, 'chocolate' is choc.late for most speakers). If we removed the schwa from the second syllable, we'd get [aɪmnə] (i'mna).\n\n* Deletion of /n/: It's simple cluster reduction. In English, two nasals that are next to each other are often reduced to a single nasal (as in damn), so the /n/ is deleted, yielding in this case [aɪ̃mə] (i'ma). Or people dropped the /n/ for the sake of ease.\n\nSome people further reduce the diphthong [aɪ] it to something like [a], which results in [ãmə] (ama)\nThat's why people spell it that way. It's highly informal and as TypeIA pointed out in a comment, it's mostly a verbal thing and is not usually found in written form. It's commonly found in chatspeak or lolspeak. You shouldn't write it in any kind of writing." } ]
[ { "from": "human", "value": "How to prevent \"Delhi Belly\" from eating/drinking locally?" }, { "from": "gpt", "value": "Basically, you can't.\nThe world is full of gastrointestinal (GI) diseases, even in developed, First World nations. There are some decent steps to trying to minimize your exposure:\n\n* Properly cooked foods. Everything heated to a proper internal temperature (depends on the dish, check the USDA's site for guidelines), no sampling the raw chicken dish, etc.\n* For fruits and veg, if you can't peel it, don't eat it. A tremendous number of GI outbreaks are due to fruit and veg, rather than meat. This includes things like salads - since you can't really peel lettuce, avoid it.\n* Check if the local water is safe. When in doubt, assume it isn't. You can stick to bottled water, though there's always the distinct chance its being bottled from a contaminated source. Coke/Pepsi etc., and beer are good alternatives. Little known fact, the Coca-Cola company is hugely involved in clean water programs worldwide, because they need it for their product.\n* Ice. Ice is bad. Its probably made using the local tap-water, and there are many beasties that can survive an encounter with an ice machine.\n\nBut when it comes down to it, nearly every traveller makes some sort of safe-eating \"mistake\" fairly frequently, whether they realize it or not. At the end of the day, your best bet is to talk to your travel physician, and see if you can get a prescription for an antibiotic. Using that in combination with something like Imodium will probably keep your trip mostly on track - shutting down the problem long enough for the antibiotics to treat the source. Unless of course its viral - norovirus, rotavirus etc. In that event, best of luck.\nAnd if it does happen? Stay hydrated. You're losing salts and water, they need to be replaced." } ]
[ { "from": "human", "value": "I'm working at my first programming job. My boss is a very smart software engineer, and I feel\nlike I have very little to offer compared to him. Problem is, he is always busy, and needs someone to help him out. I feel like I'm not good enough, but I still want to succeed. I want to be a great programmer.\nWhat can I do to impress him?\nThank you." }, { "from": "gpt", "value": "Remember the scene in Aladdin where Aladdin wants to impress Jasmine, and the genie tells him he'd do better to just focus on being himself? Same principle here.\nIf the boss is that much better than you and you know it, he probably knows it too. He isn't expecting any great feats of programming rock-stardom out of you. Since this is your first job, he most likely hired you because he saw the potential to become a good coder in you. So if you really want to impress him, learn. Learn the language, learn the system you're working on, learn the ins and outs and dark corners. Focus on learning correct principles, learning them well and learning them quickly, in that order.\nAnd remember that part of learning is copying knowledge that other people already have. Don't be afraid to ask questions, either of your coworkers or on StackOverflow, or research things on Google. Whatever you do, don't pretend you know something when you really don't, in an effort to avoid seeming dumb. Any good developer will notice quickly, and that will make you look even stupider in their eyes. Humility tends to still be considered a virtue among engineers.\nDo a good job at that and it'll impress the boss." } ]
[ { "from": "human", "value": "Can I pass variables to a GNU Makefile as command line arguments? In other words, I want to pass some arguments which will eventually become variables in the Makefile." }, { "from": "gpt", "value": "You have several options to set up variables from outside your makefile:\n\n* From environment - each environment variable is transformed into a makefile variable with the same name and value.\nYou may also want to set ```-e``` option (aka ```--environments-override```) on, and your environment variables will override assignments made into makefile (unless these assignments themselves use the ```override``` directive . However, it's not recommended, and it's much better and flexible to use ```?=``` assignment (the conditional variable assignment operator, it only has an effect if the variable is not yet defined):\n```FOO?=default_value_if_not_set_in_environment\n```\nNote that certain variables are not inherited from environment:\n\n* ```MAKE``` is gotten from name of the script\n* ```SHELL``` is either set within a makefile, or defaults to ```/bin/sh``` (rationale: commands are specified within the makefile, and they're shell-specific).\n\n* From command line - ```make``` can take variable assignments as part of his command line, mingled with targets:\n```make target FOO=bar\n```\nBut then all assignments to ```FOO``` variable within the makefile will be ignored unless you use the ```override``` directive in assignment. (The effect is the same as with ```-e``` option for environment variables).\n* Exporting from the parent Make - if you call Make from a Makefile, you usually shouldn't explicitly write variable assignments like this:\n```# Don't do this!\ntarget:\n $(MAKE) -C target CC=$(CC) CFLAGS=$(CFLAGS)\n```\nInstead, better solution might be to export these variables. Exporting a variable makes it into the environment of every shell invocation, and Make calls from these commands pick these environment variable as specified above.\n```# Do like this\nCFLAGS=-g\nexport CFLAGS\ntarget:\n $(MAKE) -C target\n```\nYou can also export all variables by using ```export``` without arguments." } ]
[ { "from": "human", "value": "I have noticed that some games quote the requirement for \"pixel shader 3.0 or better\". \nWhat is a pixel shader and is it some software requirements or hardware requirements?" }, { "from": "gpt", "value": "Simple answer\nPixel shaders are tiny programs that can do operations on a single pixel on the screen, as opposed to geometry shaders and vertex shaders which work on the geometrical primitives (triangles) that make up everything you see on the screen. The most common use for pixel shaders is 'shading', approximation to real world lighting. Commonly used shading model is Phong.\nPixel shaders are executed on your video card, so your video card needs to support them. Each new version provides more capabilities, so an older video card will not run newer shaders. A new version of the pixel shader specification (e.g. Pixel Shader 3.0) is usually released for each new version of DirectX (more accurately, Direct3D).\nSoftware Requirements\nYou need to have the correct version of Direct3D (or OpenGL) installed in order to use the shaders. For example, Pixel Shader 4.0 requires at least Direct3D 10. Normally you don't have to worry about this, every game that uses Direct3D will install the correct version for you when you install the game. The only exceptions are Direct3D 10 and later, which will not run on Windows XP or earlier. You will need at least Windows Vista in order to play a game that uses Direct3D 10 or 11.\nWikipedia provides a nice list of Pixel Shader versions, the version of Direct3D you need, and the types of graphics cards that work with them.\n\nTechnical answer\nThe 'standard' stages of a 3D rendering pipeline are as follows (somewhat simplified):\n\n* Transformation (Moving, rotating and scaling all the objects in the scene)\n* Lighting\n* Projection ('Squashing' the 3D world into a 2D plane)\n* Clipping (Removing anything outside the field of view)\n* Rasterising (Converting the vector graphics (triangles, etc) into raster graphics (pixels))\n* Texturing\n* Display\n\nPixel Shaders are used as an alternative to the standard texturing phase. During rasterisation, each triangle is converted into pixels. These pixels do not have their final colour yet, but the do have a bunch of parameters associated with them. These include base colour, texture coordinates, lighting information, etc. The Pixel Shader is a small program that takes these parameters and uses them to calculate the final colour as it is displayed on the screen. The Pixel Shader has access to all texture data, and can use them to do interesting things such as blending two textures (to create a 'dirty' look), using a texture as a bump map (to simulate a relief), or to simulate reflections.\nHardware\nOn the hardware side, Pixel Shaders are executed on 'Shader Units', small processors on your GPU. Each Shader Unit is basically a very simple CPU, but a modern video card may contain thousands of these things (an AMD Radeon HD6990 contains over 3000). Older GPUs had different Shader Units for different tasks: Pixel Shaders were executed on different parts of the system than Vertex Shaders. Modern GPUs have so called 'unified shader units' which can perform all of these operations." } ]
[ { "from": "human", "value": "Red light facing forwards? It was nighttime in Manhattan. Isn't more always better when it comes to being seen?" }, { "from": "gpt", "value": "No. You should always ride with a white light facing forward and a red light facing backwards. If you want additional illumination, you can add multiple white/red lights in the appropriate direction. Amber/yellow lights can be used facing any direction for additional visibility. \nThe first reason is that it's the law:\n\n (a) Every bicycle when in use during the period from one-half hour after sunset to one-half hour before sunrise shall be equipped with a lamp on the front which shall emit a white light visible during hours of darkness from a distance of at least five hundred feet to the front and with a red or amber light visible to the rear for three hundred feet. Effective July first, nineteen hundred seventy-six, at least one of these lights shall be visible for two hundred feet from each side.\n\nMore importantly for your safety though, the color of a light conveys a certain meaning. Drivers, pedestrians, and other cyclists associate the color red with a taillight and the color white with a headlight. If you put the wrong color facing the wrong direction, people may think you are traveling the opposite direction. Imagine a car is pulling out of a driveway and sees a red bike light flashing to their left. They may assume that means a bike is moving away from them on the left. If they then pull out of the driveway and you're really moving towards them, you could get hit. " } ]
[ { "from": "human", "value": "If water is not a good conductor, why are we advised to avoid water near electricity (no wet hands near circuits etc.)?" }, { "from": "gpt", "value": "&quot;Pure&quot; water is a very poor conductor (resistivity is actually used as a measure of purity).\n&quot;Real&quot; water is not pure - it contains electrolytes and is quite conductive. Also - when your skin is wet, its resistivity is significantly lower.\nFor example - &quot;pure&quot; water has a resistivity of (about) 18.2 M$\\Omega\\cdot\\rm{cm}$. With 10 ppm of dissolved NaCl (&quot;very good quality tap water&quot; would have less than 50 ppm), the resistivity drops to about $43~\\rm{k\\Omega\\cdot cm}$\n\nA lot of detail can be found in &quot;Conduction of Electrical Current to and Through the Human Body: A Review&quot; (Fish and Geddes, ePlasty 2009, 9, e44). \n\n> Why immersion in water can be fatal with very low voltages\n* Immersion wets the skin very effectively and great lowers skin resistance per unit area\n* Contact area is a large percentage of the entire body surface area\n* Electric current may also enter the body through mucous membranes, such as the mouth and throat\n* The human body is very sensitive to electricity. Very small amounts of current can cause loss of ability to swim, respiratory arrest and cardiac arrest" } ]
[ { "from": "human", "value": "What is the difference between cohesion and coupling?\nHow can coupling and cohesion lead to either good or poor software design?\nWhat are some examples that outline the difference between the two, and their impact on overall code quality?" }, { "from": "gpt", "value": "Cohesion refers to what the class (or module) can do. Low cohesion would mean that the class does a great variety of actions - it is broad, unfocused on what it should do. High cohesion means that the class is focused on what it should be doing, i.e. only methods relating to the intention of the class.\nExample of Low Cohesion:\n```-------------------\n| Staff |\n-------------------\n| checkEmail() |\n| sendEmail() |\n| emailValidate() |\n| PrintLetter() |\n-------------------\n```\nExample of High Cohesion:\n```----------------------------\n| Staff |\n----------------------------\n| -salary |\n| -emailAddr |\n----------------------------\n| setSalary(newSalary) |\n| getSalary() |\n| setEmailAddr(newEmail) |\n| getEmailAddr() |\n----------------------------\n```\nAs for coupling, it refers to how related or dependent two classes/modules are toward each other. For low coupled classes, changing something major in one class should not affect the other. High coupling would make it difficult to change and maintain your code; since classes are closely knit together, making a change could require an entire system revamp.\nGood software design has ***high cohesion*** and ***low coupling***." } ]
[ { "from": "human", "value": "Can Romex (NM-B) cable be run through conduit?" }, { "from": "gpt", "value": "Yes, NM (Romex) cable can be in conduit. In fact, National Electrical Code (NEC() calls for it to be in conduit, when protection from physical damage is required. But it really isn't worth it.\n\n## It's a nightmare to pull\nNM (Romex) is already solid wire except in the large sizes, and now you have 3-4 wires bound together. You are trying to pull this around maybe 14\" radius elbows, and if the NM gets twists in it (it always does), it really drags in those places. It's just a stiff, miserable pull - enough to \"put you off conduit forever\" - which is a shame, because conduit is wonderful when using easy-to-pull stranded wire.\n\nPulling this stiff cable increases the risk of damaging the cable. What's more, \"cable in conduit\" is often a newbie who chooses cable simply because he is unaware that wire comes in any other forms. Which leads to more risk of damage still.\n\n## It requires ridiculously large conduit\nYou still have to calculate and respect conduit fill rules, and those are very punishing toward cable. Most cable is oblong, and the rules say you use the largest dimension and treat it as a circular wire of that dimension.\n\n* For a single \"wire\", you are allowed 53% conduit fill. That means the conduit ID must be at least 137% of the large cross-section of the cable. That's not so bad, but...\n* For two \"wires\", you're only allowed 31% fill. That's to protect the wires from binding. That means the conduit ID must be at least 2.54 times the cable large dimension.\n* For three \"wires\", you're allowed 40% fill. That means the conduit must be at least 2.74 times the cable width (at 3 wires), larger for more wires.\n\nFor instance, someone wanted to squeeze three #6 cables through a 1\" conduit. Now this is \"easy peasy\" with 6 individual #6 THHN wires and 3 bare #10 grounds. However, with three #6 UF cables, the conduit size needed to be 3\" instead of 1\". Whoa.\n\nYou are certainly allowed to do it, but you will be using rather enormous conduit, and you will have a hard time pulling." } ]
[ { "from": "human", "value": "Let's say I have a function which takes an ```std::function```:\n```void callFunction(std::function x)\n{\n x();\n}\n```\nShould I pass ```x``` by const-reference instead?:\n```void callFunction(const std::function& x)\n{\n x();\n}\n```\nDoes the answer to this question change depending on what the function does with it? For example if it is a class member function or constructor which stores or initializes the ```std::function``` into a member variable." }, { "from": "gpt", "value": "If you want performance, pass by value if you are storing it.\n\nSuppose you have a function called \"run this in the UI thread\".\n```std::future run_in_ui_thread( std::function )\n```\nwhich runs some code in the \"ui\" thread, then signals the ```future``` when done. (Useful in UI frameworks where the UI thread is where you are supposed to mess with UI elements)\nWe have two signatures we are considering:\n```std::future run_in_ui_thread( std::function ) // (A)\nstd::future run_in_ui_thread( std::function const& ) // (B)\n```\n\nNow, we are likely to use these as follows:\n```run_in_ui_thread( [=]{\n // code goes here\n} ).wait();\n```\nwhich will create an anonymous closure (a lambda), construct a ```std::function``` out of it, pass it to the ```run_in_ui_thread``` function, then wait for it to finish running in the main thread.\nIn case (A), the ```std::function``` is directly constructed from our lambda, which is then used within the ```run_in_ui_thread```. The lambda is ```move```d into the ```std::function```, so any movable state is efficiently carried into it.\nIn the second case, a temporary ```std::function``` is created, the lambda is ```move```d into it, then that temporary ```std::function``` is used by reference within the ```run_in_ui_thread```.\nSo far, so good -- the two of them perform identically. Except the ```run_in_ui_thread``` is going to make a copy of its function argument to send to the ui thread to execute! (it will return before it is done with it, so it cannot just use a reference to it). For case (A), we simply ```move``` the ```std::function``` into its long-term storage. In case (B), we are forced to copy the ```std::function```.\nThat store makes passing by value more optimal. If there is any possibility you are storing a copy of the ```std::function```, pass by value. Otherwise, either way is roughly equivalent: the only downside to by-value is if you are taking the same bulky ```std::function``` and having one sub method after another use it. Barring that, a ```move``` will be as efficient as a ```const&```.\nNow, there are some other differences between the two that mostly kick in if we have persistent state within the ```std::function```.\nAssume that the ```std::function``` stores some object with a ```operator() const```, but it also has some ```mutable``` data members which it modifies (how rude!).\nIn the ```std::function const&``` case, the ```mutable``` data members modified will propagate out of the function call. In the ```std::function``` case, they won't.\nThis is a relatively strange corner case.\nYou want to treat ```std::function``` like you would any other possibly heavy-weight, cheaply movable type. Moving is cheap, copying can be expensive." } ]
[ { "from": "human", "value": "I have an Eloquent model which has a related model:\n```public function option() {\n return $this->hasOne('RepairOption', 'repair_item_id');\n}\npublic function setOptionArrayAttribute($values)\n{\n $this->option->update($values);\n}\n```\nWhen I create the model, it does not necessarily have a related model. When I update it, I might add an option, or not.\nSo I need to check if the related model exists, to either update it, or create it, respectively:\n```$model = RepairItem::find($id);\nif (Input::has('option')) {\n if () {\n $option = new RepairOption(Input::get('option'));\n $option->repairItem()->associate($model);\n $option->save();\n $model->fill(Input::except('option');\n } else {\n $model->update(Input::all());\n }\n};\n```\nWhere `````` is the code I am looking for." }, { "from": "gpt", "value": "A Relation object passes unknown method calls through to an Eloquent query Builder, which is set up to only select the related objects. That Builder in turn passes unknown method calls through to its underlying query Builder.\nThis means you can use the ```exists()``` or ```count()``` methods directly from a relation object:\n```$model->relation()->exists(); // bool: true if there is at least one row\n$model->relation()->count(); // int: number of related rows\n```\nNote the parentheses after ```relation```: ```->relation()``` is a function call (getting the relation object), as opposed to ```->relation``` which a magic property getter set up for you by Laravel (getting the related object/objects).\nUsing the ```count``` method on the relation object (that is, using the parentheses) will be much faster than doing ```$model->relation->count()``` or ```count($model->relation)``` (unless the relation has already been eager-loaded) since it runs a count query rather than pulling all of the data for any related objects from the database, just to count them. Likewise, using ```exists``` doesn't need to pull model data either.\nBoth ```exists()``` and ```count()``` work on all relation types I've tried, so at least ```belongsTo```, ```hasOne```, ```hasMany```, and ```belongsToMany```." } ]
[ { "from": "human", "value": "NASA is hiring a new 'planetary protection officer' to defend Earth from alien matter, and the pay is a six-figure salary: as much as $187,000 a year.\nWhen we are not sure whether aliens exist, why are we still hiring staff for protecting Earth? I do understand we have to take precautions. But when we don't have any proof why spend $187,000 a year?\nSource: Nasa [sic] hiring new 'planetary protection officer' to defend Earth from alien matter - Times of India, Aug 3, 2017" }, { "from": "gpt", "value": "You're observing shamefully bad journalism. The &quot;protect Earth from aliens&quot; bullet point in the &quot;Highlights&quot; section of the article was put there by an editor who either ignorantly or willfully distorted the actual role of the Planetary Protection Officer.\nThe first paragraph of the story gets a little closer:\n\nThe full-time role of &quot;planetary protection officer&quot; will involve ensuring that humans in space do not contaminate planets and moons, as well as ensuring that alien matter does not infect Earth.\n\n&quot;Planetary Protection Officer&quot; isn't a new position; the current one is retiring. The primary focus of the planetary protection office is sterilizing probes that are going to other planets and moons. This is done both to preserve any existing life elsewhere in the solar system from Terran competition, and so that if and when we find life on other bodies, we will know we didn't bring it ourselves.\nPreventing microbes from other worlds reaching Earth is also a concern, for similar reasons.\nDeveloping and implementing the policies of the planetary protection office is a complex job requiring a broad array of both technical and human skills, and so a $187K salary is not remarkable for it:\n\nCandidates will be required to travel frequently — but like any job, there will be a significant amount of emails, proposals and other reading.\nCandidates must have at least one year's experience as a top-level civilian government employee, and an advanced degree in physical science, engineering or mathematics. They must also have &quot;advanced knowledge&quot; of planetary protection.\nThe position also requires &quot;demonstrated skills in diplomacy that resulted in win-win solutions during extremely difficult and complex multilateral discussions&quot;. The new hire will also receive &quot;secret&quot; security clearance. Only US citizens and US nationals can apply.\n" } ]
[ { "from": "human", "value": "Traditional advice for making megadungeons in older versions of D&D is in addition to any rooms with Monsters, Treasure, Traps, or \"Tricks\", there should also be at least 50 to 60 percent \"Empty\" rooms, which contain nothing overtly threatening or valuable. Now, there's several arguments for including these empty rooms that I buy, so I'm not going to accept any answer which primarily says, \"Don't include empty rooms\". The main issue I run into with empty rooms, however, is that they're boring in the way that I've been including them. They don't do their job of increasing tension, and the set dressing included around them hasn't been sufficiently interesting to my players either. My question is this: How can I make empty rooms interesting, by increasing tension or simply being interesting in and of themselves?" }, { "from": "gpt", "value": "By definition, nothing's going to happen in an empty room (though see below). There are no hidden doors to find, no puzzles to solve, no enemies to fight. So what's their purpose?\n\n## Bringing the dungeon to life\nWhile all the orcs may sit around in a guard room waiting for PCs to show up, where do they sleep, what do they eat, what happens to their trash? Think of a dungeon not just as a place to have fights in, but as an actual place that serves a purpose. Once you do, the dungeon will start making sense. &quot;Empty&quot; rooms will increase immersion for the players, and force you to consider things you may not have otherwise. Should there be a pet otyugh that eats the trash? Are the orcs demanding cows from the local farmers for &quot;protection&quot;? Do they keep a famed halfling cook enslaved, to make them rare steaks?\n\n## Foreshadowing\nOnce the dungeon makes sense, you can use that to place clues for things that dwell deeper within. Has a horde of zombies marched through to guard the necromancer's abode within, and left a few rotten body parts here and there? Has a malevolent force been summoned and spoiled all the meat and milk in the dungeon? Is there a golem maintenance station, with oil to grease them, rags to polish them, and a mad goblin mechanic? These may be vital clues PCs need to prepare for a tough fight, or they can simply let them form theories and feel smart about being right once they do come upon a golem or three.\n\n#Currently empty\nThese rooms are empty now, but they don't have to stay that way. PCs may choose to fortify a room and bring the enemy to them - such tactical choices could be an important part of dungeoncrawling. Orcs may chase PCs through the dungeon, or randomly come across them in a kitchen because they were feeling peckish.\nNote that some of these ideas would introduce creatures or things into rooms that PCs may choose to interact with, which would make them non-empty. In a way that's fine: you started with an empty room but found something interesting to put inside after all. If that's not your intention, well, don't put goblins or halflings or otyughs in. Stick to body parts and greasy pots and shadowy portraits and bloodstains and scent of brimstone and fresh flowers and broken mirrors and...\n\nTell a story with your empty rooms, or offer tactical choices. Preferably both." } ]
[ { "from": "human", "value": "Laravel - Eloquent \"Has\", \"With\", \"WhereHas\" - What do they mean? explain in the context of an example" }, { "from": "gpt", "value": "With\n```with()``` is for eager loading. That basically means, along the main model, Laravel will preload the relationship(s) you specify. This is especially helpful if you have a collection of models and you want to load a relation for all of them. Because with eager loading you run only one additional DB query instead of one for every model in the collection.\nExample:\n```User > hasMany > Post```\n```$users = User::with('posts')->get();\nforeach($users as $user){\n $users->posts; // posts is already loaded and no additional DB query is run\n}\n```\n\nHas\n```has()``` is to filter the selecting model based on a relationship. So it acts very similarly to a normal WHERE condition. If you just use ```has('relation')``` that means you only want to get the models that have at least one related model in this relation.\nExample:\n```User > hasMany > Post```\n```$users = User::has('posts')->get();\n// only users that have at least one post are contained in the collection\n```\n\nWhereHas\n```whereHas()``` works basically the same as ```has()``` but allows you to specify additional filters for the related model to check.\nExample:\n```User > hasMany > Post```\n```$users = User::whereHas('posts', function($q){\n $q->where('created_at', '>=', '2015-01-01 00:00:00');\n})->get();\n// only users that have posts from 2015 on forward are returned\n```" } ]
[ { "from": "human", "value": "What are some of the advantages of using one over the other?" }, { "from": "gpt", "value": "ASP.NET Web Forms and MVC are two web frameworks developed by Microsoft - they are both good choices. Neither of the web frameworks are to be replaced by the other nor are there plans to have them 'merged' into a single framework. Continued support and development are done in parallel by Microsoft and neither will be 'going away'.\nEach of these web frameworks offers advantages/disadvantages - some of which need to be considered when developing a web application. A web application can be developed using either technology - it might make development for a particular application easier selecting one technology versus the other and vice versa.\nASP.NET Web Forms:\n\n* Development supports state\n• Gives the illusion that a web application is aware of what the user has been doing, similar to Windows applications. I.e. Makes 'wizard' functionality a little bit easier to implement. Web forms does a great job at hiding a lot of that complexity from the developer.\n* Rapid Application Development (RAD)\n• The ability to just 'jump in' and start delivering web forms. This is disputed by some of the MVC community, but pushed by Microsoft. In the end, it comes down to the level of expertise of the developer and what they are comfortable with. The web forms model probably has less of a learning curve to less experienced developers.\n* Larger control toolbox\n• ASP.NET Web Forms offers a much greater and more robust toolbox (web controls) whereas MVC offers a more primitive control set relying more on rich client-side controls via jQuery (Javascript).\n* Mature\n• It's been around since 2002 and there is an abundance of information with regards to questions, problems, etc. Offers more third-party control - need to consider your existing toolkits.\n\nASP.NET MVC:\n\n* Separation of concerns (SoC)\n• From a technical standpoint, the organization of code within MVC is very clean, organized and granular, making it easier (hopefully) for a web application to scale in terms of functionality. Promotes great design from a development standpoint.\n* Easier integration with client side tools (rich user interface tools)\n• More than ever, web applications are increasingly becoming as rich as the applications you see on your desktops. With MVC, it gives you the ability to integrate with such toolkits (such as jQuery) with greater ease and more seamless than in Web Forms.\n* Search Engine Optimization (SEO) Friendly / Stateless\n• URL's are more friendly to search engines (i.e. mywebapplication.com/users/ 1 - retrieve user with an ID of 1 vs mywebapplication/users/getuser.aspx (id passed in session)). Similarly, since MVC is stateless, this removes the headache of users who spawn multiple web browsers from the same window (session collisions). Along those same lines, MVC adheres to the stateless web protocol rather than 'battling' against it.\n* Works well with developers who need high degree of control\n• Many controls in ASP.NET web forms automatically generate much of the raw HTML you see when an page is rendered. This can cause headaches for developers. With MVC, it lends itself better towards having complete control with what is rendered and there are no surprises. Even more important, is that the HTML forms typically are much smaller than the Web forms which can equate to a performance boost - something to seriously consider.\n* Test Driven Development (TDD)\n• With MVC, you can more easily create tests for the web side of things. An additional layer of testing will provide yet another layer of defense against unexpected behavior.\n\nAuthentication, authorization, configuration, compilation and deployment are all features that are shared between the two web frameworks." } ]
[ { "from": "human", "value": "What factors determine the maximum altitude for a plane?\nIs it limited by wing design, engine thrust, and so on?\nIs there a formula by which one can calculate the maximum altitude a plane can reach?" }, { "from": "gpt", "value": "The higher you get, the lower the density of the air becomes. This lower density results in a lower lift being generated for the same airspeed and angle of attack. Effectively, the higher you fly the higher your minimum speed becomes. So while climbing, your speed needs to increase to compensate for the lower air density. As long a you can fly faster, the lower density at altitude can be compensated for. \nBasically there are two things that limit your maximum speed: thrust and speed of sound and with that your maximum altitude.\nFirst is thrust; the higher you get, the lower the thrust your engines deliver. You might note that drag goes down with the air density as well but since you are flying faster and faster during the climb the drag doesn't decrease at all. If your maximum altitude is limited by thrust then at some point during the climb the thrust and drag are getting close to equal and that is where the climb stops. When you can no longer climb with more than 100ft per minute (for propeller aircraft) or 500ft per minute (for jet / turbofan aircraft) you have reached your service ceiling. If the aircraft maximum altitude is determined by thrust, the absolute ceiling will take very long to reach. \nAt high altitudes air breathing engines will get difficulties eventually. Due to the lower air density the mass flow through the engine is reduced up to a point where it causes a flame out. \nThe other limitation is the speed of sound, at least for subsonic aircraft. In the process of generating lift, air flowing over the top of the wing is accelerated. At one point, when the aircraft is still flying below the speed of sound, shock waves will start to form over the wing. This results in increase of drag and reduces the lift. So provided you have enough engine power at your disposal you can climb to an altitude where your minimum speed is also your maximum speed. This is called the coffin corner. In the coffin corner:\n\n* if you fly any faster, you will exceed the maximum Mach number ($M_{mo}$) of your aircraft, resulting in high speed buffet, vibrations and possible loss of control. \n* if you fly any slower, the maximum lift that the wing can provide will be insufficient to maintain altitude. Descent or the aircraft will stall. \n* if you fly any higher and you will be too fast and too slow at the same time. \n* if you turn, you increase the wing loading, thereby increasing the minimum speed needed to create the required lift. Also the outer wing will easily exceed the maximum speed while at the same time the inner wing is below stall speed. This can quickly develop into a spin. \n\nSince accurate knowledge of engine performance, drag and wing characteristics of the aircraft is needed, there is not a simple formula to derive the maximum altitude for an aircraft. \n\nApart from the aircraft performance related limitations above there is a certified maximum operating altitude for the pressurized cabin. This takes into account the structural properties of the hull (pressure difference between inside and outside) and the achievable emergency descent rate in case of a depressurization event." } ]
[ { "from": "human", "value": "Why did the Typescript folks create the ```infer``` keyword?\nAccording to the documents, this is an example of how you would use it:\n```type ReturnType = T extends (...args: any[]) => infer R ? R : any;\n```\nI don't understand why this is needed. Why can't it just be:\n```type ReturnType = T extends (...args: any[]) => R ? R : any;\n```\nWhy doesn't this work? Why is the ```infer``` keyword necessary ?" }, { "from": "gpt", "value": "With ```infer```, the compiler ensures that you have declared all type variables explicitly:\n```type MyType = T extends infer R ? R : never;\ntype T1 = MyType // T1 is { b: string; }\n```\nHere we declare a new type variable ```R``` in ```MyType```, which gets inferred from ```T```.\n(Note, that ```infer``` is always used within the ```extends``` clause of a conditional type.)\nUsage of undeclared type parameters now can result in a compile error:\n```type MyType2 = T extends R2 ? R2 : never; // error, R2 undeclared\n```\nWithout ```infer```, the compiler wouldn't know, if you wanted to introduce an additional type variable ```R2``` that is to be inferred (see first case), or if ```R2``` is just an accidental typing error/typo. ```infer``` exists to remove this ambiguity.\nMore precisely the compiler checks, if ```T``` is assignable to ```R``` , when ```infer``` is omitted:\n```type R = { a: number }\ntype MyType3 = T extends R ? R : never; // compare T with type R\ntype T3 = MyType3 // T3 is never\n```\nNote, that ```infer R``` shadows type references of an equally-named type declaration ```R```:\n```type R = { a: number }\ntype MyType4 = T extends infer R ? R : never;\ntype T4 = MyType4 // { b: string; }\n```" } ]
[ { "from": "human", "value": "Which is more widely supported: ```window.onload``` or ```document.onload```?" }, { "from": "gpt", "value": "When do they fire?\n```window.onload```\n\n* By default, it is fired when the entire page loads, including its content (images, CSS, scripts, etc.).\n\nIn some browsers it now takes over the role of ```document.onload``` and fires when the DOM is ready as well.\n```document.onload```\n\n* It is called when the DOM is ready which can be prior to images and other external content is loaded.\n\nHow well are they supported?\n```window.onload``` appears to be the most widely supported. In fact, some of the most modern browsers have in a sense replaced ```document.onload``` with ```window.onload```.\nBrowser support issues are most likely the reason why many people are starting to use libraries such as jQuery to handle the checking for the document being ready, like so:\n```$(document).ready(function() { /* code here */ });\n$(function() { /* code here */ });\n```\n\nFor the purpose of history. ```window.onload``` vs ```body.onload```:\n\n A similar question was asked on codingforums a while\n back regarding the usage of ```window.onload``` over ```body.onload```. The\n result seemed to be that you should use ```window.onload``` because it is\n good to separate your structure from the action.\n" } ]
[ { "from": "human", "value": "I was surprised to learn that Puerto Ricans, despite living in a US territory, were not entitled to vote in the presidential elections.\nI was even more surprised to learn that US citizens are allowed to vote for president from anywhere in the world - EXCEPT if they happen to live in Puerto Rico.\nWhat is the legal/political rationale behind this? What is it about Puerto Rico that magically removes one's right to vote? Has anyone ever challenged this?" }, { "from": "gpt", "value": "This is a peculiarity as a result of the federal nature of the USA and the exceptional position of Puerto Rico as a territory but not a state. Within the States and Territories of the USA, your voting rights depend on residence. If you leave the States and Territories your voting rights depend on former residence or inheritance.\n\nIn general most citizens of the USA are also citizens of a state of the USA. Since states don't issue their own passports, your citizenship of a state is determined by residence. If a New Yorker moves to Florida, they become Floridians, and so can vote in state elections in Florida, but can't now vote in elections in New York.\n\nNow if our New Yorker moves to Timbuktu, this is treated slightly differently. They remain a US citizen and a citizen of New York, and so retain the right to vote in New York elections. Their children could also claim New York citizenship.\n\nBut Puerto Rico is both part of the USA but not a State or part of a State of the USA. When our New Yorker moves to Puerto Rico, they can vote in Puerto Rican elections but not elections in New York.\n\nNow the nature of elections in the US is that there are no national elections There are statewide elections of Senators, Governors and Presidential electors. There are district elections of Representatives and there are local elections of many kinds. Our New Yorker has lost the right to vote in New York elections (just as they would have done if they had moved to Florida) but not gained the right to vote in Puerto Rican elections for Presidential electors (because there are none).\n\nThis is odd, but something similar is true if the New Yorker moves to DC. They cease to have the right to vote in elections to the Senate." } ]