text
stringlengths
171
13.9k
### BEGIN CONVERSATION ### ## Human: ## Reasons why healthy people would intentionally want to get infected? ## Assistant: ## Because some self-proclaimed health guru claims that it's good for you to have that disease. The miracle-virus causes your body to absorb free cosmic energies. Your constantly raising body temperature is proof that it works. The 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. The 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. The 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. All 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. Sounds ridiculous? Then you might want to take a look at the community of people drinking bleach. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. When 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. However, 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? ## Assistant: ## 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? No. Detonating a modern nuclear device is, in fact, incredibly difficult and merely shooting down the aircraft carrying it would not be sufficient. In fact, several aircraft carrying older nuclear devices have either crashed or otherwise been lost without the device on board detonating. It's likely that the crash might cause a release of nuclear material but detonation is practically impossible. In 1966... ...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. The 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. Washington Post 1964 In 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 ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Since I created my repository it appears that the tags I have been creating are not pushed to the repository. When I do ```git tag``` on the local directory all the tags are present, but when I logon to the remote repository and do a ```git tag```, only the first few show up. What could the problem be?. ## Assistant: ## 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 ``` $ git push <remote> tag <tagname> ``` to push a single tag, ``` $ git push <remote> --tags ``` to push all tags (or ```git push --tags``` to push to default remote, usually ```origin```). This is very much intended behavior, to make pushing tags explicit. Pushing tags should be usually conscious choice. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## How do I add Git submodule to a sub-directory? ## Assistant: ## You go into ~/.janus and run: ```git submodule add <git@github ...> snipmate-snippets/snippets/``` If you need more information about submodules (or git in general) ProGit is pretty useful. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## These are a few extra points to complement Andrew Rosen's comprehensive response: * 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. * 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. * 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I don't really get the difference between gain and volume boost. So 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. Would this mean, in most settings, getting 'close to' as much gain as possible without any hiss/background noise is ideal? ## Assistant: ## Here's a brief overview to get you started. Hopefully this helps! * '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. * '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. A 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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: For example, you have an Ace, King, Queen, Jack, and Ten. You call your hand and say, &quot;I have a Straight!&quot; But 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. Your hand has not been determined until you call your hand. Is 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. Or would it depend on the specific poker variation/house rules? ## Assistant: ## 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. Some 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. There 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. Finally, 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## How to get the first item from an associative PHP array? ## Assistant: ## PHP If 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. So it would be best to check, especially if there is the chance that the returned value might be the boolean FALSE: ```$value = empty($arr) ? $default : reset($arr); ``` The 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: ```$value = $default; foreach(array_slice($arr, 0, 1) as $value); ``` Assuming you want to get both the key and the value separately, you need to add the fourth parameter to ```array_slice```: ```foreach(array_slice($arr, 0, 1, true) as $key => $value); ``` To get the first item as a pair (```key => value```): ```$item = array_slice($arr, 0, 1, true); ``` Simple modification to get the last item, key and value separately: ```foreach(array_slice($arr, -1, 1, true) as $key => $value); ``` performance If 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: ```$key = count($arr) ? array_keys($arr)[0] : null; ``` If 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). A 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. PHP 7.3+ PHP 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. So since PHP 7.3 the first value of ```$array``` may be accessed with ```$array[array_key_first($array)]; ``` You still had better check that the array is not empty though, or you will get an error: ```$firstKey = array_key_first($array); if (null === $firstKey) { $value = &quot;Array is empty&quot;; // An error should be handled here } else { $value = $array[$firstKey]; } ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why do people write #!/usr/bin/env python on the first line of a Python script? ## Assistant: ## In order to run the python script, we need to tell the shell three things: * That the file is a script * Which interpreter we want to execute the script * The path of said interpreter The 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. The ```env``` command accomplishes (2.) and (3.). To quote &quot;grawity,&quot; > 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... > 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.) ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## > Did every programmer of every game implemented all possible various API's that old graphic cards supported? Yes - 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. Instead, 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. There 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. An 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why is it "behead" and not "dehead"? ## Assistant: ## 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. So 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. There 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: Forming trans. verbs on substantives used in an instrumental relation; the primary idea being; * a. To surround, cover, or bedaub with, as in becloud, to put clouds about, cover with clouds, bedew. Thence, by extension, * 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. * 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. Although 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. El destierro Apropos 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. Truly, el Cid was belanded of his lands by the King. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. ## Assistant: ## 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. At 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. The 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. So, 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. Purists 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## There was a deleted scene that explained it: 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. Basically, there were 2 rules about the Ark not mentioned in the final cut of the film: * If you touch the Ark, you die * If you look at the Ark when it is opened, you die 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. [Source] 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. [Source] Notice that nobody ever touches the Ark throughout the rest of the film until the finale. And from the Bible (King James Version): 1 Samuel 6:19: 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... 2 Samuel 6:6-7 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## It depends on the router/switch. If 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. (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) If 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. The 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". This 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. Basically, 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. If 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What command do I use to find the size of all the files (recursively) in a Linux or Mac OS X directory? ## Assistant: ## 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. Here's an example. This is the value with regular ```du```. It's in 512-byte blocks: ```$ du -s 248 . ``` The ```-h``` flag results in a more readable number, in kilobytes. As expected, it's half the number of 512-byte blocks: ```$ du -hs 124K . ``` Finally, 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: ```$ find . -type f -exec ls -l {} \; | awk '{sum += $5} END {print sum}' 60527 ``` This 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```. Here'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. The 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why don't toilets use saltwater? ## Assistant: ## 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. A 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). It 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. Additionally, 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## How do I modify fields inside the new PostgreSQL JSON datatype? ## Assistant: ## With Postgresql 9.5 it can be done by following- ```UPDATE test SET data = data - 'a' || '{"a":5}' WHERE data->>'b' = '2'; ``` OR ```UPDATE test SET data = jsonb_set(data, '{a}', '5'::jsonb); ``` Somebody asked how to update many fields in jsonb value at once. Suppose we create a table: ```CREATE TABLE testjsonb ( id SERIAL PRIMARY KEY, object JSONB ); ``` Then we INSERT a experimental row: ```INSERT INTO testjsonb VALUES (DEFAULT, '{"a":"one", "b":"two", "c":{"c1":"see1","c2":"see2","c3":"see3"}}'); ``` Then we UPDATE the row: ```UPDATE testjsonb SET object = object - 'b' || '{"a":1,"d":4}'; ``` Which does the following: * Updates the a field * Removes the b field * Add the d field Selecting the data: ```SELECT jsonb_pretty(object) FROM testjsonb; ``` Will result in: ``` jsonb_pretty ------------------------- { + "a": 1, + "c": { + "c1": "see1", + "c2": "see2", + "c3": "see3", + }, + "d": 4 + } (1 row) ``` To update field inside, Dont use the concat operator ```||```. Use jsonb_set instead. Which is not simple: ```UPDATE testjsonb SET object = jsonb_set(jsonb_set(object, '{c,c1}','"seeme"'),'{c,c2}','"seehim"'); ``` Using the concat operator for {c,c1} for example: ```UPDATE testjsonb SET object = object || '{"c":{"c1":"seedoctor"}}'; ``` Will remove {c,c2} and {c,c3}. For more power, seek power at postgresql json functions documentation. One might be interested in the ```#-``` operator, ```jsonb_set``` function and also ```jsonb_insert``` function. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. So I get an exception, when I call: ```[mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; ``` Is there another way to scroll to the top of table view? ## Assistant: ## Possible Actions: 1 ```func scrollToFirstRow() { let indexPath = NSIndexPath(forRow: 0, inSection: 0) self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: true) } ``` 2 ```func scrollToLastRow() { let indexPath = NSIndexPath(forRow: objects.count - 1, inSection: 0) self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true) } ``` 3 ```func scrollToSelectedRow() { let selectedRows = self.tableView.indexPathsForSelectedRows if let selectedRow = selectedRows?[0] as? NSIndexPath { self.tableView.scrollToRowAtIndexPath(selectedRow, atScrollPosition: .Middle, animated: true) } } ``` 4 ```func scrollToHeader() { self.tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated: true) } ``` 5 ```func scrollToTop(){ self.tableView.setContentOffset(CGPointMake(0, UIApplication.sharedApplication().statusBarFrame.height ), animated: true) } ``` Disable Scroll To Top: ```func disableScrollsToTopPropertyOnAllSubviewsOf(view: UIView) { for subview in view.subviews { if let scrollView = subview as? UIScrollView { (scrollView as UIScrollView).scrollsToTop = false } self.disableScrollsToTopPropertyOnAllSubviewsOf(subview as UIView) } } ``` Modify and use it as per requirement. Swift 4 ``` func scrollToFirstRow() { let indexPath = IndexPath(row: 0, section: 0) self.tableView.scrollToRow(at: indexPath, at: .top, animated: true) } ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## 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. The main differences: * bokeh is created optically, gaussian blur in post-production; * 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; * in bokeh, the smearing characteristics depend on configuration and aperture shape of the lens, whereas gaussian blur is always smooth; * 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; * 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; * in bokeh, light areas will dominate over dark ones, while gaussian blur gives preserves the ratio of dark-light areas. So, 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why does "elite" rhyme with "beet" rather than "bite"? ## Assistant: ## This has everything to do with the following: * The language of origin of the word and * The point at which the word entered the English language. The 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. However, 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. &quot;Elite&quot; joined the party a little bit late, so its pronunciation remained rather stable. As Rjpond points out, elite is a modern borrowing. Words like crime, sublime, mime, etc. are older borrowings. To 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. Small addendum: Already 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.) You might say that there is some linguistic pressure to avoid creating homophones: elite vs. alight. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. So what is Ray Marching? Some comments suggests that it is a variation of Sphere Tracing. What are the computational advantages of a such approach? ## Assistant: ## ## TL;DR They belong to the same family of solvers, where sphere tracing is one method of ray marching, which is the family name. ## Raymarching a definition Raymarching 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. This can be useful if you: * Need to render volumetrics that arenot uniform * Rendering implicit functions, fractals * Rendering other kinds of parametric surfaces where intersection is not known ahead of time, like paralax mapping etc. ## Sphere tracing Sphere 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. Sphere tracing is used for rendering implicit surfaces. Implicit surfaces are formed at some level of a continuous function. In essence solving the equation ```F(X,Y,Z) = 0 ``` Because 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Is martial arts training 'inadequate' for the real world? ## Assistant: ## Yes, depending on your definitions of martial arts, inadequate, and real world. No, depending on your definitions of martial arts, inadequate, and real world. Surviving 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... There 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. Making general sweeping statements about violence and how to survive it generally indicate either bad research or an agenda. For 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Make a single page landscape in Google Documents ## Assistant: ## 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. It 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. Note 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). A 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. Also, creating multiple Orientations in Word isn't as straight forward as one might want either. For those wanting to do this in Word: Use portrait and landscape orientation in the same document 1. Select the pages or paragraphs that you want to change to portrait or landscape orientation. NOTE: 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. 2. On the Page Layout tab, in the Page Setup group, click Margins. 3. Click Custom Margins. (This is the important part) 4. On the Margins tab, click Portrait or Landscape. 5. In the Apply to list, click Selected text.. NOTE: 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## PHP is writing this error in the logs: "Notice: Use of undefined constant". Error in logs: ```PHP Notice: Use of undefined constant department - assumed 'department' (line 5) PHP Notice: Use of undefined constant name - assumed 'name' (line 6) PHP Notice: Use of undefined constant email - assumed 'email' (line 7) PHP Notice: Use of undefined constant message - assumed 'message' (line 8) ``` Relevant lines of code: ```$department = mysql_real_escape_string($_POST[department]); $name = mysql_real_escape_string($_POST[name]); $email = mysql_real_escape_string($_POST[email]); $message = mysql_real_escape_string($_POST[message]); ``` What does it mean and why am I seeing it? ## Assistant: ## 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. That is, it's trying to interpret this (note the missing quote marks): ```$_POST[department] ``` The 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: ```// Implicit declaration of constant called department with value 'department' define('department', 'department'); ``` There are various ways you can get this error message, but they all have the same root cause - a token that could be a constant. Strings missing quotes: ```$my_array[bad_key]``` This 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: Change: ```$department = mysql_real_escape_string($_POST[department]); ...(etc)... ``` To: ```$department = mysql_real_escape_string($_POST['department']); ...(etc)... ``` Variable missing dollar sign: ```var_without_dollar``` Another 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: ```my_local; // should be $my_local my_member; // should be $this->my_member ``` Invalid character in variable name: ```$bad-variable-name``` A 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. For example, this is OK, since underscores are allowed in variable names: ```if (123 === $my_var) { do_something(); } ``` But this isn't: ```if (123 === $my-var) { do_something(); } ``` It'll be interpreted the same as this: ```if (123 === $my - var) { // variable $my minus constant 'var' do_something(); } ``` Referring to a class constant without specifying the class scope In 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()```. Eg: ```class MyClass { const MY_CONST = 123; public function my_method() { return self::MY_CONST; // This is fine } public function my_method() { return MyClass::MY_CONST; // This is fine } public function my_bad_method() { return MY_CONST; // BUG - need to specify class scope } } ``` Using a constant that's not defined in this version of PHP, or is defined in an extension that's not installed There 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. So if you tried to use this feature in PHP 5.2, say: ```$rounded = round($my_var, 0, PHP_ROUND_HALF_DOWN); ``` You'd get this error message: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' Warning (2): Wrong parameter count for round() ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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! ## Assistant: ## 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. You 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. Your 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. When 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. When 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What are the advantages of studying words by their frequency? ## Assistant: ## 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. According to Nation & Waring (1997), text coverage in the Brown corpus is as follows: * Most frequent 1000 words: 72.0% * Most frequent 2000 words: 79.7% * Most frequent 3000 words: 84.0% * Most frequent 4000 words: 86.8%. So 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. Note 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. Although 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. So 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. Also, 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. ## Assistant: ## 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. Stockfish 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. There 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. Note: 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## How to decrypt Jenkins passwords from credentials.xml? ## Assistant: ## There is a `hudson.util.Secret.decrypt()` function which can be used for this, so: 1. In Jenkins, go to: `/script` page. 2. Run the following command: ```println(hudson.util.Secret.decrypt("{XXX=}")) ``` or ``` println(hudson.util.Secret.fromString("{XXX=}").getPlainText()) ``` where `{XXX=}` is your encrypted password. This will print the plain password. To do the opposite, you can run: ``` println(hudson.util.Secret.fromString("some_text").getEncryptedValue()) ``` Alternatively check the following scripts: `tweksteen/jenkins-decrypt`, `menski/jenkins-decrypt.py`. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? Let's give Yagi an example: Let's say I use 4 different metals for the directors , reflector, and driven element. One 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 Other then the metal variations, the antennas are identical. So, 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. ## Assistant: ## 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: $$ P = I^2 R $$ Any energy you use to make heat is energy you aren't using to make electromagnetic waves. So 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: * Silver: 15.9 * Copper: 16.8 * Gold: 24.4 * Aluminium: 26.2 * Zinc: 59.0 * Nickel: 69.9 * Iron: 100 * Tin: 109 I'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. A 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. There'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. Since 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. Magnetic 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. Yet, 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? ## Assistant: ## For Win16 programs, Windows implemented co-operative multitasking. Its implementation was based upon the &quot;message loop&quot; architecture of every Windows program. The 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```). If 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. If 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). If 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. The 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I'm working on 2 different branches: release and development. I noticed I still need to integrate some changes that were committed to the release branch back into the development branch. The problem is I don't need all of the commit, only some hunks in certain files, so a simple ```git cherry-pick bc66559 ``` does not do the trick. When I do a ```git show bc66559 ``` I can see the diff but don't really know a good way of applying that partially to my current working tree. ## Assistant: ## 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. To use it in combination with cherry-pick: ```git cherry-pick -n # get your patch, but don't commit (-n = --no-commit) git reset # unstage the changes from the cherry-picked commit git add -p # make all your choices (add the changes you do want) git commit # make the commit! ``` ``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.) You can provide specific paths to ```add -p``` if necessary. If you're starting with a patch you could replace the ```cherry-pick``` with ```apply```. If you really want to ```git cherry-pick -p ``` (that option does not exist), you can use ```git checkout -p ``` That 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.) ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. What is the ideal number of cities for a cultural victory? Does it change over time? ## Assistant: ## 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; The short answer is... We know that adding another city increases the culture costs by approximately 30% of the base cost (that of 1 city). Therefore: If 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. (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.) The long answer is... It depends To begin with, we need to make some assumptions: * 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). * 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. * This list of social policy costs is accurate for the given parameters: medium map and normal speed. And now, some math. The 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) This 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). For 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). It is not until the 4th social policy that this trend is broken and diminishing returns end at the NINTH! city. Remember -- this assumes that each city has a monument the minute it is founded. Now let's say we've reached the classical age, and have temples in addition to monuments. Each city is now generating 5 culture. The first policy takes 5 turns with a single city, 4 turns with two, and 3 with three. What (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). So 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. It'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. Given a table name, is it possible to get a list of the names of the columns in that table? For 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. ## Assistant: ## 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. However, 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. The Postgres developers aren't making promises, but basics (like what is needed here) aren't going to change across major versions. More detailed assessment: * Query to output names and data types of a query, table or view ```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. Given one table, is it possible to have a list of the names of the columns for this table. ```SELECT attrelid::regclass AS tbl , attname AS col , atttypid::regtype AS datatype -- more attributes? FROM pg_attribute WHERE attrelid = 'myschema.mytable'::regclass -- table name optionally schema-qualified AND attnum > 0 AND NOT attisdropped ORDER BY attnum; ``` Faster 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. There are also subtle differences in visibility. The following artical has detailed comparison: * How to check if a table exists in a given schema ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I am using Visual Studio Code and have a fairly common project structure: ```├── client/ │ ├── tsconfig.json ├── shared/ ├── server/ │ ├── tsconfig.json ├── project.json ``` The 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. The 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. Note 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. Is the only option to wait for filesGlob? ## Assistant: ## These days it is much easier as vscode has better support for this. You can use this directory structure so all the code is independent: ```├── frontend/ │ ├── src/ │ │ ├── │ ├── package.json │ ├── tsconfig.json ├── shared/ │ ├── package.json ├── backend/ │ ├── src/ │ │ ├── │ ├── package.json │ ├── tsconfig.json ``` Then in both the backend and frontend ```tsconfig.json```: ```{ &quot;compilerOptions&quot;: { &quot;paths&quot;: { &quot;~shared/*&quot;: [&quot;../shared/*&quot;] }, &quot;rootDirs&quot;: [ &quot;./src&quot;, &quot;../shared&quot; ] } } ``` To allow access to the shared code e.g.: ```import { Foo } from '~shared/foo'; ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I have a problem with the embedded bitcode term. What is embedded bitcode? When to enable, ```ENABLE_BITCODE``` in new Xcode? What happens to the binary when enabled, ```ENABLE_BITCODE``` in Xcode 7? ## Assistant: ## > What is embedded bitcode? According to docs: > 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. This 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: 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. However 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. Bitcode 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. > When to enable ENABLE_BITCODE in new Xcode? 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. > What happens to the binary when ENABLE_BITCODE is enabled in the new Xcode? From Xcode 7 reference: > 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. To 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 $$\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. What 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? ## Assistant: ## A general model (with continuous paths) can be written $$ \frac{dS_t}{S_t} = r_t dt + \sigma_t dW_t^S $$ where the short rate $r_t$ and spot volatility $\sigma_t$ are stochastic processes. In 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 $$ C(t,S;T,K) = BS(S,T-t,K;\Sigma(T,K)) $$ where $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)$. In the local volatility model, rates are deterministic, instant volatility is stochastic but there is only one source of randomness $$ \frac{dS_t}{S_t} = r(t) dt + \sigma_{Dup}(t,S_t) dW_t^S $$ this is a special case of the general model with $$ 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 $$ What 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). The 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. This can be seen in several ways: 1. The forward smile. Forward implied volatility is implied from prices of forward start options: ignoring interest rates, $$ 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)) $$ Alternatively, 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. This is because the initial smile you calibrate the model too has decreasing skew: $$ \partial_K \Sigma(0,S;T,K) \xrightarrow[T\to +\infty]{} 0 $$ 2. 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. This is not consistent with what is observed on markets. See Hagan and al. Managing Smile Risk for the derivation. This means that $\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. 3. 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. The 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. There 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## 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. During 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. The 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). ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. What are the minimum general requirements so that we can say something is AI? ## Assistant: ## 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: > 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. Artificial Intelligence: A Modern Approach - Stuart Russell and Peter Norvig So 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 To 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I have some questions regarding the usage and significance of the ```synchronized``` keyword. * What is the significance of the ```synchronized``` keyword? * When should methods be ```synchronized```? * What does it mean programmatically and logically? ## Assistant: ## 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: > ```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. In 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. Again, this is a non-trivial topic in Java. To learn more, explore topics about: * Concurrency * Java Memory Model Keep exploring these topics until the name "Brian Goetz" becomes permanently associated with the term "concurrency" in your brain. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I am using the ```$http``` service of AngularJS to make an Ajax request. How can a spinner GIF (or another type of busy indicator) be shown while the Ajax request is executing? ## Assistant: ## This really depends on your specific use case, but a simple way would follow a pattern like this: ``` .controller('MainCtrl', function ( $scope, myService ) { $scope.loading = true; myService.get().then( function ( response ) { $scope.items = response.data; }, function ( response ) { // TODO: handle the error somehow }).finally(function() { // called no matter success or failure $scope.loading = false; }); }); ``` And then react to it in your template: ``` <div class="spinner" ng-show="loading"></div> <div ng-repeat="item in items>{{item.name}}</div> ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. Do I have any rights over the overhead bin above my seat? Could I ask the flight attendant to remove some of the bags to make room for me? I 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? ## Assistant: ## 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. It 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. In 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. It 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. Boarding 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## 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. Canon 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. In 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. Stepper 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I'm trying to set get id of all elements in an ```HTMLCollectionOf```. I wrote the following code: ```var list = document.getElementsByClassName("events"); console.log(list[0].id); for (key in list) { console.log(key.id); } ``` But I got the following output in console: ```event1 undefined ``` which is not what I expected. Why is the second console output ```undefined``` but the first console output is ```event1```? ## Assistant: ## 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```. So consider the following as an alternative to jfriend00's ```for``` loop: ```var list= document.getElementsByClassName("events"); [].forEach.call(list, function(el) { console.log(el.id); }); ``` There's a good article on MDN that covers this technique. Note their warning about browser compatibility though: [...] passing a host object (like a ```NodeList```) as ```this``` to a native method (such as ```forEach```) is not guaranteed to work in all browsers and is known to fail in some. So while this approach is convenient, a ```for``` loop may be the most browser-compatible solution. Update (Aug 30, 2014): Eventually you'll be able to use ES6 ```for```/```of```! ```var list = document.getElementsByClassName("events"); for (const el of list) console.log(el.id); ``` It's already supported in recent versions of Chrome and Firefox. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I am 21 years old and living in a large city in Germany where smalltalk in local markets is not a common thing. A 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. My 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. ## Assistant: ## Asking her out directly seems like a bad idea. Instead, 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. For example: &quot;I like to grab lunch here before going to [Public Event You Enjoy]&quot; This could be almost anything, but here are some examples: * A place your band plays * A public dance * A painting/pottery class * A wine tasting This 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; If 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; If 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. And 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. ## Assistant: ## As Jo has already shown, this can be accomplished in 28 steps. This is minimal, and it can be proven. To help visualize this problem, we can imagine: 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}. 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. ```1024 3072 9216 ---- ---- ---- ---- ---- ---- ---- ---- .``` ```---- 1536 4608 13824 41472 124416 373248 1119744 3359232 10077696 30233088 .``` ```---- ---- ---- ---- ---- ---- 186624 ---- 1679616 ---- 15116544 .``` ```128 384 1152 3456 10368 31104 93312 ---- ---- ---- ---- .``` ```---- 192 ---- 1728 ---- 15552 46656 139968 419904 1259712 3779136 .``` ```32 96 ---- ---- ---- ---- ---- ---- ---- ---- 1889568 .``` ```16 48 144 432 1296 3888 11664 34992 104976 314928 944784 .``` ```---- ---- ---- ---- ---- 1944 ---- 17496 ---- 157464 472392 .``` ```4 12 36 108 324 972 ---- ---- ---- ---- ---- .``` ```---- ---- 18 ---- 162 486 1458 4374 13122 39366 118098 .``` ```1 3 9 ---- ---- ---- ---- ---- ---- 19683 ---- .``` 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). Proving minimality: 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. 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. With our x-coordinate limited to [0,10], we now look at the bottlenecks. 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. 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. 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## ```oImg.setAttribute('width', '1px'); ``` ```px``` is for CSS only. Use either: ```oImg.width = '1'; ``` to set a width through HTML, or: ```oImg.style.width = '1px'; ``` to set it through CSS. Note 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: ```// IEWIN boolean previously sniffed through eg. conditional comments function img_create(src, alt, title) { var img = IEWIN ? new Image() : document.createElement('img'); img.src = src; if ( alt != null ) img.alt = alt; if ( title != null ) img.title = title; return img; } ``` Also 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)```. To 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why is %s better than + for concatenation in python? ## Assistant: ## There are several benefits of using ```%s``` over ```+``` for string concatenation in Python: * 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```. * 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. * 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## 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. Upper 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. Liquid 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. If 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. Solid 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## How to prevent "Delhi Belly" from eating/drinking locally? ## Assistant: ## Basically, you can't. The world is full of gastrointestinal (GI) diseases, even in developed, First World nations. There are some decent steps to trying to minimize your exposure: * 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. * 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. * 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. * 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. But 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. And if it does happen? Stay hydrated. You're losing salts and water, they need to be replaced. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I'm working at my first programming job. My boss is a very smart software engineer, and I feel like 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. What can I do to impress him? Thank you. ## Assistant: ## 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. If 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. And 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. Do a good job at that and it'll impress the boss. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. ## Assistant: ## You have several options to set up variables from outside your makefile: * From environment - each environment variable is transformed into a makefile variable with the same name and value. You 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): ```FOO?=default_value_if_not_set_in_environment ``` Note that certain variables are not inherited from environment: * ```MAKE``` is gotten from name of the script * ```SHELL``` is either set within a makefile, or defaults to ```/bin/sh``` (rationale: commands are specified within the makefile, and they're shell-specific). * From command line - ```make``` can take variable assignments as part of his command line, mingled with targets: ```make target FOO=bar ``` But 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). * Exporting from the parent Make - if you call Make from a Makefile, you usually shouldn't explicitly write variable assignments like this: ```# Don't do this! target: $(MAKE) -C target CC=$(CC) CFLAGS=$(CFLAGS) ``` Instead, 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. ```# Do like this CFLAGS=-g export CFLAGS target: $(MAKE) -C target ``` You can also export all variables by using ```export``` without arguments. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I have noticed that some games quote the requirement for "pixel shader 3.0 or better". What is a pixel shader and is it some software requirements or hardware requirements? ## Assistant: ## Simple answer Pixel 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. Pixel 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). Software Requirements You 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. Wikipedia provides a nice list of Pixel Shader versions, the version of Direct3D you need, and the types of graphics cards that work with them. Technical answer The 'standard' stages of a 3D rendering pipeline are as follows (somewhat simplified): * Transformation (Moving, rotating and scaling all the objects in the scene) * Lighting * Projection ('Squashing' the 3D world into a 2D plane) * Clipping (Removing anything outside the field of view) * Rasterising (Converting the vector graphics (triangles, etc) into raster graphics (pixels)) * Texturing * Display Pixel 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. Hardware On 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## If water is not a good conductor, why are we advised to avoid water near electricity (no wet hands near circuits etc.)? ## Assistant: ## &quot;Pure&quot; water is a very poor conductor (resistivity is actually used as a measure of purity). &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. For 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}$ A 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). > Why immersion in water can be fatal with very low voltages * Immersion wets the skin very effectively and great lowers skin resistance per unit area * Contact area is a large percentage of the entire body surface area * Electric current may also enter the body through mucous membranes, such as the mouth and throat * 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 ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What is the difference between cohesion and coupling? How can coupling and cohesion lead to either good or poor software design? What are some examples that outline the difference between the two, and their impact on overall code quality? ## Assistant: ## 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. Example of Low Cohesion: ```------------------- | Staff | ------------------- | checkEmail() | | sendEmail() | | emailValidate() | | PrintLetter() | ------------------- ``` Example of High Cohesion: ```---------------------------- | Staff | ---------------------------- | -salary | | -emailAddr | ---------------------------- | setSalary(newSalary) | | getSalary() | | setEmailAddr(newEmail) | | getEmailAddr() | ---------------------------- ``` As 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. Good software design has ***high cohesion*** and ***low coupling***. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Can Romex (NM-B) cable be run through conduit? ## Assistant: ## 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. ## It's a nightmare to pull NM (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. Pulling 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. ## It requires ridiculously large conduit You 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. * 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... * 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. * 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. For 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. You are certainly allowed to do it, but you will be using rather enormous conduit, and you will have a hard time pulling. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Let's say I have a function which takes an ```std::function```: ```void callFunction(std::function x) { x(); } ``` Should I pass ```x``` by const-reference instead?: ```void callFunction(const std::function& x) { x(); } ``` Does 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. ## Assistant: ## If you want performance, pass by value if you are storing it. Suppose you have a function called "run this in the UI thread". ```std::future run_in_ui_thread( std::function ) ``` which 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) We have two signatures we are considering: ```std::future run_in_ui_thread( std::function ) // (A) std::future run_in_ui_thread( std::function const& ) // (B) ``` Now, we are likely to use these as follows: ```run_in_ui_thread( [=]{ // code goes here } ).wait(); ``` which 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. In 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. In 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```. So 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```. That 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&```. Now, there are some other differences between the two that mostly kick in if we have persistent state within the ```std::function```. Assume that the ```std::function``` stores some object with a ```operator() const```, but it also has some ```mutable``` data members which it modifies (how rude!). In 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. This is a relatively strange corner case. You want to treat ```std::function``` like you would any other possibly heavy-weight, cheaply movable type. Moving is cheap, copying can be expensive. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I have an Eloquent model which has a related model: ```public function option() { return $this->hasOne('RepairOption', 'repair_item_id'); } public function setOptionArrayAttribute($values) { $this->option->update($values); } ``` When I create the model, it does not necessarily have a related model. When I update it, I might add an option, or not. So I need to check if the related model exists, to either update it, or create it, respectively: ```$model = RepairItem::find($id); if (Input::has('option')) { if () { $option = new RepairOption(Input::get('option')); $option->repairItem()->associate($model); $option->save(); $model->fill(Input::except('option'); } else { $model->update(Input::all()); } }; ``` Where `````` is the code I am looking for. ## Assistant: ## 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. This means you can use the ```exists()``` or ```count()``` methods directly from a relation object: ```$model->relation()->exists(); // bool: true if there is at least one row $model->relation()->count(); // int: number of related rows ``` Note 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). Using 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. Both ```exists()``` and ```count()``` work on all relation types I've tried, so at least ```belongsTo```, ```hasOne```, ```hasMany```, and ```belongsToMany```. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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. When 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? Source: Nasa [sic] hiring new 'planetary protection officer' to defend Earth from alien matter - Times of India, Aug 3, 2017 ## Assistant: ## 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. The first paragraph of the story gets a little closer: The 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. &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. Preventing microbes from other worlds reaching Earth is also a concern, for similar reasons. Developing 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: Candidates will be required to travel frequently — but like any job, there will be a significant amount of emails, proposals and other reading. Candidates 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. The 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## 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? ## Assistant: ## 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? ## Bringing the dungeon to life While 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? ## Foreshadowing Once 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. #Currently empty These 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. Note 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... Tell a story with your empty rooms, or offer tactical choices. Preferably both. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Laravel - Eloquent "Has", "With", "WhereHas" - What do they mean? explain in the context of an example ## Assistant: ## With ```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. Example: ```User > hasMany > Post``` ```$users = User::with('posts')->get(); foreach($users as $user){ $users->posts; // posts is already loaded and no additional DB query is run } ``` Has ```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. Example: ```User > hasMany > Post``` ```$users = User::has('posts')->get(); // only users that have at least one post are contained in the collection ``` WhereHas ```whereHas()``` works basically the same as ```has()``` but allows you to specify additional filters for the related model to check. Example: ```User > hasMany > Post``` ```$users = User::whereHas('posts', function($q){ $q->where('created_at', '>=', '2015-01-01 00:00:00'); })->get(); // only users that have posts from 2015 on forward are returned ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What are some of the advantages of using one over the other? ## Assistant: ## 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'. Each 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. ASP.NET Web Forms: * Development supports state • 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. * Rapid Application Development (RAD) • 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. * Larger control toolbox • 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). * Mature • 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. ASP.NET MVC: * Separation of concerns (SoC) • 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. * Easier integration with client side tools (rich user interface tools) • 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. * Search Engine Optimization (SEO) Friendly / Stateless • 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. * Works well with developers who need high degree of control • 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. * Test Driven Development (TDD) • 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. Authentication, authorization, configuration, compilation and deployment are all features that are shared between the two web frameworks. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why did the Typescript folks create the ```infer``` keyword? According to the documents, this is an example of how you would use it: ```type ReturnType = T extends (...args: any[]) => infer R ? R : any; ``` I don't understand why this is needed. Why can't it just be: ```type ReturnType = T extends (...args: any[]) => R ? R : any; ``` Why doesn't this work? Why is the ```infer``` keyword necessary ? ## Assistant: ## With ```infer```, the compiler ensures that you have declared all type variables explicitly: ```type MyType = T extends infer R ? R : never; type T1 = MyType // T1 is { b: string; } ``` Here we declare a new type variable ```R``` in ```MyType```, which gets inferred from ```T```. (Note, that ```infer``` is always used within the ```extends``` clause of a conditional type.) Usage of undeclared type parameters now can result in a compile error: ```type MyType2 = T extends R2 ? R2 : never; // error, R2 undeclared ``` Without ```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. More precisely the compiler checks, if ```T``` is assignable to ```R``` , when ```infer``` is omitted: ```type R = { a: number } type MyType3 = T extends R ? R : never; // compare T with type R type T3 = MyType3 // T3 is never ``` Note, that ```infer R``` shadows type references of an equally-named type declaration ```R```: ```type R = { a: number } type MyType4 = T extends infer R ? R : never; type T4 = MyType4 // { b: string; } ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Which is more widely supported: ```window.onload``` or ```document.onload```? ## Assistant: ## When do they fire? ```window.onload``` * By default, it is fired when the entire page loads, including its content (images, CSS, scripts, etc.). In some browsers it now takes over the role of ```document.onload``` and fires when the DOM is ready as well. ```document.onload``` * It is called when the DOM is ready which can be prior to images and other external content is loaded. How well are they supported? ```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```. Browser 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: ```$(document).ready(function() { /* code here */ }); $(function() { /* code here */ }); ``` For the purpose of history. ```window.onload``` vs ```body.onload```: A similar question was asked on codingforums a while back regarding the usage of ```window.onload``` over ```body.onload```. The result seemed to be that you should use ```window.onload``` because it is good to separate your structure from the action. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I was surprised to learn that Puerto Ricans, despite living in a US territory, were not entitled to vote in the presidential elections. I 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. What 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? ## Assistant: ## 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. In 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. Now 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. But 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. Now 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). This 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. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Suppose I wrote that I will be killed by a UFO falling from space in the year 2315 while I am lifting. Will the Note increase my lifespan? In other words, will I still be alive by then? ## Assistant: ## No. There are some rules that prevent this. From the Rules of the Death Note wiki: 1. The 23-days rule How to use: XXVII * [...] * If you write, “die of disease” for the cause of death, but only write a specific time of death without the actual name of disease, the human will die from an adequate disease. But the Death Note can only operate within 23 days (in the human calendar). This is called the 23-day rule. 2. Situation/cause of death is impossible How to Use: LIV * [...] * In the occasion where the cause of death is possible but the situation is not, only the cause of death will take effect for that victim. If both the cause and the situation are impossible, that victim will die of heart attack. While an UFO falling on your head is technically unlikely, but not impossible, the fact that you'll be naturally alive by 2315 is impossible. You'll just shorten your life, not make it longer. 3. Setting death after original lifespan How to Use: LVII * In the Death Note, you cannot set the death date longer than the victim’s original life span. Even if the victim’s death is set in the Death Note beyond his/her original life span, the victim will die before the set time. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I have an Affa Protector enchanted with Unhallowed Pact ... My opponent kills my Affa with Dread Slaver ... Who will take control of the creature at the end? This is taking into consideration that my aura spell was cast 5 turns ago. Meaning my aura spell is NOT on the stack. ## Assistant: ## It depends on whose turn it is. Both abilities trigger at the same time, and so will be put on the stack together. Abilities are put on the stack in APNAP (Active Player, Non-Active Player) order.* This means that the player whose turn it is puts their ability on the stack, then the other player does. That second player's ability will resolve first, returning the creature to the battlefield. When the other ability tries to resolve, it fails to find the creature in the graveyard and thus can't return it. Thus whoever's the active player won't end up with the creature. For multiplayer games where there are multiple NAPs they are put on the stack in turn order starting from the AP, so the last player in turn order with such an effect would take precedence. * From the rules on Triggered Abilities: > 603.3b If multiple abilities have triggered since the last time a player received priority, each player, in APNAP order, puts triggered abilities he or she controls on the stack in any order he or she chooses. [...] This works with any number of players, starting with the active player and passing around in turn order. In this case, the player furthest away from taking their turn (the last player to put their ability on the stack) would get the creature. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I've found that some people call JavaScript a "dynamically, weakly typed" language, but some even say "untyped"? Which is it really? ## Assistant: ## strong/weak can be thought of in relation to how the compiler, if applicable, handles typing. * Weakly typed means the compiler, if applicable, doesn't enforce correct typing. Without implicit compiler interjection, the instruction will error during run-time. ```"12345" * 1 === 12345 // string * number => number ``` Strongly typed means there is a compiler, and it wants you an explicit cast from string to integer. ```(int) "12345" * 1 === 12345 ``` In either case, some compiler's features can implicitly alter the instruction during compile-time to do conversions for you, if it can determine that is the right thing to do. Thus far, JavaScript can be categorized as Not-Strongly-Typed. That either means it's weakly-typed or un-typed. dynamic/static can be thought of in relation to how the language instructions manipulate types. * Dynamically typed means the value's type is enforced, but the variable simply represents any value of any type. ```x = 12345; // number x = "string"; // string x = { key: "value" }; // object y = 123 + x; // error or implicit conversion must take place. ``` Statically typed means the variable type is strongly enforced, and the value type is less-so enforced. ```int x = 12345; // binds x to the type int x = "string"; // too late, x is an integer - error string y = 123; // error or implicit conversion must take place. ``` Thus far, JavaScript can be categorized as Not-Statically-Typed. Also, it appears to be Dynamically Typed, if typed at all. So we need to see what Typing means. Typed means that the language distinguishes between different types such as string, number, boolean, object, array, null, undefined and so on. Also each operation is bound to specific types. So you cannot divide an integer by a string. ``` 2 / "blah" // produces NaN ``` Untyped means the operation of dividing integer by string would result in treating the first four bytes of string as integer. This is because Untyped operations take place directly on bits, there are no types to observe. The outcome will be something quite unexpected: ``` 2 / "blah" // will be treated as 2 / 1500275048 ``` Since JavaScript behaves according to the definition of being Typed, it must be. And therefore it must be Dynamically Typed, and Weakly Typed. If anybody claims JavaScript is Untyped, it is merely for academic theory, not for practical application. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I was fixing my laptop, and as you may know, laptops have a lot of small screws to take out when you are fixing it. One of the screws fell into the floor (the floor has carpet on it), and I was unable to follow the screw with my sight. If I don't follow the screw with my sight when it falls, there is a high chance that I will not see that screw again. My question is: what kind of method, tool or hack can I use to find small screws that falls into the floor? I have tried using the tool with a magnet on the tip, that mechanics use to grab wrenches that falls in inaccessible areas, but had no luck finding the screw. ## Assistant: ## This is why you should always have spare screws on hand. Fortunately, there is a way: ## Light Method Most screws are silver. Shine a flashlight into the carpet and look for little silvery glints. This may take some time, but you'll probably find it. If your carpet is unnaturally thick... ## Magnet Method Take a powerful magnet (like a bar magnet, hardware stores - fridge magnets might work) and run it over the surface where you think the screw is. You should find it. If that still fails... ## Vacuum Method Take a good vacuum cleaner. Put a sock over the extending arm, and run it over where you think the screw is. The sock will prevent the screw from being vacuumed up, but it will be stuck to the sock. There will still be enough suction to pick up the screw, even with the sock. If not, get a new vacuum! If that fails... ## Organize your screws There are many useful tools to organize screws. Go to your local RadioShack and get one, or make one out of a magnet for that awesome lifehack feel. ## Stop using carpet! [Not a &quot;find your screws&quot; method - a tip about not frying your computer] Carpet can cause static discharge, which is very very very bad for a computer (personal experience). Work on a hard floor with an antistatic strap to reduce the chance of frying your PC. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What is the difference between mutex and critical section? Please explain from Linux, Windows perspectives? I am programming in C#, would these two terms make a difference. Please post as much as you can, with examples and such.... Thanks ## Assistant: ## From a theoretical perspective, a critical section is a piece of code that must not be run by multiple threads at once because the code accesses shared resources. * A mutex is an algorithm (and sometimes the name of a data structure) that is used to protect critical sections. * Semaphores and Monitors are common implementations of a mutex. In practice there are many mutex implementation availiable in windows. They mainly differ as consequence of their implementation by their level of locking, their scopes, their costs, and their performance under different levels of contention. Availiable synchronization primitives. * Monitor * Mutex * Semaphore * ReaderWriterLock * ReaderWriterLockSlim * Interlocked The ```lock(object)``` statement is implemented using a ```Monitor``` - see MSDN for reference. In the last years much research is done on non-blocking synchronization. The goal is to implement algorithms in a lock-free or wait-free way. In such algorithms a process helps other processes to finish their work so that the process can finally finish its work. In consequence a process can finish its work even when other processes, that tried to perform some work, hang. Usinig locks, they would not release their locks and prevent other processes from continuing. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What is the purpose of the single underscore "_" variable in Python? What is the meaning of ```_``` after ```for``` in this code? ```if tbh.bag: n = 0 for _ in tbh.bag.atom_set(): n += 1 ``` ## Assistant: ## ```_``` has 3 main conventional uses in Python: 1. To hold the result of the last executed expression in an interactive interpreter session (see docs). This precedent was set by the standard CPython interpreter, and other interpreters have followed suit. 2. For translation lookup in i18n (see the gettext documentation for example), as in code like ```raise forms.ValidationError(_(&quot;Please enter a correct username&quot;)) ``` 3. As a general purpose &quot;throwaway&quot; variable name: * To indicate that part of a function result is being deliberately ignored (Conceptually, it is being discarded.), as in code like: ```label, has_label, _ = text.partition(':') ``` * As part of a function definition (using either ```def``` or ```lambda```), where the signature is fixed (e.g. by a callback or parent class API), but this particular function implementation doesn't need all of the parameters, as in code like: ```def callback(_): return True ``` This use case can conflict with the translation lookup use case, so it is necessary to avoid using ```_``` as a throwaway variable in any code block that also uses it for i18n translation (many folks prefer a double-underscore, ```__```, as their throwaway variable for exactly this reason). Linters often recognize this use case. For example ```year, month, day = date()``` will raise a lint warning if ```day``` is not used later in the code. The fix, if ```day``` is truly not needed, is to write ```year, month, _ = date()```. Same with lambda functions, ```lambda arg: 1.0``` creates a function requiring one argument but not using it, which will be caught by lint. The fix is to write ```lambda _: 1.0```. An unused variable is often hiding a bug/typo (e.g. set ```day``` but use ```dya``` in the next line). The pattern matching feature added in Python 3.10 elevated this usage from &quot;convention&quot; to &quot;language syntax&quot; where ```match``` statements are concerned: in match cases, ```_``` is a wildcard pattern, and the runtime doesn't even bind a value to the symbol in that case. For other use cases, remember that ```_``` is still a valid variable name, and hence will still keep objects alive. In cases where this is undesirable (e.g. to release memory or external resources) an explicit ```del name``` call will both satisfy linters that the name is being used, and promptly clear the reference to the object. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What is the difference between doing: ```ptr = malloc (MAXELEMS * sizeof(char *)); ``` or: ```ptr = calloc (MAXELEMS, sizeof(char*)); ``` When is it a good idea to use calloc over malloc or vice versa? ## Assistant: ## ```calloc()``` gives you a zero-initialized buffer, while ```malloc()``` leaves the memory uninitialized. For large allocations, most ```calloc``` implementations under mainstream OSes will get known-zeroed pages from the OS (e.g. via POSIX ```mmap(MAP_ANONYMOUS)``` or Windows ```VirtualAlloc```) so it doesn't need to write them in user-space. This is how normal ```malloc``` gets more pages from the OS as well; ```calloc``` just takes advantage of the OS's guarantee. This means ```calloc``` memory can still be &quot;clean&quot; and lazily-allocated, and copy-on-write mapped to a system-wide shared physical page of zeros. (Assuming a system with virtual memory.) The effects are visible with performance experiments on Linux, for example. Some compilers even can optimize malloc + memset(0) into calloc for you, but it's best to just use calloc in the source if you want zeroed memory. (Or if you were trying to pre-fault it to avoid page faults later, that optimization will defeat your attempt.) If you aren't going to ever read memory before writing it, use ```malloc``` so it can (potentially) give you dirty memory from its internal free list instead of getting new pages from the OS. (Or instead of zeroing a block of memory on the free list for a small allocation). Embedded implementations of ```calloc``` may leave it up to ```calloc``` itself to zero memory if there's no OS, or it's not a fancy multi-user OS that zeros pages to stop information leaks between processes. On embedded Linux, malloc could ```mmap(MAP_UNINITIALIZED|MAP_ANONYMOUS)```, which is only enabled for some embedded kernels because it's insecure on a multi-user system. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I've looked in the Apex developer's guide and a saw the Naming Conventions section which has basically only has this: We recommend following Java standards for naming, that is, classes start with a capital letter, methods start with a lowercase verb, and variable names should be meaningful. I'm looking for something more in depth, such as end all Controllers with Controller and their tests with ControllerTest, etc. What is a good set of naming conventions to use when developing on the Force.com platofrm? It would be preferable if the answer has something that handles custom objects, classes, visualforce pages, and components and not just Apex classes. ## Assistant: ## Follow the CamelCase Java conventions, except for VF pages and components start with a lower case letter. Triggers: * <ObjectName>Trigger - The trigger itself. One per object. * <ObjectName>TriggerHandler - Class that handles all functionality of the trigger * <ObjectName>TriggerTest Controllers: * <ClassName>Controller * <ClassName>ControllerExt * <ClassName>ControllerTest * <ClassName>ControllerExtTest Classes: * <ClassName> * <ClassName>Test (These might be Util classes or Service classes or something else). Visualforce pages and components: * <ControllerClassName>[optionalDescription] (without the suffix Controller). There might be multiple views so could also have an extra description suffix. Object Names and custom Fields * Upper_Case_With_Underscores Variables/properties/methods in Apex * camelCaseLikeJava - more easily differentiated from fields Test methods in test classes * test<methodOrFunctionalityUnderTest><ShortTestCaseDesc> - For example, testSaveOpportunityRequiredFieldsMissing, testSaveOpportunityRequiredFieldsPresent, etc. Working on something that would be used as an app or in some cases just a project? If yes, then do the following: Prefix all custom objects, apex classes, Visualforce pages and components with an abbreviation so that they are easier to identify (e.g., easier for changesets). For example the WidgetFactory app would have the prefix wf on those. Additionally, when adding custom fields to a standard object they would also be prefixed to identify them as part of the app/package. The main reason for the Object and Fields Names using Upper_Case_With_Underscores is that when you type in the name field or object with spaces it automatically adds the underscores. Although Apex is case insensitive, always refer to the Objects and Custom Fields in the code as Upper_Case_With_Underscores as well for consistency all around and consistency with what is generated by the SOQL schema browser and other tools. Object and Field Labels (which are generally ignored by code but visible to users) should keep spaces, not underscores. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## When learning some basic French, I was somewhat surprised to learn that phrases of the form "I have found the cat" generally translate almost word-for-word from English (J'ai trouvé le chat). To me, it's not immediately obvious that possession ("I have"/"J'ai") has a correspondence with past tense, although if I think about it a little more I suppose I can kind of see how it makes sense. This makes me wonder: Is this a common pattern in other languages? Especially ones not closely related to English. ## Assistant: ## This is what's called a "Sprachbund" feature: it's a trait shared by a bunch of languages in an area, even ones that aren't genetically related. In particular, this one is a feature of the "Standard Average European" Sprachbund, a group of languages centered in Western Europe, and it's one of the features that was originally used to define that Sprachbund in the first place! The construction seems to have arisen back in Latin. In Classical Latin, past aoristic verbs ("I loved") and present perfective verbs ("I have loved") look exactly the same: both of those would be written amāvī. But it's a pretty useful distinction to be able to make! So in Vulgar Latin, a new construction arose, using the verb habēre ("to have"). It's thought that a phrase like habeō litterās scriptās "I have (written letters)" got reanalyzed into "I (have written) letters", with habēre no longer indicating that you're actually holding anything in your hands, just that an action's been completed in the past. Vulgar Latin eventually evolved into French, Italian, Spanish, and all the other Romance languages, and brought this construction with it; habēre is the direct ancestor of French avoir, via a series of sound changes. And once various Romance languages and Germanic languages and others were all being spoken in the same area, this feature spread through the Sprachbund: people speaking Germanic languages started to use the same construction. English "have"/German haben/etc isn't actually at all related to Latin habēre, but they looked similar, so it was the obvious choice when adopting the construction into Germanic. Nowadays, this feature is called the "have-perfective", and it shows up in all sorts of languages within the Standard Average European (SAE) Sprachbund. It's not at all universal, but can be a good way to determine if a language has been influenced by SAE or not! ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I'm building a simple helper script for work that will copy a couple of template files in our code base to the current directory. I don't, however, have the absolute path to the directory where the templates are stored. I do have a relative path from the script but when I call the script it treats that as a path relative to the current working directory. Is there a way to specify that this relative url is from the location of the script instead? ## Assistant: ## Python have already evolve to the ```__future__``` long time ago. So how about using the amazing ```pathlib``` coming with Python 3.4 to accomplish the task instead of struggling with ```os```, ```os.path```, ```glob ```, ```shutil```, etc. So we have 3 paths here (possibly duplicated): * ```mod_path```: which is the path of the simple helper script * ```src_path```: which contains a couple of template files waiting to be copied. * ```cwd```: current directory, the destination of those template files. and the problem is: we don't have the full path of ```src_path```, only know it's relative path to the ```mod_path```. Now let's solve this with the the amazing ```pathlib```: ```# Hope you don't be imprisoned by legacy Python code :) from pathlib import Path # `cwd`: current directory is straightforward cwd = Path.cwd() # `mod_path`: According to the accepted answer and combine with future power # if we are in the `helper_script.py` mod_path = Path(__file__).parent # OR if we are `import helper_script` mod_path = Path(helper_script.__file__).parent # `src_path`: with the future power, it's just so straightforward relative_path_1 = 'same/parent/with/helper/script/' relative_path_2 = '../../or/any/level/up/' src_path_1 = (mod_path / relative_path_1).resolve() src_path_2 = (mod_path / relative_path_2).resolve() ``` In the future, it's just that simple. Moreover, we can select and check and copy/move those template files with ```pathlib```: ```if src_path != cwd: # When we have different types of files in the `src_path` for template_path in src_path.glob('*.ini'): fname = template_path.name target = cwd / fname if not target.exists(): # This is the COPY action with target.open(mode='wb') as fd: fd.write(template_path.read_bytes()) # If we want MOVE action, we could use: # template_path.replace(target) ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## How to send HTML-formatted email in C#? ## Assistant: ## Setting isBodyHtml to true allows you to use HTML tags in the message body: ``` msg = new MailMessage("[email protected]", "[email protected]", "Message from PSSP System", "This email sent by the PSSP system<br />" + "<b>this is bold text!</b>"); msg.IsBodyHtml = true; ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I want to sum a list of Integers. It works as follows, but the syntax does not feel right. Could the code be optimized? ```Map integers; integers.values().stream().mapToInt(i -> i).sum(); ``` ## Assistant: ## This will work, but the `i -> i` is doing some automatic unboxing which is why it "feels" strange. `mapToInt` converts the stream to an `IntStream` "of primitive int-valued elements". Either of the following will work and better explain what the compiler is doing under the hood with your original syntax: ``` integers.values().stream().mapToInt(i -> i.intValue()).sum(); integers.values().stream().mapToInt(Integer::intValue).sum(); ``` The other simple option is `BigDecimal sum = numbers.stream().reduce(BigDecimal.ZERO, BigDecimal::add);`. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I am beginner of LaTeX. From many examples I found, I notice that it's very common to use command ```\leavevmode```. I can't find any information about this command. Could anyone tell me what's the function of it and how to use it? ## Assistant: ## The ```\leavevmode``` is defined by LaTeX and plainTeX and ensures that the vertical mode is ended and horizontal mode is entered. In vertical mode, TeX stacks horizontal boxes vertically, whereas in horizontal mode, they are taken as part of the text line. For example ```\mbox{..}``` is defined as ```\leavevmode\hbox{..}``` to ensure that horizontal mode is entered if it is used at the beginning of a paragraph. If you only use ```\hbox{ }``` it is stacked above the following paragraph instead. Compare: ```Text\par\hbox{Hello} World ``` Result: ``` Text Hello World ``` with: ```Text\par\mbox{Hello} World ``` Result: ``` Text Hello World ``` You see that in the first case the ```\hbox``` is stacked with the two paragraphs vertically (but without paragraph indention) because it is processed in vertical mode. In the second case horizontal mode is entered first and so ```Hello``` is processed as part of the second paragraph. Use ```\leavevmode``` for all macros which could be used at the begin of the paragraph and add horizontal boxes by themselves (e.g. in form of text). For further reading about ```\leavevmode``` please see "The TeXBook" by Donald E. Knuth, Appendix A, section 13.1, page 313 as well Appendix B, page 356. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## In Python specifically, how do variables get shared between threads? Although I have used ```threading.Thread``` before I never really understood or saw examples of how variables got shared. Are they shared between the main thread and the children or only among the children? When would I need to use thread local storage to avoid this sharing? I have seen many warnings about synchronizing access to shared data among threads by using locks but I have yet to see a really good example of the problem. Thanks in advance! ## Assistant: ## In Python, everything is shared, except for function-local variables (because each function call gets its own set of locals, and threads are always separate function calls.) And even then, only the variables themselves (the names that refer to objects) are local to the function; objects themselves are always global, and anything can refer to them. The `Thread` object for a particular thread is not a special object in this regard. If you store the `Thread` object somewhere all threads can access (like a global variable) then all threads can access that one Thread object. If you want to atomically modify anything that another thread has access to, you have to protect it with a lock. And all threads must of course share this very same lock, or it wouldn't be very effective. If you want actual thread-local storage, that's where `threading.local` comes in. Attributes of `threading.local` are not shared between threads; each thread sees only the attributes it itself placed in there. If you're curious about its implementation, the source is in _threading_local.py in the standard library. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why can't we kill ourselves by holding our breath? ## Assistant: ## ## Short answer Healthy people cannot hold their breaths until unconsciousness sets in, let alone commit suicide. ## Background According to Parkes (2005), a normal person cannot even hold their breath to unconsciousness, let alone death. Parkes says: Breath‐holding is a voluntary act, but normal subjects appear unable to breath‐hold to unconsciousness. A powerful involuntary mechanism normally overrides voluntary breath‐holding and causes the breath that defines the breakpoint. Parkes explains that voluntary breath‐holding does not stop the central respiratory rhythm. Instead, breath holding merely suppresses its expression by voluntarily holding the chest at a certain volume. At the time of writing, no simple explanation for the break point existed. It is known to be caused by partial pressures of blood gases activating the carotid arterial chemoreceptors. They are peripheral sensory neurons that detect changes in chemical concentrations, including low oxygen (hypoxia) and high carbon dioxide (hypercapnia). Both hypoxia and hypercapnia are signs of breath holding and both are detected by the chemoreceptors. These receptors send nerve signals to the vasomotor center of the medulla which eventually overrides the conscious breath holding. The breaking point can be postponed by large lung inflations, hyperoxia and hypocapnia, and it is shortened by increased metabolic rates. Reference - Parkes, Exp Physiol (2006); 91(1): 1-15 ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Sometimes while driving in the traffic, I come across a car or two which would be dripping water-like drops from its exhaust steadily in 4-5 second intervals. I tried to ask a couple of people at the local workshops; they say, and I quote, &quot;The car is giving an amazing mileage&quot;. And I am like, what does that water dripping mean even then? Why does the water drip? What is the source of it? And what does it signify? ## Assistant: ## It signifies that the car is running absolutely correct. Here is the reason why: A gasoline (petrol) molecule is made up as such: C8H18 (or 8 Carbon atoms and 18 Hydrogen atoms) Energy is obtained from the combustion of it by the conversion of a hydrocarbon to carbon dioxide and water. The combustion of octane follows this reaction: 2 C8H18 + 25 O2 → 16 CO2 + 18 H2O Or better said, you have two of the hydrocarbon molecules along with 25 oxygen molecules, they swirl together into a mix, the spark plug ignites them, boom, and out the tail pipe comes 16 carbon dioxide molecules and 18 water molecules ... at least in a perfect world. Some cars don't put out exactly that ratio. There may be a little bit of carbon monoxide (CO), unburnt hydrocarbons (C8H18), and/or nitrogen oxide (NO2) coming out of the engine exhaust port along with the CO2 and H2O. In this case, the catalytic convertor's job is to help clean these up so you can get closer to the perfect ratio described above. As described, the water coming out of the tail pipe is a natural occurrence of the combustion process. You will usually see it coming out of the tail pipe when the engine and exhaust system of the vehicle is not completely warmed up. When it does become completely warmed up, you won't see it any more, because it comes out as steam (well, you'll see it in the winter time if it's cold enough, but you get the idea). ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why can't MX records point to an IP address? ## Assistant: ## The whole idea behind the mail exchange (MX) record is to specify a host or hosts which can accept mail for a domain. As specified in RFC 1035, the MX record contains a domain name. It must therefore point to a host which itself can be resolved in the DNS. An IP address could not be used as it would be interpreted as an unqualified domain name, which cannot be resolved. The reasons for this in the 1980s, when the specs were originally written, are almost the same as the reasons for it today: A host may be connected to multiple networks and use multiple protocols. Back in the 80s, it was not uncommon to have mail gateways which connected both to the (relatively new) Internet which used TCP/IP and to other legacy networks, which often used other protocols. Specifying MX in this way allowed for DNS records which could identify how to reach such a host on a network other than the Internet, such as Chaosnet. In practice, though, this almost never happened; virtually everyone re-engineered their networks to become part of the Internet instead. Today, the situation is that a host may be reached by multiple protocols (IPv4 and IPv6) and by multiple IP addresses in each protocol. A single MX record can't possibly list more than one address, so the only option is to point to a host, where all of that host's addresses can then be looked up. (As a performance optimization, the DNS server will send along the address records for the host in the response additional section if it has authoritative records for them, saving a round trip.) There is also the situation that arises when your mail exchangers are provided by a third party (e.g. Google Apps or Office 365). You point your MX records to their hostnames, but it may occur that the service provider needs to change the mail servers' IP addresses. Since you have pointed to a host, the service provider can do this transparently and you don't have to make any changes to your records. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why is ```SELECT *``` bad practice? Wouldn't it mean less code to change if you added a new column you wanted? I understand that ```SELECT COUNT(*)``` is a performance problem on some DBs, but what if you really wanted every column? ## Assistant: ## The asterisk character, "*", in the SELECT statement is shorthand for all the columns in the table(s) involved in the query. Performance The ```*``` shorthand can be slower because: * Not all the fields are indexed, forcing a full table scan - less efficient * What you save to send ```SELECT *``` over the wire risks a full table scan * Returning more data than is needed * Returning trailing columns using variable length data type can result in search overhead Maintenance When using ```SELECT *```: * Someone unfamiliar with the codebase would be forced to consult documentation to know what columns are being returned before being able to make competent changes. Making code more readable, minimizing the ambiguity and work necessary for people unfamiliar with the code saves more time and effort in the long run. * If code depends on column order, ```SELECT *``` will hide an error waiting to happen if a table had its column order changed. * Even if you need every column at the time the query is written, that might not be the case in the future * the usage complicates profiling Design ```SELECT *``` is an anti-pattern: * The purpose of the query is less obvious; the columns used by the application is opaque * It breaks the modularity rule about using strict typing whenever possible. Explicit is almost universally better. When Should "SELECT *" Be Used? It's acceptable to use ```SELECT *``` when there's the explicit need for every column in the table(s) involved, as opposed to every column that existed when the query was written. The database will internally expand the * into the complete list of columns - there's no performance difference. Otherwise, explicitly list every column that is to be used in the query - preferably while using a table alias. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I did my training around the Seattle area, and was told that landing at SeaTac Airport (the region's major International/Commercial airport), while not strictly forbidden, was definitely frowned upon because it can slow down and interfere with the big planes on schedules. To discourage GA aircraft from using the big airport, they have a variety of landing fees, ramp fees, and prior-approval requirements. But later, I moved near MCI, and was told that landing at the big airport was no big deal. That they're actually happy to have little planes there. If you fly small GA planes, do you land at the major airports in your area? What advanced preparations can you make to minimize your impact on the "big boys", and remain a good airspace citizen? ## Assistant: ## Can you? Absolutely, and air traffic control will treat you (almost) like any other airplane. You are supposedly handled on a first-come-first-serve basis (reality is slightly different with different aircraft speeds, etc.). Do the airlines like it if you slow them down? No, but it's part of the system and the way that it works. Very often, there are multiple runways at bigger airports, and sometimes there are even shorter runways that are dedicated for airplanes that don't need to land on the same one as the "big boys". Even if not, they will work you in. Now, that being said, very often there is a better option. As you said, there are usually high fees at the big airports, so landing at a smaller satellite airport can often save you money and save you time because you won't have to taxi as far or sit and wait in line to get out. An extra 15 minutes by car can be better than an extra 30 minutes while taxiing. As far as being prepared, it isn't really much different than smaller airports other than the fact that ATC is much busier. They don't have the time/tolerance to keep repeating instructions to you, and expect you to be "on your game". When they rattle off taxi instructions like "Cessna N1234, taxi to the ramp via Alpha, Tango, Echo, and Xray. Hold short of runway 23." they expect a quick readback and for you to follow instructions exactly because they need to move on to the next guy. It will also help everyone out if you don't fly your final approach the way that most people are taught for an entire 10 mile final: very close to your actual landing speed. In fact, you are usually landing on a runway that is 4X+ the distance that you need and you can slow down fairly quickly (especially compared to a jet), so if you can fly an extra 20 (or 80) knots as long as possible, it will be greatly appreciated and keep traffic moving. Make sure that you leave yourself enough time to slow down at the end and above all else, ***be safe***. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Given the following code: ```var arr = [1,2,3,4,5]; var results: number[] = await arr.map(async (item): Promise => { await callAsynchronousOperation(item); return item + 1; }); ``` which produces the following error: TS2322: Type 'Promise[]' is not assignable to type 'number[]'. Type 'Promise is not assignable to type 'number'. How can I fix it? How can I make ```async await``` and ```Array.map``` work together? ## Assistant: ## The problem here is that you are trying to ```await``` an array of promises rather than a Promise. This doesn't do what you expect. When the object passed to ```await``` is not a Promise, ```await``` simply returns the value as-is immediately instead of trying to resolve it. So since you passed ```await``` an array (of Promise objects) here instead of a Promise, the value returned by await is simply that array, which is of type ```Promise[]```. What you probably want to do is call ```Promise.all``` on the array returned by ```map``` in order to convert it to a single Promise before ```await```ing it. According to the MDN docs for ```Promise.all```: The ```Promise.all(iterable)``` method returns a promise that resolves when all of the promises in the iterable argument have resolved, or rejects with the reason of the first passed promise that rejects. So in your case: ```var arr = [1, 2, 3, 4, 5]; var results: number[] = await Promise.all(arr.map(async (item): Promise => { await callAsynchronousOperation(item); return item + 1; })); ``` This will resolve the specific error you are encountering here. Depending on exactly what it is you're trying to do you may also consider using ```Promise.allSettled```, ```Promise.any```, or ```Promise.race``` instead of ```Promise.all```, though in most situations (almost certainly including this one) ```Promise.all``` will be the one you want. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why don't helicopters use reaction wheels to counter the main rotor? ## Assistant: ## You're talking about a device (in helicopters the tail fan imparting horizontal thrust) that counteracts the torque imparted on the main rotor (and therefore on the helicopter) by the surrounding air as the main rotor is dragged through the air. You propose instead to impart an opposite torque through a reaction wheel. That would indeed impart an opposite torque for short lengths of time. However, you don't get a torque from spinning a reaction wheel at constant angular velocity but by changing and accelerating that angular velocity. Now the torque imparted on the helicopter by the air through the main rotor is steady - or at least its of roughly constant direction. Therefore, to counter that torque, the reaction wheel would have to accelerated uniformly and indefinitely. Clearly this is impossible from an engineering standpoint. You can also think of this from a conservation of angular momentum, without thinking about the origin of the torques. The air imparts a steady angular impulse to the helicopter. Therefore, the helicopter system's angular momentum must increase steadily (unless there's a countering torque from the tailfan). So either that angular momentum is the spinning of the helicopter's body (which is what we're trying to avoid) or that of the reaction wheel, whose angular momentum must be steadily increasing under the action of the angular impulse to the system. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## When configuring cron to run a command every other day using the "Day of Month" field, like so: ```1 22 */2 * * COMMAND ``` it runs every time the day of month is odd: 1,3,5,7,9 and so on. How can I configure cron to run on days of month that are even like 2,6,8,10 and so on (without specifying it literally, which is problematic as every month has a different number of days in the month)? ## Assistant: ## The syntax you tried is actually ambiguous. Depending on how many days are in the month, some months it will run on odd days and some on even. This is because the way it is calculated takes the total number of possibilities and divides them up. You can override this strage-ish behavior by manually specifying the day range and using either an odd or even number of days. Since even day scripts would never run on the 31st day of longer months, you don't lose anything using 30 days as the base for even-days, and by specifying specifically to divide it up as if there were 31 days you can force odd-day execution. The syntax would look like this: ```# Will only run on odd days: 0 0 1-31/2 * * command # Will only run on even days: 0 0 2-30/2 * * command ``` Your concern about months not having the same number of days is not important here because no months have MORE days than this, and for poor February, the date range just won't ever match the last day or two, but it will do no harm having it listed. The only 'gotcha' for this approach is that if you are on an odd day cycle, following months with 31 days your command will also run on the first of the month. Likewise if you are forcing an even cycle, each leap year will cause one three-day cycle at the end of February. You cannot really get around the fact that any regular pattern of "every other day" is not always going to fall on even or odd days in every month and any way you force this you will either have an extra run or be missing a run between months with mismatched day counts. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Can I spend the night alone in a tent in a forest outside Stockholm in -20°C without risking my life? The backstory From the end of January, I'm starting my studies in a suburb of Stockholm. I've decided to, if it turns out plausible, not rent an apartment, but live in a tent. (This is not out of frugality, but out of a will to try something new.) I do have friends who I could visit once a week or so to prepare food and wash my clothes, so I think I can solve the practical problems, or at least those that I've come to think of. I'd camp in one of the forests, maybe 1 km from "civilisation". I'd have access to showers etc at university every day. However: I don't want to freeze to death in my sleep! That's very important to me. I've read that the nights can get as cold as -20°C (-4°F). With the proper preparations, would this be a plausible way of living, at least for a month or so? I do have camping experience, and have been hiking for three weeks, but only in summer. ## Assistant: ## Yes, it is definitely doable. -20&deg;C is only -4&deg;F. The real question is whether it is doable by you at the level of discomfort and hassle you are willing to put up with. Only you can answer that. At best we can point out what the hassles and discomforts will be. First, your fear of dying of cold in your sleep is silly. You'd have to do something pretty stupid to die of hypothermia, and even that's not going to happen when you're inside the sleeping bag. The main danger will be from frostbite, but that again would largely need stupidity to help it along, although that's easier to do than outright death from hypothermia. Your tent will be a long term fixed installation you set up once at a time and conditions of your choosing. You can therefore afford a larger and heavier tent with more stuff you bring in once. Definitely get a tent you can stand upright in. That will make changing clothes much quicker and more comfortable. Since you should be able to keep water out of the tent, get a nice down sleeping bag and a few light blankets. The down bag should be rated for most nights, then put the blankets on top for the few unusually cold nights. Since again weight is not really a issue, get a full sleeping bag, not a mummy bag. They are simply more comfortable. Get a good insulating pad, and another two as backup. Get a tent large enough to fit your sleeping bag and something to sit on next to it, like a folding chair. Put something under the legs to spread out the weight to that they don't hurt the tent floor. Get one of those rubber-backed mats people sometimes put just inside their doors and put it just inside your tent. That allows a place to step with boots still on, then you can sit down on the chair with boots still on the mat to take them off. The crud stays on the mat, which you can shake clean by reaching outside after having put on your down hut booties. Some things are going to be a hassle. At -4&deg;F you want to keep your gloves on whenever possible, but some tasks will be difficult that way. You end up taking your gloves on and off a lot, trading off efficiency with cold fingers. Get a pair of polypro glove liners. They are thin and still allow many tasks to be done, but provide at least a little insulation. Their main advantage is that any metal you touch won't immediately conduct the heet from your hand away. Touching bare metal at -4&deg;F is a good way to get frostbite. Be prepared for some discomfort no matter what equipment you have. The toughest part will be getting yourself out of the sleeping bag in the morning. You'll really have to will yourself to leave the warm comfort of the bag and get into the air at probably the coldest part of the day. At some point you'll have to change your clothes and get undressed in the process. That's going to be cold. It won't be cold long enough to be any real danger, so it's really a mindset issue to get over. Whether you can or not and are willing to push yourself in that way only you can say. You say you have access to heated buildings during the day, so it would make things a lot simpler for you if you don't have to deal with cooking and eating at your camp. Perparing food outside in the cold takes a lot longer than in a heated kitchen, severly limits what you can do, and may also risk predator encounters depending on what is around your area in the winter. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why is the volt not identical to the full name Volta, unlike the other electrical units ohm, ampere, coulomb, tesla, weber and henry? Is there a historical explanation, was the volt introduced at a different time? ## Assistant: ## The volt, ohm and farad were introduced by the same person, Latimer Clark, a cable engineer, in a paper in 1861. He started the tradition of naming units after scientists. He initially distorted all names: the unit names ohma, volt, galvat (from Galvani), and farad (from Faraday). In his words, he "neglected etymological rules". In that same year, a committee of the British Association for the Advancement of Science began developing a coherent system of electrical units, the cgs system. Varley, a committee member, liked Clark's proposal, but he advocated adding a French name such as Ampere, to facilitate the international acceptance of the new units ("I should like to introduce a French name into the list. We have Germany, England and Italy represented"). For the same reason he may have pleaded for not distorting the French and German names. In addition, Varley objected to the galvat "because Galvani discovered next to nothing". Latimer Clark adapted the unit names in his 'Elementary treatise on electrical measurement' (1868). He changed ohma to ohm, and dropped the galvat. Maxwell acknowledged Clark's practical units and their names in his 'Treatise on electricity and magnetism' (1873). In 1881, at the International Electrical Congress in Paris), two French names, ampere and coulomb, were added. The diplomacy worked, and the new system of electrical units was adopted by all countries. The only units that kept the initial name distortion were the volt and the farad. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## We can define cross products mathematically like if we take two vectors, we can find another vector with certain properties but why do we use it in physics, if we consider a hypothetical physical quantity like force which is equal to cross product of certain vectors? For example, the force exerted on a charge in motion in an uniform magnetic field. Why is it so? Why does that force have to be a cross product of two vectors? Is it possible to come up with them when what we do is just observe the nature? ## Assistant: ## This is a great question. The dot and cross products seem very mysterious when they are first introduced to a new student. For example, why does the scalar (dot) product have a cosine in it and the vector (cross) product have a sine, rather than vice versa? And why do these same two very non-obvious ways of "multiplying" vectors together arise in so many different contexts? The fundamental answer (which unfortunately may not be very accessible if you're a new student) is that there are only two algebraically independent tensors that are invariant under arbitrary rotations in $n$ dimensions (we say that they are "$\mathrm{SO}(n)$ invariant"). These are the Kronecker delta $\delta_{ij}$ and the Levi-Civita symbol $\epsilon_{ijk \cdots}$. Contracting two vectors with these symbols yields the dot and cross products, respectively (the latter only works in three dimensions). Since the laws of physics appear to be isotropic (i.e. rotationally invariant), it makes sense that any physically useful method for combining physical quantities like vectors together should be isotropic as well. The dot and cross products turn out to be the only two possible multilinear options. Why multilinear maps are so useful in physics is an even deeper and more fundamental question, but which answers to that question are satisfying is probably inherently a matter of opinion. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I have a web project in my solution file that is "unavailable" when I open the solution. When I right-click on the web project and reload the project, I get the following error: ``` The Web Application Project mycompany.myapp.mywebproject is configured to use IIS. The Web Server 'http://localhost/MyWebApp could not be found. ``` I have not manually set up virtual directories for this web application. Per colleagues, Visual Studio should prompt me to create virtual directories but I am not getting prompted. I installed VS2010 before installing IIS on my dev machine. Here is my development machine setup: * Windows 7 Enterprise * Service Pack 1 * 64 bit OS * Visual Studio 2010 Enterprise Service pack 1 * IIS version 7.5 ## Assistant: ## When this happens the easiest solution is to make the virtual directory manually. First of all, you need to make sure you have the right version of ASP.Net installed and that you have installed the IIS extensions. To do this, go to the relevant .net version's folder in C:\(Windows)\Microsoft.NET\Framework\(dotnetver)\ (substituting the bracketed folders for the right folders on your PC) and run this command ```aspnet_regiis.exe -i ``` Next once that's run and finished, sometimes running ```iisreset ``` from the command line helps, sometimes you don't need to. Next, go to your IIS Manager and find you localhost website and choose add a folder. Browse to the folder in your project that contains the actual ASP.Net project and add that. Finally, right click on the folder you added and you should have an option that says 'convert to application' or 'create virtual directory' or something similar. Please make sure the Virtual directory has the name 'MyWebApp'!! Reload your solution and it should work. Good luck! ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Why is it hard to draw people running in animes? ## Assistant: ## The walk cycle is considered to be one of the most basic aspects of animation. American animators and animation enthusiasts often times scorn the Japanese styles and methods of animation as lazy, while Japanese anime enthusiasts deride the American style as clunky or too comical. Why is that you ask? The answer lies in how these countries distribute their budget and time. While American animation often times may seem lacking in it's attention to detail, it makes up for it the quality of their animation. American animation often times meticulous and original in how they animate motion, though sometimes content is reused cyclically, the animation is painstakingly frame by frame. In contrast, Japanese anime uses a lot of shortcuts (to save budget and meet deadlines). Typically long scenes feature only the mouth of a character (and maybe other minor features like a waving hair or glittering eyes) moving during delivery of key information/dialog, or the short burst of motion of some character in some an action pose against an animated, cyclic, and stylized background (I'm looking at you transformation scenes). Often times these uses of dramatic still-shots are done against patterned (or static illustrated) backgrounds, sometimes a few moving emotive icons (sweat drops, question marks, small chibi animated heads) will accompany a some sort of monologue. Admittedly both styles of animation reuse shots and sequences, but it's more noticeable in Japanese anime for various reason (e.g., not enough budget and/or manpower). This is why Japanese anime is typically labeled as "lazy" by American animators and enthusiasts. A typical walk cycle in animation consists of 8 keyframes typically: The smoothness of an animation is typically determined by the framerate and amount of key frames in the animation. In American animation, the animation is captured by shooting two frames of film per drawing at a rate of 24 frames per second (fps) to achieve the smooth motion of American animation. Japanese anime, while it also runs at an average 24 fps, typically captures their animation at a rate of three or four frames per drawing in order to save money and manpower. Though it varies depending on the studio and tools used (e.g 3DCG) with main objects in the foreground (typically characters) are animated at 8 to 12 fps, while background objects can be animated at as low as 6 to 8 fps. Lets compare the difference between one walk cycle that is 8 frame to one that is 16 frames, both at 60 fps: Notice the 16 frame one is smoother, but slower while the 8 frame is faster, but choppier. This is because it takes the 16 frame animation twice as long, covering more frames, to go through one cycle than the 8 frame one. The varying of frame rates can also be be used to depict the expansion and compression of time (think bullet time from The Matrix). However generally choppy animation is the result of not enough keyframes in your animation. More frames mean more and manpower and/or time, which ultimately means more money is required. Japanese anime production don't typically have as big of a budget compared to American productions (but there are exceptions), so they must make do with what they have and cut corners where they can (like Shaft did with the certain Bakemonogatari TV episodes). ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Malachi 4:5: I will send you the prophet Elijah. He will come before the day of the Lord arrives. It will be a great and terrifying day Jesus says in Matthew 11:14 "and if you are willing to believe their message, John is Elijah, whose coming was predicted" Jesus says in Mathew 17:12 But I tell you, Elijah has already come, and they did not recognize him, but have done to him everything they wished. In the same way the Son of Man is going to suffer at their hands.” It's pretty clear from the above verses that John was Elijah reincarnated. Wouldn't the above verses imply that reincarnation is true? ## Assistant: ## Faulty Premise #1: John the Baptist was a reincarnation of Elijah When Jesus asked Peter who people said he was, he answered that some people thought that Jesus was Elijah come back. Peter knew better and said Jesus was the Christ. In any event, John the Baptist himself directly denied the claim (see John 1:19-21). What Jesus more likely was saying in Matthew 11 is that John the Baptist was a prophet in the tradition of Elijah. Elijah was the greatest of the prophets (even if his disciple Elisha inherited a double portion of his spirit). All of the prophets that followed came in the name and spirit of Elijah, in the same way that some of Paul's letters apparently were created after his death. They were in the spirit and tradition even if not the actual man. Note also Elijah never died - he was taken up into heaven, and people thought he would return. As such, no Elijah was not being thought to have reincarnated- only returned. Elijah's return was long a part of Jewish custom. Even today, during a Passover sedar, a chair is left empty for Elijah. But again, since he did not die, Jews look for his return, not his reincarnation. Faulty Premise #2: The Jewish world view has any concept of reincarnation at all The most basic rule of hermeneutics suggests that a text cannot mean what it could not mean to the original audience. If the Jews had no concept of reincarnation, then any interpretation that says it does has a very, very high bar to clear. In his book The Gift of the Jews, Thomas Cahill advances the thesis that the primary distinctive philosophy of the Jews was precisely that history was not circular. Their linear idea of a human life was a departure from others and was an explicit rejection of reincarnation. As such, a text would need to be exceedingly explicit to a culture that rejected circular life patterns, and the obscure interpretation above (especially in light of the more obvious intepretation) simply doesn't hold water. Furthermore, the book of Hebrews - written to the people into which both Jesus and John the Baptist were born - explicitly reject reincarnation. As the writer points out in 9:27, It is appointed unto a man once to die and then the judgement. Here we do have an explicit rejection of reincarnation by the followers of Jesus. There is one death. There is one judgement. Hence, in any Christian worldview, you don't come back. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I see hugely varied performance depending on how many newlines there are in the file I'm visiting. Here's an example. I have two JSON files: ```$ wget https://github.com/Wilfred/ReVo-utilities/blob/a4bdc40dd2656c496defc461fc19c403c8306d9f/revo-export/dictionary.json?raw=true -O one_line.json $ python -m json.tool pretty_printed.json ``` These are two JSON files with the same content. ```one_line.json``` is 18MiB of JSON without any newlines. ```pretty_printed.json``` has newlines and whitespace added, making it 41MiB. However, the bigger file split over many lines is much faster to open in Emacs, both in Javascript mode and Fundamental mode. Why does Emacs have such poor performance with long lines, since it's actually fewer bytes? Is there anything I can do to improve performance without reformatting the data outside of Emacs? ## Assistant: ## Emacs' handling of long lines is not very well optimized. For a number of operations, Emacs has to scan the whole line repeatedly. For example, to display a line, Emacs has to figure out the height of the line, which requires scanning the whole line to find the tallest glyph. Additionally, scanning for bidirectional display eats up a lot of time. You can get some additional information in, for example, the docstring of ```cache-long-line-scans``` (renamed ```cache-long-scans``` in 24.4). You can try and see if setting ```bidi-paragraph-direction``` to ```left-to-right``` and setting ```bidi-inhibit-bpa``` (new in Emacs 27, see footnote 1) to ```t``` improves the speed for you (see footnote 2). This removes some significant contributors to line scans, but sadly not the only ones. The best option is to add newlines. You can pipe a JSON file through e.g. ```python -c 'import json, sys ; json.dump(json.load(sys.stdin), sys.stdout, indent=2)'``` to add newlines and improve readability in general. Footnote 1: ```bidi-inhibit-bpa``` is new in Emacs 27. Setting it to ```t``` can have a noticeable (sometimes dramatic) effect in cases where (a) a physical line is very long, and (b) the line includes many parentheses and/or braces, especially if they are nested. Footnote 2: There is also ```bidi-display-reordering```, but this is only for internal/debugging purposes. Setting it to ```nil``` may improve performance, however that is an unsupported setting which may cause other problems, so it is not recommended. In Emacs 27, the combination of setting ```bidi-paragraph-direction``` and ```bidi-inhibit-bpa``` is a supported configuration which provides approximately the same performance boost. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Sooner or later we come across a task in our project, with which we are totally unfamiliar ('we' as in PM, but also possibly the staff assigned to do this particular task). How can we estimate amount of time/work/resources needed to complete such a task? What margins of error should we assume? ## Assistant: ## Don't place too much confidence on your first guess just because you've used a sophisticated formula to derive your estimate. Do your best, move on, plan to revise your estimate, don't let bad estimates linger and destroy the discipline of your project schedule ... errors in time estimates are likely to be lognormally distributed... use a method that incorporates an optimistic guess, a pessimistic guess and heavily weights your best guess. Estimate, test, check, then revise and update your project schedule. The third or fourth revision of the estimates is usually about as accurate as you can hope for; your second estimate is far better than your first guess ... if possible, try to get a measure from an early trial of a similar or analogous task ... revise the estimate and revise your plan as soon as better data becomes available. If your first estimate was too conservative, don't allow slack time to corrupt completion of succeeding tasks. If your first estimate was overly optimistic, make your adjustments EARLY and let your stakeholders and customers know. It's more important to be good at following up, to check your estimates and to competently communicate updates than it is to be a develop skill as an estimator of unfamiliar tasks. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## If we fold a paper and then apply pressure on the newly formed crease, it seems that the paper's surface gets a permanent deformation but what exactly has happened to the paper at a molecular scale? ## Assistant: ## Basically, a fold or crease in paper will remain because the structure of the fibers in the paper have become irreversibly damaged. This happens because the paper is bent/compressed beyond its elastic limit. Chemically, paper is mainly composed of cellulose from plant fibers. Cellulose is an organic polymer, which has D-glucose units connected through hydrogen bonds. These bonds form between the oxygen atom of the one-hydroxyl group belonging to the glucose and the hydrogen atom of the next glucose unit. These are microscopic properties of paper, but to understand what happens when we fold paper or do Origami, it is sufficient to learn what is happening macroscopically. All materials have what is called an elastic limit and a plastic region. The elastic limit is the point at which a material will bend but still return to its original position without any permanent change or damage to its structure. Further deforming the material beyond this limit takes it to its plastic region. At this point any structural or physical changes become permanent and the paper will not return to its original form. Every material has a different elastic limit or yield, and plastic region. Imagine holding a piece of paper slightly bent but not folding or creasing it. The plant fibers that make up the paper will not have exceeded their elastic limit. So as soon as you let go of the paper sheet it will quickly return to its noncreased original flat state. However, if you were to roll that piece of paper into a cylinder and hold it for a few minutes, some of these fibers will be pushed beyond the elastic limit which is evident since it will not lie flat anymore since slight deformations have occurred in this sheet. Now, when you properly fold a piece of paper as you would during Origami, the plant fibers along the crease are pushed into the plastic region of the paper, causing a fracture point at the actual line of the fold. A practical example of this is if you were to fold a piece of paper, you will note that if you stretch the paper evenly on both sides of the fold, the paper will tear right on the fold (a quick way to &quot;cut&quot; paper if you have no scissors). The fold then becomes an irreversible structural failure and the fibers in the paper will never regain their original state. Because of this damage to its structure, the paper will from then on have this fold. And no matter how hard you try to flatten out the fold it will never return to its original state. This is why Origami models continually retain their shape. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## What are the differences between the Strategy design pattern and the State design pattern? please explain the difference in layman's terms? ## Assistant: ## The difference simply lies in that they solve different problems: * The State pattern deals with what (state or type) an object is (in) -- it encapsulates state-dependent behavior, whereas * the Strategy pattern deals with how an object performs a certain task -- it encapsulates an algorithm. The constructs for achieving these different goals are however very similar; both patterns are examples of composition with delegation. Some observations on their advantages: * By using the State pattern the state-holding (context) class is relieved from knowledge of what state or type it is and what states or types that are available. This means that the class adheres to the open-closed design principle (OCP): the class is closed for changes in what states/types there are, but the states/types are open to extensions. * By using the Strategy pattern the algorithm-using (context) class is relieved from knowledge of how to perform a certain task (-- the "algorithm"). This case also creates an adherence to the OCP; the class is closed for changes regarding how to perform this task, but the design is very open to additions of other algorithms for solving this task. This likely also improves the context class' adherence to the single responsibility principle (SRP). Further the algorithm becomes easily available for reuse by other classes. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I remember when the Muslim holy book was the Koran when I was in middle school, but now it's the Quran. But it's always been Qatar and Iraq (but still Kuwait.) Who decided that 'Q' was going to be represent that sound instead of 'K', and why? ## Assistant: ## In Arabic, in fact, they've always been separate sounds! The sound we write "K" is spelled with the letter ك in Arabic, and is pronounced a little bit further forward in the mouth; the sound we write "Q" is spelled with the letter ق and pronounced a little bit farther back. In phonetic terms, "K" is a velar sound, and "Q" is a uvular sound. English doesn't distinguish between these two different sounds. But since we've got a spare letter lying around—the English letter "Q" is actually related to the Arabic letter ق, if you go back far enough!—it's become conventional to separate them in writing. "Kuwait" is spelled with a ك, so it gets a "K"; "Qatar" is spelled with a ق, so it gets a "Q". The "Qur'an", similarly, has a ق in it. Nowadays, by the way, the letter "Q" has started to be associated with Arabic in particular, since it shows up significantly more there than in English. So in pop culture, you'll sometimes see names like "Hakeem" respelled to "Haqim"—even though the original Arabic has a ك in it! Linguistically, this is called hypercorrection, and it's the same reason you'll see words like "forté" with an é: English-speakers associate the acute accent with Romance loans (café, fiancé, résumé), but it has no special meaning in English, so it sometimes gets inserted where it doesn't actually belong (the original Italian word is simply forte). ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## How do you add Boost libraries in CMakeLists.txt? ## Assistant: ## Put this in your `CMakeLists.txt` file (change any options from OFF to ON if you want): ``` set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost VERSION COMPONENTS *boost libraries here*) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) add_executable(progname file1.cxx file2.cxx) target_link_libraries(progname ${Boost_LIBRARIES}) endif() ``` Obviously you need to put the libraries you want where I put `*boost libraries here*`. For example, if you're using the `filesystem` and `regex` library you'd write: ``` find_package(Boost VERSION COMPONENTS filesystem regex) ``` ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## Quando devo fazer essa gravação direto no banco? Quais as situações? Eu sei que posso gravar no banco o caminho da imagem. ## Assistant: ## Além do custo ser mais alto como mencionado, deve-se levar em conta vários fatores: * Volume de dados: para um baixo volume de dados pode não haver problema. Por outro lado, para armazenamento de grande massa de dados o banco de dados é praticamente inviável. Pergunte ao Facebook ou ao Google se eles usariam banco. O Facebook, por exemplo, usa um sistema de arquivos personalizado para tornar o acesso mais rápido ainda e diminuir a o overhead por arquivo exigido pelos sistemas de arquivos tradicionais. * Clusterização: uma vantagem do banco de dados é no caso do seu sistema rodar em vários servidores, todos terão acesso uniforme aos arquivos. Porém, usar uma unidade na rede para armazenar os arquivos. * Disponibilidade: seu sistema vai ter muitos acessos? Isso pode sobrecarregar um banco de dados tradicional. Por outro lado, seu servidor HTTP pode usar as rotinas de acesso de baixo nível ao sistema de arquivos para enviar o stream de dados ao cliente. * Escalabilidade: se a demanda de volume ou disponibilidade aumentarem, será possível adicionar mais capacidade ao sistema? É muito mais fácil dividir arquivos entre servidores diferentes do que distribuir registros de uma tabela em mais servidores. * Flexibilidade: fazer cópias de segurança, mover arquivos de um servidor para outro, fazer algum processamento nos arquivos armazenados, tudo isso fica mais fácil se os arquivos estiverem num diretório. Se você faz o deploy em ambiente de cliente, os arquivos no disco não inviabilizam você de receber cópias do banco de dados para testes. Tente pedir para o seu cliente enviar terabytes de dados para você analisar se der algum problema no banco. * Overhead de leitura e gravação: o custo computacional para gravar e ler dados do banco de dados é maior do que para ler e gravar diretamente em um arquivo. Existem várias estratégias para escalar um sistema tanto em termos de disponibilidade quanto em volume. Basicamente essas estratégias consistem em distribui-los em vários vários servidores e redirecionar o usuário para cada um deles conforme algum critério. Os detalhes variam de implementação, tais como: estratégia de atualização dos dados, redundância, critérios de distribuição, etc. Uma das grandes dificuldades em gerenciar arquivos fora do BD é que temos agora duas fontes de dados distintas e que precisam estar sempre em sincronia. Do ponto de vista de segurança, efetivamente há pouca diferença. Se um hacker pode comprometer um servidor, ele poderá ler tanto os arquivos gravados em disco do seu sistema quanto os arquivos do sistema de banco de dados. Se essa questão for crítica, uma alternativa é armazenar os dados criptografados. Porém, sempre que fiz a análise do melhor tipo de solução, o uso do sistema de arquivos sempre esteve em grande vantagem. ### END CONVERSATION ###
### BEGIN CONVERSATION ### ## Human: ## I need a regular expression that validates a number, but doesn't require a digit after the decimal. ie. ```123 123. 123.4 ``` would all be valid ```123.. ``` would be invalid ## Assistant: ## Here is the regular expression you can use: ``` /^\d*\.?\d*$/ ``` * `^` - Beginning of the line; * `\d*` - 0 or more digits; * `\.?` - An optional dot (escaped, because in regex, . is a special character); * `\d*` - 0 or more digits (the decimal part); * `$` - End of the line. This allows for .5 decimal rather than requiring the leading zero, such as 0.5 ### END CONVERSATION ###