Continued fractions using all natural integers

Question: What can one say about the set of continued fractions $[0;a_1,a_2,\ldots]$, where $a_1,a_2,\ldots$ are a permutation of the set of natural numbers?
Comment: I'm going to take a wild guess here: nothing. Except, of course, for the fact that those numbers cannot be rational or quadratic irrationalities. Since I've nothing to support this guess really, I'll leave this as a comment rather than an answer.
Answer: It has measure zero; see the Wikipedia article on Khinchin's constant.
Answer: Using techniques from ergodic theory there are some good results on what the continued fraction of a random number looks like.  In particular, the entries should follow the Guass-Kuzman distribution.  This says that the entry is 1 roughly 40% of the time.  So getting a permutation of the set of natural numbers is exceedingly unlikely.
Comment: Do you need Gauss-Kuzmin? It seems like such a strong condition on the continued fraction should be attainable with much weaker techniques. (Actually, looking at Wikipedia, the approach I had in mind looks like it could be pretty easily modified to yield Gauss-Kuzmin, but I still wonder if this is easier.)
Answer: Yeah, it has measure 0 by what Qiaochu said, although I strongly suspect there's probably a more elementary way to prove this (or at least give a strong heuristic argument.)
It's also uncountable, which means that in particular: 1. There exist numbers of this type that are transcendental, 2. There exist numbers of this type that are uncomputable, 3. It's very very very very unlikely that you'll be able to come up with a nontrivially different characterization of them.
They don't form any algebraic structure of any significance as far as I can tell (not a field, not a ring, I'm 100% sure but not completely convinced not a group), they're obviously not dense in the reals...
In essence, these are pretty much a completely typical uncountable set of measure 0, as far as I can tell.
Comment: Is there *any* algebraic number at all in this set?  Continued fraction [1,2,3,4,5...] itself evaluates to a quotient of Bessel functions, so is presumably not algebraic.
Comment: Actually, I think it's nowhere dense. Topologically this resembles the Cantor set, except I'm not sure if it's dense in itself or not.
Comment: @Prof. Edgar:  See the answers of Timothy Gowers and David Speyer below .
Comment: I should point out that my answer only argues that the approximation rate of this continued fraction is consistent with the set containing an algebraic number; I have no opinion as to whether there actually is an algebraic number in this set.
Comment: @Gerald: Although I've not seen the conjecture about transcendence of such CFs (but this is indeed a very unnatural set as already pointed out), it's something that one should expect. The CF for $[1,2,3,\dots]$ (as quotient of the values of Bessel functions) is trancendental. @David: almost all numbers have approximation rate consistent with algebraic numbers. Algebraic numbers are too rare to appear.
Comment: Regarding the last sentence. The space is homeomorphic to the the irrationals. It's rather unlike the Cantor set since its compact subsets are nowhere dense.
Comment: It has measure 0 and is uncountable?
Answer: I could be saying something accidentally stupid here, but let me risk it. It seems to me that Roth's theorem, which tells us that algebraic numbers can't be approximated substantially better than quadratic irrationalities, implies that the quotients in a continued fraction grow more slowly than linearly (or indeed any power that's greater than zero). If that's right, then a number of the kind you are talking about would have to be transcendental. My doubt about this argument is whether I've got the relationship between the quotients and rational approximation correct.
Of course, this is ignoring completely the fact that the quotients are a permutation of the positive integers and just using the fact that they must be quite large. It sounds as though your question is not "What can we say about a number with that property?" but rather "What can we say about the set of all numbers with that property?" so this observation, even if correct, may not have much to do with your question.
Comment: I don't think this works, see my answer.
Comment: I think you're right -- and indeed I was worried that something like that would happen. So it seems that the quotients have to grow rather fast to make the number transcendental.
Answer: This is a comment on gowers' answer, but it is long enough that I am making it an answer on its own.
I don't think this quite works. If $[a_0, a_1, \ldots, a_i]=p_i/q_i$, and $x$ is the value of the infinite continued fraction, then
$$|x-p_i/q_i|= 1/(q_i q_{i+1})-1/(q_{i+1} q_{i+2}) + \cdots \approx 1/(q_i q_{i+1}).$$
We have $a_{i+1} q_i < q_{i+1} < (a_{i+1} +1 ) q_i$, so $q_{i+1} \approx a_{i+1} q_i$.
If $a_i$ is a permutation of the integers which doesn't reorder them too much then $a_i$ is about $i$ so $q_i \approx i!$. Inverting Stirling's approximation, $i \approx \log q_i/\log \log q_i$.
So we have
$$|x-p/q| \approx \frac{\log \log q}{q^2 \log q}.$$
This is consistent with Roth's theorem.
My hazy memory is that there is a conjecture that, for $\phi(q)$ a decreasing positive function, there is an algebraic number $x$ with infinitely many solutions to $|x-p/q| < \phi(q)$ if and only if $\sum q \phi(q)$ diverges. That would predict that the error rate above is consistent with being algebraic. Does any one know if I remember this correctly?
Answer: An obvious thing to ask is what its Hausdorff dimension and box dimension are, although I can't give you an answer. Calculating the Hausdorff dimension of a set of numbers defined in terms of a restriction on continued fraction expansions has been a popular topic in ergodic theory lately, see for example:
http://www.informatik.uni-bremen.de/~mhk/papers/Texan.pdf
http://www.maths.qmw.ac.uk/~omj/hensley4.ps
http://www.jstor.org/pss/117986
However I am not aware of anyone's having studied this particular restriction.
Answer: The closure of this set in $[0,1]$ is exactly the subset $\mathcal C$ of all real numbers whose continued fraction expansions involve only different numbers. Rational numbers are fine for membership in $\mathcal C$ if they have a continued fraction expansion
involves only distinct integers.
The set $\mathcal C$ is a Kantor set and it is also the closure of all real numbers whose continued fraction is a permutation of $\mathbb N$ with finite support (identity outside a finite set).
Answer: First some comments on the previous comments: Let $\theta=[0,a_0,a_1,\ldots]$ have convergents $p_i/q_i$. Then the connection between the $a_i$ and how well $p_i/q_i$ approximates $\theta$ is given by the following inequality:
$$\frac{1}{q_k^2(a_{k+1}+2)} < |a-p_k/q_k| \le \frac{1}{q_k^2a_{k+1}}.$$
This is taken from Khintchin's book on continued fractions, Page 36 (with a typo corrected.)
This is why Roland's statement is true: For example you can make $\theta:=[0,a_0,a_1,\ldots]$ close to the number $2/3=[0,1,2]$, by taking for  $\theta$ something like $[0,1,2,10^{100},\ldots]$.
As for Roth's theorem, if for some $\epsilon>0$ and for  infinitely many $k$ it holds that $a_{k+1}\ge q_k^{\epsilon}$, then by the above double inequality, Roth's theorem is violated, and $\theta$ can't be algebraic. But consider $[0,1,2,3,\ldots]$. Here the $q_k$ are bounded below by the Fibonacci sequence and the $a_k$ grow linearly, so there is no problem with Roth's Theorem. For all I can see (SEE THE COMMENTS BELOW!!), $[0,1,2,3,\ldots]$  might be an algebraic number, although that might be ruled out by some of Lang's conjectural strengthenings of Roth.
Comment: But $[0,1,2,3,\dots]$ is known to be a transcendental number!
Comment: Oh!! Do you have a reference? Are you sure you're not thinking of Champernowne's constant .1234.... ?
Comment: A classical (Lambert-Euler) continued fraction is $(e-1)/(e+1)=[0;2,6,10,14,\dots]$ (Lang's or Cassels's books on Diophantine approximations). In a similar way one can show that $[1,2,3,\dots]$ is of the form $I_0(2)/I_0(1)$ (or something like this) for Bessel's functions. The algebraic independence of the numerator and denominator in this quotient was shown by C. Siegel already in 1929.
Comment: There is nothing to do with Roth's theorem! The number $[0,1,2,\dots]$ has irrationality exponent 2 (as algebraics) and even the exact quality of its approximation by rationals is known (see B.\,G.~Tasoev's paper [Math. Notes 67 (2000), 786--791]). There are no such results for algebraic irrationalities of degree $>2$.


Know what references an object

Question: I have an object which implements reference counting mechanism. If the number of references to it becomes zero, the object is deleted.
I found that my object is never deleted, even when I am done with it.  This is leading to memory overuse.  All I have is the number of references to the object and I want to know the places which reference it so that I can write appropriate cleanup code.
Is there some way to accomplish this without having to grep in the source files?  (That would be very cumbersome.)
Comment: Most classic fault: you have a cycle of references :x Good luck figuring it out!
Answer: A huge part of getting reference counting (refcounting) done correctly in C++ is to use Resource Allocation Is Initialization so it's much harder to accidentally leak references.  However, this doesn't solve everything with refcounts.
That said, you can implement a debug feature in your refcounting which tracks what is holding references.  You can then analyze this information when necessary, and remove it from release builds.  (Use a configuration macro similar in purpose to how DEBUG macros are used.)
Exactly how you should implement it is going to depend on all your requirements, but there are two main ways to do this (with a brief overview of differences):

store the information on the referenced object itself

accessible from your debugger
easier to implement

output to a special trace file every time a reference is acquired or released

still available after the program exits (even abnormally)
possible to use while the program is running, without running in your debugger
can be used even in special release builds and sent back to you for analysis

The basic problem, of knowing what is referencing a given object, is hard to solve in general, and will require some work.  Compare: can you tell me every person and business that knows your postal address or phone number?
Answer: One known weakness of reference counting is that it does not work when there are cyclic references, i.e. (in the simplest case) when one object has a reference to another object which in turn has a reference to the former object. This sounds like a non-issue, but in data structures such as binary trees with back-references to parent nodes, there you are.
If you don't explicitly provide for a list of "reverse" references in the referenced (un-freed) object, I don't see a way to figure out who is referencing it.
In the following suggestions, I assume that you don't want to modify your source, or if so, just a little.
You could of course walk the whole heap / freestore and search for the memory address of your un-freed object, but if its address turns up, it's not guaranteed to actually be a memory address reference; it could just as well be any random floating point number, of anything else. However, if the found value lies inside a block a memory that your application allocated for an object, chances improve a little that it's indeed a pointer to another object.
One possible improvement over this approach would be to modify the memory allocator you use -- e.g. your global operator new -- so that it keeps a list of all allocated memory blocks and their sizes. (In a complete implementation of this, operator delete would have remove the list entry for the freed block of memory.) Now, at the end of your program, you have a clue where to search for the un-freed object's memory address, since you have a list of memory blocks that your program actually used.
The above suggestions don't sound very reliable to me, to be honest; but maybe defining a custom global operator new and operator delete that does some logging / tracing goes in the right direction to solve your problem.
Comment: One day a student came to Moon and said, "I understand how to make a better garbage collector. We must keep a reference count of the pointers to each cons." Moon patiently told the student the following story: "One day a student came to Moon and said, 'I understand how to make a better garbage collector...'" (http://www.serve.com/cmtan/buddhism/Lighter/aikoans.html, http://en.wikipedia.org/wiki/Hacker_koan)
Comment: The simplest case is an object that has a reference to itself. :) (This isn't a pathological case either, consider any class that uses `delete this`.)
Answer: I am assuming you have some class with say addRef() and release() member functions, and you call these when you need to increase and decrease the reference count on each instance, and that the instances that cause problems are on the heap and referred to with raw pointers. The simplest fix may be to replace all pointers to the controlled object with boost::shared_ptr. This is surprisingly easy to do and should enable you to dispense with your own reference counting - you can just make those functions I mentioned do nothing. The main change required in your code is in the signatures of functions that pass or return your pointers. Other places to change are in initializer lists (if you initialize pointers to null) and if()-statements (if you compare pointers with null). The compiler will find all such places after you change the declarations of the pointers.
If you do not want to use the shared_ptr - maybe you want to keep the reference count intrinsic to the class - you can craft your own simple smart pointer just to deal with your class. Then use it to control the lifetime of your class objects. So for example, instead of pointer assignment being done with raw pointers and you "manually" calling addRef(), you just do an assignment of your smart pointer class which includes the addRef() automatically.
Comment: Using objects which manage resources as an intrinsic part of their natural lifetime is called RAII.
Comment: No reasonable person could disagree with that.
Answer: I don't think it's possible to do something without code change. With code change you can for example remember the pointers of the objects which increase reference count, and then see what pointer is left and examine it in the debugger. If possible - store more verbose information, such as object name.
Answer: I have created one for my needs. You can compare your code with this one and see what's missing. It's not perfect but it should work in most of the cases.
http://sites.google.com/site/grayasm/autopointer
when I use it I do:
util::autopointer aptr=new A();

I never do it like this:
A* ptr = new A();
util::autopointer aptr = ptr;

and later to start fulling around with ptr; That's not allowed.
Further I am using only aptr to refer to this object.
If I am wrong I have now the chance to get corrections. :) See ya!

Know what references an object


About high-symmetry points in the first Brillouin zone of space group R-3m

Question: I want to figure out the high-symmetry points in the first Brillouin zone of space group R-3m (166). For example, there are points K and M just like the bandstructure in this paper.
But I can't figure out each component of kx, ky, kz from Bilbao Crystallographic Serve.
Can anyone help me? I am not fimiliar about space groups. Thanks in advance!
Comment: This paper - [High-throughput electronic band structure calculations: Challenges and tools](https://www.sciencedirect.com/science/article/pii/S0927025610002697) - lists the high-symmetry points and the suggested k-path for band structure plots for all the Bravais crystals.
Answer: As described on the paper, the system presents a hexagonal unit cell. From the paper recommended by @MathJacky (if you don't have access to the published paper, there is an arXiv version), we have that the Brillouin zone lattice is:

And the high symmetry points $\Gamma$, $A$, $H$, $K$, $L$, and $M$ can be calculated as:

With that information, you can generate the path between continuous points.


Constant Power to Garbage Disposal

Question: I put in a new counter top and had to take off my garbage disposal to do so. When I hooked everything back up and flipped the switch nothing happened. I grabbed my wire tester and touched the wire and there was a pop and some smoke from the disposal. Now weather the switch is on or off I have constant power to the garbage disposal. Everything else that is on that breaker works just fine. What could be the problem? And how can I fix this?
Comment: If both wires were hot as you suggest, and if they were on different legs, then you may have inadvertently supplied your garbage disposal with 200+ volts. That would explain the pop sound and the magic smoke. Unfortunately I think it's unlikely you'll be able to service it yourself without causing further damage and/or a hazardous piece of equipment once reinstalled. It might be time to get a new one, and double check all those wires to see which circuits they're all coming from before connecting anything to them.
Comment: What sort of "wire tester" do you have?
Comment: Just a standard tester. Plastic end, I have used it for years.
Comment: You mean a non-contact voltage tester? The kind that lights up and/or beeps when you hold its tip near a live wire?
Comment: Yes a non contact voltage teste .
Comment: Have you tried replacing the switch?
Comment: Yes, it seems like both wires connected to the switch both have power.
Comment: Does power come to the switch first, or the disposal first?
Comment: Power goes to the switch first.
Answer: First the bad news. If smoke came from the disposer the windings are burnt and it's never going to work. Unless when you connected the power cord (the tail), it was made up incorrectly. When you "touched the wire"  most likely some of the fine strands were loose and caused a "pop".
So first take the disposer out from under the sink and check the connections and determine if the power cord was installed properly (you should be able to see the burns if it's at the connection point).  Then verify that you haven't burned up the windings (they should smell burnt). If there is any hint that the windings are burned return and replace the disposer.
Then check the breaker and make sure the power is on. Then use your tester to check the outlets under the sink. The outlet below the sink is usually a duplex and one side should be continually hot and the other should be on the switch above the counter by the sink. If you don't get power there start backtracking the circuit find the damaged location and of course repair the part.
If everything seems to be ok. Reinstall the disposer.
I know you probably would like to know another way to check the windings on the disposal. Unfortunately I can't recommend a way to check it safely without a workbench or a good understanding of how to check the windings with an ohmmeter.
If you really want to know that you need to take it to a motor specialist or the manufacturer's recommended warranty shop.
Stay safe and good luck.

Constant Power to Garbage Disposal


Mosaic Dataset - Gray and White areas

Question: I'm trying to add high resolution orthoimagery from the USGS to a mosaic dataset in arcMap. When I "Add rasters to mosaic dataset" most of the rasters load in fine, but some have strips of white area and other places are sort of grey, low contrast. I checked Update Overviews. Please see the image below as an example of the issue. Also, as you zoom in the grey/white areas go away. Any ideas?
Comment: Is this over a military base or other critical infrastructure element?  USGS data is downsampled or redacted as appropriate for homeland security purposes.
Comment: I've no idea concerning the grey ones but the white areas could be a result of the maximum downloadable images. Please have a look at the Mosaic Dataset Properties ==> Defaults ==> Download Properties ==> Maximum Number of Items Downloadable per Request
Comment: It is not over any critical infrastructure. The download settings didn't help. I went ahead and built footprints, seamlines, and rebuilt the overviews and all the white/gray areas moved to different locations.
Answer: From Esri Technical Support: "The caching process sometimes creates blank and/or white tiles when using Mosaic datasets."
Their recommendation at https://support.esri.com/en/technical-article/000011325 is to bump the number of maximum number of rasters per mosaic dataset from the default of 20 to 100 (right click mosaic dataset > properties > defaults tab > Maximum Number of Rasters per Mosaic). This worked for me for WorldView-2 imagery.
Instead of changing the maximum number of rasters per mosaic default value, clicking the Dynamic Range Adjustment button also worked for me (in Pro this is: highlight mosaic dataset in Contents: Mosaic Layer ribbon > Appearance > DRA (next to Stretch Type).

Mosaic Dataset - Gray and White areas


Is it possible to patent an operational workflow in EU?

Question: I am designing a process something like "order online and collect" or "load parcels to a van in the order of the destinations to make unloading easier" (if these were novel). Is it possible to patent something like this in the EU?
Answer: It depends on what kind of operational workflow you want to be patented.
In short, a workflow/process/method is patentable, if it has a tangible / measurable result, like a pizza recipe (take a dough, make it flat, put specific ingredient on it, heat it up to 180°C for 20-40 minutes).
In general, European patents shall be granted for an invention, in all fields of technology, provided it is new, involve an inventive step and is susceptible of industrial application.
Novelty and inventiveness will be discussed in the application process. Industrial applicability is almost always given.
You have to make sure your workflow is in any field of technology.
The following list of categories shall not be regarded as inventions:

discoveries, scientific theories and mathematical methods;
aesthetic creations;
schemes, rules and methods for performing mental acts, playing games or doing business, and programs for computers;
presentations of information.

And even if your workflow avoids the above-listed categories, European patents shall not be granted in respect of:

inventions the commercial exploitation of which would be contrary to "ordre public" or morality;
plant or animal varieties or essentially biological processes for the production of plants or animals (but does not applies to microbiological processes or the products thereof);
methods for treatment of the human or animal body by surgery or therapy and diagnostic methods practised on the human or animal body (but does not apply to products, substances, for use in any of these methods).

If your workflow avoids all the categories above, it should be disclosed in sufficiently clear and complete manner for it to be carried out by a skilled person.
On softwares: Softwares or programs for computers are not patentable per se, but computer implemented inventions are potentially patentable. That is, you can claim a computer program, which if executed on a computer, carries out a claimed method.
Comment: @EricS As long as the algorithms produce a technical effect, namely solve a technical problem, they are patentable. But in addition to that, the claims shall be explicitly limited to algorithms run by technical devices, otherwise the claims may indeed fall within the category you mentioned because they encompass the algorithm as a mental act. Even if complex, there is case law at the EPO stating that it does not matter how complex the operations are, if they are not limited to technical devices they still can encompass the mental act.
Comment: A "workflow" as described in the question sounds suspiciously like an algorithm. I believe algorithms are unlikely to be granted as patents in the EU but I could be wrong. Indeed, the "workflow" should be unpatentable based on your answer since it well might fall under "schemes, rules and methods for performing mental acts, playing games or doing business, and programs for computers". Could you clarify this in your answer?
Comment: Run this search to see several  examples of granted patent by the EPO that might fall into what the OP is thinking about  https://patents.google.com/?q=(Delivery+route)&country=EP&status=GRANT some are about physical items being delivered efficiently.
Comment: @EricS moving something around, even by hand, is enough to not fall into "mental acts" for example.
Comment: Human contraception is not an example for missing industrial application as such. You're probably referring to the epo boa decision T 0074/93. However, that decision was about applying a contraceptive (manually) to the uterus. The argument against industrial applicability was that there is no industry for doing that. So contraceptives as such are industrially applicable.
Comment: @DonQuiKong contraceptives have been removed


Why is $M(X)=C_c(X)^*=C_0(X)^*$?

Question: Let $X$ be a a locally compact, separable and complete metric space.and $M(X)=\{$finite signed measures on $X\}$. Now I learned that $M(X)=C_c(X)^*$ i.e. it is the dual of continuous functions compactly supported in $X$. Now it seems $M(X)=C_0(X)^*$ as well (dual of continuous functions vanishing at $\infty$ as well. But why is that? Does it have something to do with the fact that $C_0(X)$ is the set of uniform limits of elements of $C_c(X)$?
Comment: Yes, because $C_0(X)$ is the completion of $C_c(X)$ and continuous linear functionals are uniformly continuous hence extends to completion.
Answer: If $X$ is a normed linear space and $M$ is dense subspace of $X$ then $M$ and $X$ have the same dual. This is because any continuous linear functional on $M$ has a unique extension to a continuous linear functional on $X$.
Comment: So the bijection between the duals is given by associating to the continuous linear functional on M it's extension on X right?
Comment: Yes, the inverse of the unique extension is the restriction map: Any continuous linear functional on $X$ restricted to $M$ is a continuous linear functional on $M$. @roi_saumon

Why is $M(X)=C_c(X)^*=C_0(X)^*$?


Audience targetted link hidden from everyone

Question: I have 4 manually created links across my top link bar. I want to use Audience Targetting to allow certain people to see it and to hide it from everyone else (I know audience targetting is not security, I have sorted permissions also).
However, with my SharePoint group assigned as the target audience it now hides the link from EVERYONE, whether they're a member of the group or not.
Comment: Is User profile serivces configured on the servere?
Answer: Are you trying to hide/show links in top navigation bar ?
If so, you can assign group level permissions to page which you want to hide .
i.e.

click edit page in site action menu
select page tab in command bar and click on Page permissions from ribbon
it will redirect you to permissions page and click on stop inheriting permissions and select the group for which you dont want to display that page and click on remove user permissions.

So that that page will not be displayed to particular selected group users.


Running Simple Maven Web-App Inside Eclipse

Question:
When I run a simple web-app consisting of just a simple servlet and a simple jsp page I do not get "run as - on Server" option in Eclipse. I can run that on command line successfully using Jetty Plugin. I am comfortable doing Maven stuffs from Command line but am having problem when using Eclipse.
Can someone point to some link which shows how to use maven with Eclipse. I saw Sonatype site but am not satisfied.
Also why is Ear packaging recommended for maven(I heard so)?

I am using Eclipse Indigo (not WTP) & m2e & Maven 3.
UPDATE - I have configured both Tomcat 6 and Glassfish 3 in Eclipse and they work for non-maven projects. Im trying to run this simple maven -web project in Tomcat
"The problem is that when I create a non-maven web-project in Eclipse the contents go inside the folder "Web-Content" which is recognised by Eclipse and thus I can have an option like Run on Server and am also able to add projects on Server inside Eclipse.
But for maven web-projects the contents(and web.xml) reside in src/main/webapp and is thus not recognised by Eclipse.
UPDATE 2 - I created maven project by selecting "maven-archetype-webapp" archetype. Created a simple Servlet and added its entries inside src/main/webapp. I run "maven install" and the build was successful. Packaging is war. But am not able to add project to the server like a normal web-project
Answer:
You should configure server instances in eclipse to be able to run on them from eclipse
You can generate eclipse project files by maven,  or use one existing maven plugins for eclipse ( the all suck, but some suck more ;) )
Who recommends this?  Maven does not force you to use EAR packaging - you need it if you
like to deploy application consisting of multiple web modules with some EJB modules as single artifact.

PS:  I would recommend  to use IDEA -  even free community edition is way better than eclipse
Comment: I have configured both Tomcat and Glassfish and am able to run non-maven web projects in them. Can you be more specific pls how to run it inside eclipse


Why is Systema used for American secret agents training?

Question: Following this article and the embedded video. We can see that American secret agents are trained to use Systema techniques. What is it? Why not Krav Maga for instance? As can be seen there are some other solutions for the drill with the knife and gun in Krav Maga. What other techniques are trained for secret agents?
Comment: First thing to realize is that there's no official support by the government or the armed forces for any particular martial art. Most branches of the military have their own brand of hand-to-hand combat training. You can find pictures and videos of U.S. military training in Taekwondo, Judo, karate, and even ninjutsu. Who cares? It's just what one small, local group decided to do. It should not imply effectiveness or a preference for any particular martial art.
Answer: There is no known relation between the demonstrator in the video and American "secret agents". This connection is insinuated in the TV show:

demonstrates how Secret Service agents could eliminate a threat.
demonstrates how the Secret Service can up the ante to guard the protect team and spare innocent bystanders

Basically, these are the kinds of techniques that can/should be used. There is no evidence the US Secret Service studies Systema in particular.
Comment: Given who they routinely guard, I would be surprised if there are *any* accurate representations of what/how they train in the public sector.


Connect car speakers to 2 separate head units

Question: How can i connect 4 car door speakers to 2 separate head units I'm thinking of using diodes any one has any clues please provide a diagram with type and rating of the diodes or any possible alternatives thank you
Comment: Diodes are not going to help you here.
Comment: Welcome to Motor Vehicle Maintenance & Repair! What is the ultimate goal of hooking the two head units into the speakers?
Comment: Diodes in the audio path are going to make the system sound terrible.
Answer: There are switches available for swapping between sets of speakers : check out the HiFi world - you can use these to switch between two head units.
Depending on the type of switch you may be able to switch only the supply from either head unit and common the relevant returns. However, if both head units are powered then you may have interference issues.


How to keep data in memory in asp.net MVC2 web app?

Question: I have a MVC2 web app without a database that is being hosted by IIS7. The model is a custom index of some properties of a filesystem, and right now the index is stored in memory. The problem is that on a regular basis, the data stored in memory gets released, and the index must be recreated. Maybe the best solution would be to serialize the index object and load it when the index gets released, but it would be much simpler if I could prevent the data from going anywhere.
Comment: Why can't you just use a database?
Answer: Anytime there is no activity for a certain amount of time or IIS recycles the process you are going to lose any data in memory so if you require that information, you are going to need to persist it in some way and retrieve it when the memory is cleared.
Have you considered having this data in a persistent xml file or serialized to a file on the server?
If it gets cleared from memory you could check for that case and then just reload the file back into the application cache.
Answer: To allow the data to survive you are going to have to move it outside the pervue of IIS - and that means either an XML store (in App_Data, Isolated Storage or somewhere else), a Database, or a service.
I mention a service because, while its potentially overkill, I imagine that there is some caretaking that needs to be done with this data as well?  Removing stale entries, adding new entries and generally taking care of housekeeping?  Putting all of that into a service allows the data to persist outside of the limits of IIS (but beware how far this is taken, as at some point you may just be reinventing some aspects of a database server anyway).


When is the Eilenberg-Moore category of a monad on an ind-category itself an ind-category?

Question: I have a monad on an ind-category (specifically, my ind-category has a monoidal structure and I have an algebra object, so the monad is tensoring with it). It would be very useful in my work if the Eilenberg-Moore category of the monad it itself an ind-category. Is there a known criterion for the monad for this to be true? Further, is there a handy description for a generating sub-category of modules? I'm also happy to use the dual case of a comonad on a pro-category if there's a break in symmetry that makes that an easier question.
Comment: It is certainly true that the Eilenberg–Moore category of a finitary (i.e. filtered-colimit preserving) monad on an accessible category (i.e. Ind-category) is itself accessible (i.e. an Ind-category).
Comment: I would guess that the conjecture for monads on ind categories is correct (exactly) when the functor part of the monad preserves filtered colimits. Dually with comonads on pro categories when the functor preserves cofilteed limits. Maybe even comonads on ind categories if filtered colimits are preserved.
Comment: @varkor you should write this as an answer. I don't think there is a better criterion.
Answer: Let $T$ be a monad on an accessible category (i.e. an $\mathbf{Ind}$-category). If the underlying endofunctor of $T$ is finitary (i.e. preserves filtered colimits), then the Eilenberg–Moore category of $T$ is also accessible. This is proven (in slightly more generality) in Theorem 2.78 of Adámek–Rosický's Locally presentable and accessible categories, for instance.
Comment: @SimonHenry: I realised I made a mistake after posting the comment. What I meant was that I suspect in this case the Eilenberg–Moore category is the $\mathbf{Ind}$-completion of the completion under coequalisers of T-algebra homomorphisms, of the subcategory of the Kleisli category of the monad on the finitely presentable objects.
Comment: Thank you very much for that (and for the helpful reference). The suggestion for the generating category in your comment is also a useful direction to pursue.


What is the definition of the "solar mixing ratio"?

Question: What is the definition of the "solar mixing ratio"?
Specifically, I'd like to know why the ratio of H2 and He is 0.84 and 0.16 at the "solar mixing ratio" as shown in Table I in The Galileo Mission.
Answer: An answer which explains it possibly, but remains speculation as I don't find the term explained:
Taking the pristine abundance of atoms, from which the sun formed (thus solar mixing) gives you a ratio of H and He atoms of 92% hydrogen to 8% helium. Converting that to the place and phase where we have molecular hydrogen (H2), gives a molecular mixing ratio of 83% hydrogen (H2) and 13% helium (He) - which is pretty close to the values given there. They probably use another source with slightly different numbers for the pristine elemental abundances than this wikipedia article.
Thus I consider it likely that they compare molecular abundances. They compare the abundances or ratios you would see, if you took the pre-solar nebular without any chemical segregation and formed the giant planets with the one measured by their spectrometers when actually looking at the atmospheres of the planets.
Answer: The mixing ratio is the ratio of the number of moles of species $x$ to the total number of moles in the gas considered. i.e. it is a ratio of number densities.
Reading a page or so beyond the Table you refer to suggests that the "solar mixing ratio" is what you would expect the mixing ratio to be if the gas that made up the planet had the pristine initial solar elemental abundance ratios (i.e. the elemental abundances in the protosolar nebula; it can't be the chemical make-up of the Sun, since the Sun does not contain appreciable amounts of any molecules). The isotopic solar mixing ratios also must be the isotopic number ratios inferred for the protosolar nebula, rather than the present-day Sun, since there is basically no Deuterium left in the Sun (it is entirely burned during pre main sequence evolution).
The reasons they are not are complex and associated with chemical fractionation in the protoplanetary disk, the formation process of the planet, diffusion processes after the planet has formed and probably many other effects of which I am only vaguely aware.


How can I remotely connect via ssh and reuse this connection for other apps without asking for the original credentials?

Question: There's a remote Ubuntu container that I can access via SSH using a one-time connection code (username-password). I'm using Windows, and don't have much rights on the container itself. So I'm trying to do this without changing any settings on the container. I can create a SSH connection just fine to port 2222  (specifically) on the remote host.
However, the app I'm trying to use (remote debugging in Visual Studio, not very important), is apparently not compatible with single-use passwords. Let's assume that to be true.
So what I had in mind was opening a SSH connection from my computer to the host using the one-time password, create some kind of tunnel, and then have the application re-use that connection without having to provide any username or password.
I tried using Putty to forward a local port (2345) to the remote port (2222), but after that I can't SSH to localhost:2345 without any creds (and end up on the remote server like I had hoped).
After some reading, I unfortunately still don't have a great understanding of SSH tunnels. Is there a way to accomplish what I'm trying to do?
Thanks for any help.
Answer: I don't know if this is doable with putty but OpenSSH has the -M command line switch which opens local socket for connection multiplexing and allows all subsequent connections to conect using just that without any additional authentication.


What's "scan column" and why do we name it like this?

Question:
What's "scan column" and why do we name it like this?
Why not just call 'left column' or 'right column'?
Comment: How accepted and well-known is the term 'scan column'?
Comment: is the source of the image http://webstyleguide.com/wsg3/6-page-structure/3-site-design.html ?
Answer: It sounds to me like a column the user scans with her sight, like for example a navigation menu.
Jakob Nielsen said years ago,  in one of his alertboxes about how users read in the web, that users scan page content as opposed to fully reading it.
Also, in forms it is recommended to left-align the labels because if they are right-aligned the users cannot scan them. In fact, not being able to scan it is what makes columns of centered text so horrid.
It refers to rapidly browsing with the sight.
Answer: I think it's because they are columns that are mainly used to scan for information or navigation. They don't provide content.
Example: this usability site has a picture of which areas are mainly read in a site.
But I don't think that those terms are that popular. Search for "left scan column" in google will only give you 217 results...
Comment: Looks like it's a free definition made by Lynch/Horton to name the columns. I.e. I heard those columns called "context columns" or mostly it's only one column, displaying additional information related to the main content and/or ads.
Answer: As to why they are named scan columns, Web Style Guide Online explains:

"... much as scan columns have been used in print publications for a century or more."

after stating that (scan columns)

"organize navigation links and other peripheral page elements."


Where does "amen" come from?

Question: Watched a video on YouTube. My first mistake. They were talking about the word "amen" coming from a Roman god Amen-Ra, I think. I thought "amen" just meant "to agree". How do people research this stuff to come up with what "amen" means anyway.
Comment: I'm voting to close this question as off-topic because it is about the English language.
Comment: -1 for lack of research effort. You should not get all information on Youtube. Youtube may help provide the basic introduction, but validation and verifiability are also important.
Comment: It was not a Roman God, but an Egyptian God which caused the confusion.  Next you'll ask about the "son" of God vs the "sun" God - only in English are they the same.  'filius' is not easy to confuse with 'sol'.  Most of those YouTube video are junk - as are the ones about Freemasons :D (insert plug here)
Comment: Even if it did come from an Egyptian pagan culture, would that be important? It almost certainly had a completely secular meaning by the time it was used in the written text. Would there be other serious ramifications of any particular etymology?
Comment: Wikipedia does a good job of answering this: http://en.wikipedia.org/wiki/Amen#Etymology
Comment: Glad I asked the question. I just really wanted to know dose it mean "I agree" that's all. And this is my research effort not YouTube.
Answer: The use of the "Amen" comes from the last word of the most used Bible Translations.
The word itself in the original Greek is Amēn Ἀμήν⧽ Amen from the Hebrew which means "true".
The following is a quote from Smith's Bible dictionary.

A'men. Literally "true" and used as a substantive, "that which is true",. "truth", Isa_65:16, a word used in strong asseverations, fixing, as it were, the stamp of truth upon the assertion which it accompanied, and making it binding as an oath. Compare Num_5:22.
In the synagogues and private houses, it was customary for the people or members of the family who were present to say "Amen" to the prayers which were offered. Mat_6:13; 1Co_14:16. And not only public prayers, but those offered in private, and doxologies, were appropriately concluded with "Amen". Rom_9:5; Rom_11:36; Rom_15:33; Rom_16:27;
2Co_13:14; etc.

When Christianity spread the use of saying A'men was used in the same way as a way of validating the word as the word of God, and is still used in The Baptist church as a way of affirming what was said as being true.
Answer: The mere fact that this youtuber thought Amen-Ra was a Roman God speaks greatly about the quality of his videos. Some unbelievers seem to see a pagan behind everything a Christian does.

Old English, from ecclesiastical Latin, from Greek amēn, from Hebrew
  'āmēn 'truth, certainty', used adverbially as expression of agreement,
  and adopted in the Septuagint as a solemn expression of belief or
  affirmation.
Answer: Amen is a derivative from the Hebrew verb aman "to strengthen" or "Confirm".

The word Amen is one of a small number of Hebrew words which have been
  imported unchanged into the liturgy of the Church, propter sanctiorem
  as St. Augustine expresses it, in virtue of an exceptionally sacred
  example. "So frequent was this Hebrew in the mouth of Our Saviour",
  observes the Catechism of the Council of Trent, "that it pleased the
  Holy Ghost to have it perpetuated in the Church of God". In point of
  fact St. Matthew attributes it to Our Lord twenty-eight times, and St.
  John in its doubled form twenty-six times. As regards the etymology,
  Amen is a derivative from the Hebrew verb aman "to strengthen" or
  "Confirm". - Cf. Amen | New Advent.

And
AMEN ("So is it," or "So shall it be")

A word used at the conclusion of a prayer, or in other connections, to
  express affirmation, approval, or desire. It is derived from the Old
  Testament Hebrew, and is perhaps the most widely known word in human
  speech; being familiar to Jews, Christians, and Mohammedans. It occurs
  thirteen times in the Masoretic text of the Old Testament, and in the
  Septuagint in three additional passages (Jer. iii. 19, xv. 11, Isa.
  xxv. 1). From these passages it is possible to trace in part the
  gradual development of Amen from an adjective (or, according to Barth,
  "Die Nominalbildung in den Semitischen Sprachen," 5c, 7b, a noun,
  meaning "firmness," "certainty") into an indeclinable
  interjection. - Cf. AMEN | JewishEncyclopedia.com.

Where does "amen" come from?


When is the right time to meditate?

Question: I was watching "how to meditate" in internet. In one video, a master said, not to meditate in the night in dark. If one meditates in dark, they should light candle or incense stick. The reason he gave was, one meditating in night will be possessed by spirits. Is this true? When is the right time to meditate.
Answer: The right time is whenever you can, wherever you are, starting if possibile with a calm mind. Try to maintain a constant practice, whichever technique do you follow. As a reminder read Webu Sayadaw's To Light a Fire.
Answer: I agree with robermann's comment, and if I am to add something to it, it is this.
We have to have a strong belief that the path to Nibbana exists in this Dhamma. One who has that confidence meditates carefully. Does it in an orderly manner. This requires some time. It does not happen in a day or two. Not in a week, in a month or two or in a year or two. We cannot restrict it to a short period.
With metta....

When is the right time to meditate?


How to kill people who are standing in the sun?

Question: I'm trying to find a way to make it so when someone is outside during the day they get killed. I've searched for a long time and I've tried many different things, but they end up killing you even if you're safe.
Comment: Is this for an adventure map, or for a map that can be affected by the player to a huge degree (basically, will they be able to build their own house, or cover, or is it set for them?)
Comment: What do you mean with "they end up killing you even if you're safe"?
Comment: So I would guess emulate the Zombie/Skeletons? If you stand somewhere where theres nothing over your head you die? (They do by catching fire, but I guess you could up the damage if you hook into some 'IsStandingInSun' function?)
Comment: Try checking if there is no block above a player.
Answer: It might seem like the best idea to use a daylight sensor for this, but that has lots of little problems, like being visible when placed at the player's location, potentially overwriting blocks (like grass), not being able to check its output level directly, …
Instead I would suggest simply checking for air in a column from the player's head to the build limit.
First make sure that you have a column of air at a known position, for example 0 0 (preferably in the spawn chunks):
/fill 0 0 0 0 255 0 air

Whenever you now want to check if everything above the player is air, you just need to compare with partially relative coordinates:
execute if blocks ~ ~ ~ ~ 255 ~ 0 ~ 0 all run <command>

The downside of this is that all blocks except air protect a player, including glass, buttons, signs, …
Answer: Well, the initial part is easy. You could hook up a daylight sensor with a command block, to trigger the command to deal damage by way of applying the "Instant_Damage" effect constantly, or kill them outright
/effect <player> minecraft:instant_damage

/kill @p

Instant damage deals 3 damage each time it is applied, so it would require a clock setup.
However, I'm unaware of how you might need to go about checking for anyone who is "outside", beyond checking for players that are in an area that is of a certain light level, and you'd have to figure out what light level that is, as exposure to different light sources might throw this out a bit
Answer: I tihnk it would be best, if you would make a datapack for this. In a datapack you are able to have your own aliases, so you
are able to make one like 'not_protect', and then check if the area '~ ~2 ~ ~ 255 ~' contains something other than specified in your alias,
and then,at least, run your command.
Hope that this is what you've looked for.
Answer: Here's a proof of concept for a very lightweight solution. You need a marker entity, summoned as:
/summon minecraft:armor_stand -114.60 90.00 221.33 {Marker: 1b, Invulnerable: 1b, Invisible: 1b, Tags: ["sun-burner"]}

Then you need a repeating command block and two chained command blocks, which contain in order:
execute as @e[tag = sun-burner] at @p run spreadplayers ~ ~ 0 1 false @s
execute at @e[tag = sun-burner] run effect give @p[distance = ..1] minecraft:wither 5 1 true
# Just for fluff
execute at @e[tag = sun-burner] at @p[distance = ..1] run particle minecraft:flame ~ ~1 ~ 0.5 1 0.5 0.1 32 normal

This uses spreadplayers to teleport the marker to the surface at the position of the player, then checks whether it reached the player (i.e, the player is also on the surface). In that case case, the player gets withered.
Notes & caveats:

This works only for a single player. For multiple players, the best solution is probably to put the spreadplayers + detection code in a single function, and running the function as @a.
This won't reliably target players standing in water (not sure why it does work sometimes, but that could be a feature for you) or in lava (but I guess they'd have bigger fish to fry).
This won't target players in the air, which could be an issue.
The effect currently reaches one block into overhangs. You can remove this "bleeding" by changing the second command to read @p[distance = ..0.5], but I found it cool.


Printing a PDF from formula field data

Question: I am pretty new to salesforce. We are storing Barcode information in a formula field, and I need a lwc to print a pdf of the barcode from the formula field. I'd appreciate any help, thank you in advance.
Answer: There are several parts to what you're asking. Let's unpack it.
PDF generation in Salesforce has traditionally been done using Visualforce and Apex -- see the official documentation. Your LWC can call an Apex method that in turn generates the PDF.
Barcode generation in Visualforce has been covered here and here.
In LWC, you also have the option of client-side PDF generation using separate JavaScript libraries for the barcode generation piece and the PDF generation piece. You may not find as many examples out there, and there's more than one library to choose from on both fronts, so research and test accordingly. You may want to borrow from one of these LWC + client-side PDF generation examples: Example 1, Example 2
The best solution may depend on whether you plan to save the PDF back to Salesforce (in which case, consider using server-side Apex and Visualforce), or if it will be exclusively downloaded to users' local devices (which might be a good reason to keep execution on the client side, among other considerations).

Printing a PDF from formula field data


Empty tags with no questions

Question: With reference to the question Certain tags are totally empty when you select them?, I just spotted that there are some empty tags, do-my-homework and domyjobforme, which don't have any questions under them. I tried proposing a tag synonym that would remap do-my-homework to homework, but it doesn't work - any ideas please?
Comment: The empty tags will be removed automatically after 24 hours by the system, don't worry about them
Comment: Where did you see those tags? Browsing to non existent tag will always bring empty page e.g. http://stackoverflow.com/questions/tagged/I-do-not-exist however those tags won't appear anywhere.
Answer: As Yi noted, tags with no questions get deleted automatically after a bit.  Synonyms should really only be made for tags that are useful; crap questions should be closed or fixed and not retagged.
Comment: Ok fair enough :)

Empty tags with no questions


How are Bosons force-carriers?

Question: In QFT, the exchange of Bosons between certain particles is responsible for the effect of force. My question is how can exchanging bosons lead to a force. Is force defined differently in QFT? (Aka. Should I abandon my classical understanding of force as a contact or non-contact between objects, influencing their motion?)
Comment: *Is force defined differently in QFT?* Differently from what? It is not clear what you are comparing with and what your background is.
Comment: I'm talking about the classical definition of a force.
Comment: You certainly should abandon Newtonian mechanics when you move on to quantum one... and well before you get to QFT and how bosons carry force.
Comment: I do realize that leaving Newtonian mechanics is important. However, I'm asking how are bosons force-carriers? Then, I'm asking if force has a different, more precise definition other than the Newtonian one.
Comment: Force here implies potential, which is a static (low frequency) limit of waves. In QFT waves are quantized and become bosons. No mystery, but many concepts to put together.
Comment: It seems to me that we have just kicked the can down the road in talking about force. To say that the force between particles is due to an exchange of bosons is moving the mystery of force down to a new set of particles/entities. It's like the 17th century notion of consciousness being ascribed to a homunculus, a tiny man living inside our heads...who had consciousness inside his head.
Answer: First define what you mean by "force carrier". It is not a standard term (except possibly in pop physics where it is never clearly defined). If the question is "do bosons have momentum?" then the answer is yes. If question is "do electrons exchange photons when they approach one another in free space?" then the answer is no. If the question is "do electrons interact via the electromagnetic field, and are excitations of that field an example of bosons?" then the answer is yes. If the question is "ok, how is the interaction between electrons described in quantum field theory?" then the answer is something like the following.
The interaction between a pair of charged particles is set out by noting that there are primarily two fields involved: the ones called Dirac field and electromagnetic (EM) field. The interaction can be understood in terms of energy and momentum exchange between each electron and the surrounding EM field, and the propagation of energy and momentum within the EM field. That exchange and propagation is written down mathematically as a complicated integral which cannot be done in one go, but can be expressed as a series of terms. Each term in the series involves the energy and momentum of one or more contributions to the total interaction. This contribution is often called a "virtual particle" (e.g. a "virtual photon") but you should notice (and never forget) the word "virtual" here. Virtual photons are not real photons. They are not even particles. They don't propagate like particles (their quantum amplitude decays exponentially; each one is entirely confined within one interaction), and their energy-momentum involves a combination of energy and momentum that no real photon could ever have. The entities called virtual photons are contributions to a calculation; they help us track energy and momentum and other conserved quantities such as electric charge. They are bosons (this means they have a mathematical property called commutation between certain basic operations in the mathematics).

How are Bosons force-carriers?


back button callback in navigationController in iOS

Question: I have pushed a view onto the navigation controller and when I press the back button it goes to the previous view automatically. I want to do a few things when back button is pressed before popping the view off the stack. Which is the back button callback function?
Comment: possible duplicate of [Setting action for back button in navigation controller](http://stackoverflow.com/questions/1214965/setting-action-for-back-button-in-navigation-controller)
Comment: Checkout this [solution][1] which retains the back button style as well.

  [1]: http://stackoverflow.com/a/29943156/3839641
Answer: William Jockusch's answer solve this problem with easy trick.
-(void) viewWillDisappear:(BOOL)animated {
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
       // back button was pressed.  We know this is true because self is no longer
       // in the navigation stack.
    }
    [super viewWillDisappear:animated];
}

Comment: This code is not only executed when user taps back button, but in every event the view is popped (e.g. when having a done or save button at the right-side).
Comment: Or when moving forward to a new view.
Comment: Doesn't mean the back button was the cause. Could be an unwind segue for instance.
Comment: I have a doubt, Why shouldn't we do this in viewDidDisappear?
Comment: This is also called when the user pans from the left edge (interactivePopGestureRecognizer). In my case, I'm specifically looking for when the user presses back while NOT panning from the left edge.
Comment: Is there a reason why you call the **super** function after the **if**? As far as I know, it is supposed to be called as the very first line. Look the answer at this post: http://stackoverflow.com/a/3348425/1035008
Answer: In my opinion the best solution.
- (void)didMoveToParentViewController:(UIViewController *)parent
{
    if (![parent isEqual:self.parentViewController]) {
         NSLog(@"Back pressed");
    }
}

But it only works with iOS5+
Comment: This technique can't distinguish between a back button tap and an unwind segue.
Comment: The willMoveToParentViewController and viewWillDisappear method does not explain the controller must be destroyed, didMoveToParentViewController is right
Answer: it's probably better to override the backbutton so you can handle the event before the view is popped for things such as user confirmation.
in viewDidLoad create a UIBarButtonItem and set self.navigationItem.leftBarButtonItem to it passing in a sel
- (void) viewDidLoad
{
// change the back button to cancel and add an event handler
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"back"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(handleBack:)];

self.navigationItem.leftBarButtonItem = backButton;
[backButton release];

}
- (void) handleBack:(id)sender
{
// pop to root view controller
[self.navigationController popToRootViewControllerAnimated:YES];

}

Then you can do things like raise an UIAlertView to confirm the action, then pop the view controller, etc.
Or instead of creating a new backbutton, you can conform to the UINavigationController delegate methods to do actions when the back button is pressed.
Comment: The `UINavigationControllerDelegate` does not have methods that are called when back-button is tapped.
Comment: This technique allows validation of the view controller's data and conditional return from the navigation controller's back button.
Comment: This solution breaks the edge swipe feature of iOS 7+
Answer: Maybe it's a little too late, but I also wanted the same behavior before. And the solution I went with works quite well in one of the apps currently on the App Store. Since I haven't seen anyone goes with similar method, I would like to share it here. The downside of this solution is that it requires subclassing UINavigationController. Though using Method Swizzling might help avoiding that, I didn't go that far.
So, the default back button is actually managed by UINavigationBar. When a user taps on the back button, UINavigationBar ask its delegate if it should pop the top UINavigationItem by calling navigationBar(_:shouldPop:). UINavigationController actually implement this, but it doesn't publicly declare that it adopts UINavigationBarDelegate (why!?). To intercept this event, create a subclass of UINavigationController, declare its conformance to UINavigationBarDelegate and implement navigationBar(_:shouldPop:). Return true if the top item should be popped. Return false if it should stay.
There are two problems. The first is that you must call the UINavigationController version of navigationBar(_:shouldPop:) at some point. But UINavigationBarController doesn't publicly declare it conformance to UINavigationBarDelegate, trying to call it will result in a compile time error. The solution I went with is to use Objective-C runtime to get the implementation directly and call it. Please let me know if anyone has a better solution.
The other problem is that navigationBar(_:shouldPop:) is called first follows by popViewController(animated:) if the user taps on the back button. The order reverses if the view controller is popped by calling popViewController(animated:). In this case, I use a boolean to detect if popViewController(animated:) is called before navigationBar(_:shouldPop:) which mean that the user has tapped on the back button.
Also, I make an extension of UIViewController to let the navigation controller ask the view controller if it should be popped if the user taps on the back button. View controllers can return false and do any necessary actions and call popViewController(animated:) later.
class InterceptableNavigationController: UINavigationController, UINavigationBarDelegate {
    // If a view controller is popped by tapping on the back button, `navigationBar(_:, shouldPop:)` is called first follows by `popViewController(animated:)`.
    // If it is popped by calling to `popViewController(animated:)`, the order reverses and we need this flag to check that.
    private var didCallPopViewController = false

    override func popViewController(animated: Bool) -> UIViewController? {
        didCallPopViewController = true
        return super.popViewController(animated: animated)
    }

    func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
        // If this is a subsequence call after `popViewController(animated:)`, we should just pop the view controller right away.
        if didCallPopViewController {
            return originalImplementationOfNavigationBar(navigationBar, shouldPop: item)
        }

        // The following code is called only when the user taps on the back button.

        guard let vc = topViewController, item == vc.navigationItem else {
            return false
        }

        if vc.shouldBePopped(self) {
            return originalImplementationOfNavigationBar(navigationBar, shouldPop: item)
        } else {
            return false
        }
    }

    func navigationBar(_ navigationBar: UINavigationBar, didPop item: UINavigationItem) {
        didCallPopViewController = false
    }

    /// Since `UINavigationController` doesn't publicly declare its conformance to `UINavigationBarDelegate`,
    /// trying to called `navigationBar(_:shouldPop:)` will result in a compile error.
    /// So, we'll have to use Objective-C runtime to directly get super's implementation of `navigationBar(_:shouldPop:)` and call it.
    private func originalImplementationOfNavigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
        let sel = #selector(UINavigationBarDelegate.navigationBar(_:shouldPop:))
        let imp = class_getMethodImplementation(class_getSuperclass(InterceptableNavigationController.self), sel)
        typealias ShouldPopFunction = @convention(c) (AnyObject, Selector, UINavigationBar, UINavigationItem) -> Bool
        let shouldPop = unsafeBitCast(imp, to: ShouldPopFunction.self)
        return shouldPop(self, sel, navigationBar, item)
    }
}

extension UIViewController {
    @objc func shouldBePopped(_ navigationController: UINavigationController) -> Bool {
        return true
    }
}

And in you view controllers, implement shouldBePopped(_:). If you don't implement this method, the default behavior will be to pop the view controller as soon as the user taps on the back button just like normal.
class MyViewController: UIViewController {
    override func shouldBePopped(_ navigationController: UINavigationController) -> Bool {
        let alert = UIAlertController(title: "Do you want to go back?",
                                      message: "Do you really want to go back? Tap on \"Yes\" to go back. Tap on \"No\" to stay on this screen.",
                                      preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
        alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { _ in
            navigationController.popViewController(animated: true)
        }))
        present(alert, animated: true, completion: nil)
        return false
    }
}

You can look at my demo here.
Comment: This is an awesome solution and should be baked into a blogpost! Seems to be overkill for what I am searching right now, but in other circumstances, this is sure well worth trying.
Answer: This is the correct way to detect this.
- (void)willMoveToParentViewController:(UIViewController *)parent{
    if (parent == nil){
        //do stuff

    }
}

this method is called when view is pushed as well. So checking parent==nil is for popping view controller from stack
Answer: I end up with this solutions. As we tap back button viewDidDisappear method called. we can check by calling isMovingFromParentViewController selector which return true. we can pass data back (Using Delegate).hope this help someone.
-(void)viewDidDisappear:(BOOL)animated{

    if (self.isMovingToParentViewController) {

    }
    if (self.isMovingFromParentViewController) {
       //moving back
        //pass to viewCollection delegate and update UI
        [self.delegateObject passBackSavedData:self.dataModel];

    }
}

Comment: Don't forget `[super viewDidDisappear:animated]`
Answer: For "BEFORE popping the view off the stack" :
- (void)willMoveToParentViewController:(UIViewController *)parent{
    if (parent == nil){
        NSLog(@"do whatever you want here");
    }
}

Answer: There's a more appropriate way than asking the viewControllers. You can make your controller a delegate of the navigationBar that has the back button. Here's an example. In the implementation of the controller where you want to handle the press of the back button, tell it that it will implement the UINavigationBarDelegate protocol:
@interface MyViewController () <UINavigationBarDelegate>

Then somewhere in your initialization code (probably in viewDidLoad) make your controller the delegate of its navigation bar:
self.navigationController.navigationBar.delegate = self;

Finally, implement the shouldPopItem method. This method gets called right when the back button is pressed. If you have multiple controllers or navigation Items in the stack, you'll probably want to check which of those navigation items is getting popped (the item parameter), so that you only do your custom stuff when you expect to. Here's an example:
-(BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
    NSLog(@"Back button got pressed!");
    //if you return NO, the back button press is cancelled
    return YES;
}

Comment: didn't work for me.. pitty because it's lean. "*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot manually set the delegate on a UINavigationBar managed by a controller.'"
Comment: This will unfortunately not work with a UINavigationController, instead, you need a standard UIViewController with a UINavigationBar in it. This does mean you can't take advantage of several of the automatic viewcontroller pushing and popping that the NavigationController gives you. Sorry!
Comment: I just used the UINavigationBar instead of the NavigationBarController and then it works fine. I know the question is about the NavigationBarController, but this solution is lean.
Answer: If you can't use "viewWillDisappear" or similar method, try to subclass UINavigationController. This is the header class:
#import <Foundation/Foundation.h>
@class MyViewController;

@interface CCNavigationController : UINavigationController

@property (nonatomic, strong) MyViewController *viewController;

@end

Implementation class:
#import "CCNavigationController.h"
#import "MyViewController.h"

@implementation CCNavigationController {

}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
    @"This is the moment for you to do whatever you want"
    [self.viewController doCustomMethod];
    return [super popViewControllerAnimated:animated];
}

@end

In the other hand, you need to link this viewController to your custom NavigationController, so, in your viewDidLoad method for your regular viewController do this:
@implementation MyViewController {
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        ((CCNavigationController*)self.navigationController).viewController = self;
    }
}

Answer: Here's another way I implemented (didn't test it with an unwind segue but it probably wouldn't differentiate, as others have stated in regards to other solutions on this page) to have the parent view controller perform actions before the child VC it pushed gets popped off the view stack (I used this a couple levels down from the original UINavigationController).  This could also be used to perform actions before the childVC gets pushed, too.  This has the added advantage of working with the iOS system back button, instead of having to create a custom UIBarButtonItem or UIButton.

Have your parent VC adopt the UINavigationControllerDelegate protocol and register for delegate messages:
MyParentViewController : UIViewController <UINavigationControllerDelegate>

-(void)viewDidLoad {
    self.navigationcontroller.delegate = self;
}

Implement this UINavigationControllerDelegate instance method in MyParentViewController:
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
    // Test if operation is a pop; can also test for a push (i.e., do something before the ChildVC is pushed
    if (operation == UINavigationControllerOperationPop) {
        // Make sure it's the child class you're looking for
        if ([fromVC isKindOfClass:[ChildViewController class]]) {
            // Can handle logic here or send to another method; can also access all properties of child VC at this time
            return [self didPressBackButtonOnChildViewControllerVC:fromVC];
        }
    }
    // If you don't want to specify a nav controller transition
    return nil;
}

If you specify a specific callback function in the above UINavigationControllerDelegate instance method
-(id <UIViewControllerAnimatedTransitioning>)didPressBackButtonOnAddSearchRegionsVC:(UIViewController *)fromVC {
    ChildViewController *childVC = ChildViewController.new;
    childVC = (ChildViewController *)fromVC;

    // childVC.propertiesIWantToAccess go here

    // If you don't want to specify a nav controller transition
    return nil;

}
Answer: This is what it works for me in Swift:
override func viewWillDisappear(_ animated: Bool) {
    if self.navigationController?.viewControllers.index(of: self) == nil {
        // back button pressed or back gesture performed
    }

    super.viewWillDisappear(animated)
}

Answer: If you're using a Storyboard and you're coming from a push segue, you could also just override shouldPerformSegueWithIdentifier:sender:.


Can I make a post just for curiosity?

Question: I wanted to ask if I can ask questions that arise only from my curiosity (example: I waste time doing random functions and create a problem out of nothing that seems interesting to me because it has a nice expression) or must all questions have rigorous context?
Comment: Ah yes, the gut reaction here is let's probably say "No" to curiosity. Shaking my head.
Comment: I say "Yes" to curiosity. Even simple patterns (e.g. why do some squares always end in these digits?) can lead to useful and sophisticated math concepts.
Comment: It is hard to know how to answer this question, because it is not clear what you mean by "I waste time doing random functions and create a problem out of nothing that seems interesting to me because it has a nice expression".  The answer to your question here is **probably** "No", but it is hard to say.  The general rule is that any question you ask should be something that is likely to come up naturally in some context, and therefore be of interest to other users.  It needs to be a *real* question.
Comment: The OP of this question asked the following [question seemingly based out of curiosity](https://math.stackexchange.com/questions/4847788/how-does-wolfram-find-the-closed-form-of-numbers) that is so good (it bizarrely claims that it "lacks context", which is shocking given the amount it does to interest the average reader!) that it merits a mention here. Questions like that, even slightly localized ones, will be a very beneficial addition to this site.
Comment: There was a similar post to this asked on [Meta Stack Exchange](https://meta.stackexchange.com/questions/164436/is-there-a-rule-of-thumb-for-objective-questions-asked-out-of-curiosity). Pretty much the thumb rule there is : you're asking a question either because you want to use the result or you want to gain better understanding of a concept. Such questions are also likelier to be of interest to other experienced users, whereas casual doodling typically leads to a very localized question.
Comment: ME users will assume such questions are homework and close them. You will be required to explain your motivation for it and where it came from. "I randomly created that problem. The motivation is that it seems interesting to me." is not enough to make them believe it is not homework.
Comment: I don't know what you mean by rigorous context, but if I interpret "rigorous" as "mathematically correct" then *no*, you can very well have non-mathematical context. Pouring liquids optimally into cups, covering cricket grounds with football fields, modified lotteries, dividing labour among various areas of an industry, that's all real life applications and can be "context" for an actual mathematical question you want to ask, as long as you have intentions to use/implement your results in that field.
Comment: @Efesto, I sometimes posted questions of this nature (until my question ban). And some went well, some went horribly, some I deleted. Check my MSE profile to see. It should give some sort of idea as to how you should go about this.
Answer: A large part of our purpose here (or my purpose, anyway) is to build a library of knowledge that will be useful to others.  We (or I) hope to build the library in the form of a collection of high-quality questions and answers.  That means that we are (or I am) hoping for questions that will be relevant to others in the future; that will be formulated in a way that can be found by others in the future; that are clear enough they can be answered, and that others can evaluate proposed answers.
Example: if your question is "What is the value of $x$ that minimizes $17x^4+2x^3 + 3\cos x$?", and you ask it out of curiosity, then that is probably not a great fit for this site.  It seems unlikely that others will have the same question.
Example: if your question is "What technique can I use to find the value of $x$ that minimizes $f(x)$, where $f(x)$ is a polynomial?", that would be natural and general enough that it has the right format for this site.  There is a good chance that others will run into this same problem.  On the other hand, it is likely that the question is already answered here; and it is already answered in standard textbooks; so there is not much value in asking or answering it here -- it would be better to consult standard resources.
So I don't think it's the motivation, exactly, that determines whether the question is a good fit.  If your motivation is curiosity about a question that seems natural and others would likely have, that could potentially be suitable here.  If your motivation is curiosity about an obscure situation that it's unlikely anyone else will ever face in the future, that probably doesn't advance the site's mission much, so such a question probably won't be well received.

I also want to share a disclaimer, that these are my views only.  My understanding is that there is a significant portion of the user base of this site who have different views, and who might be more open to questions based on curiosity even if no one else is ever likely to have the same question again in the future.
Comment: I strongly disagree that if the answer is in standard textbooks, then there is no value from adding it to this website. Standard textbooks are not indexed and crawled by search engines. This website is.
Comment: Also, there are countless times when I search for something on Google or Bing and am directed to some question on this website that is relevant but similar in nature to the $17 x^4$ example you provided. I find myself wondering how it knew this would be useful. Basically, this answer assumes we live in a world where search engines don't exist.
Comment: and sometimes it's hard to know ahead of time where a mathematical curiosity will lead  https://en.wikipedia.org/wiki/David_Smith_(amateur_mathematician)
Answer: Here is my observation about how the Community deals with random made-up questions :
I myself have interacted with user Dan who currently has 200+ questions , mostly made up by random curiosity and excel simulations.
Most of the questions are highly upvoted , some have 40+ votes.
Just the Month of Jan 2024 , user Dan has 13 questions which have comments like the following image :

What is the Community response/reaction to these random questions ?
Even after giving away 1500+ Points via Bounties , user Dan has 20000+ Points.
What about Context ? Here is what user Dan says , in general :

OP : "I wanted to ask if I can ask questions that arise only from my curiosity"
Short Answer : "YES , you can"
If you make the question interesting enough & generic enough & tractable enough , then the Community might interact with you on that.
When that happens , you might be motivated to interact more here.
If you make the question totally uninteresting or very very specific or very untractable , then the Community might not interact & might even resorting to downvoting & deletion.
When that happens , you can add it to your experiences & move on.
Answer: As with many such questions, my personal answer is "Possibly yes, but only with care."
There is a cultural sense (mathematical culture, that is) in which certain things pique the common curiosity. It's difficult to define, obviously, but there seems to be rough consensus on many of these things. In the recreational arena, an observation that

the common second difference of squares is $2! = 2$
the common third difference of cubes is $3! = 6$
the common fourth difference of fourth powers is $4! = 24$

might draw some consensus curiosity, especially if the observation is made by a younger student*. In that context, a question as to how to prove that (which might require tools the student is unaware of, but would probably understand) could potentially be well received, especially if it comes with some kind of incomplete attempt at a proof.
There's a certain creative inquisitiveness that's exhibited by such questions. Again, it's hard to define, but you sort of know it when you see it. Surprise, elegance, succinctness, a sense of relatedness—they all work into it.
Note that even if this question comes out of idle curiosity, substantial work goes into making it a good question. For better or worse, this is not the Math.SE of 2015. To put it bluntly, the community expects to be sold on the question, and it expects the OP to do the selling.
Note also that it isn't fundamentally a question of rigor. There are, however, issues of precision. What is the OP's asking? What kind of answer would they like? Leaving this kind of context out makes the question a poor one, even if the mathematics at the heart of it is potentially interesting.
In short, the matter of what motivates the question isn't sufficient on its own to determine whether the question will be well received or poorly received. It's simply one factor of many.

*I asked myself this question when I first heard about FLT as a ten-ish-year-old. As it turns out, I did not have the machinery to see how to prove it, nor did I recognize that it's relatively trivial (compared to FLT).
Comment: "the matter of what motivates the question isn't sufficient on its own" agreed, but providing the motivation is a good start. For example, take [this question](https://math.stackexchange.com/questions/4851972) : since $233$, $34$ and $89$ are Fibonacci numbers created by connecting consecutive digits together (or close to one), the author asks if some other concatenations are Fibonacci numbers. That's very odd-looking motivation but good enough for someone to look up. I just want someone to provide those details, however related they may be.
Answer: Here is a take from somebody who is by no means a prolific poster --- and therefore has less right to reply than those who contend with such things on a frequent basis.
If you come up with a "random" problem that is of interest to you, and you bang your head against it for quite a while but are stuck on some obstacle, I think that asking a question is not only appropriate but beneficial to everyone --- subject to three constraints: (1) you really thought about the problem long and hard before posting, (2) you formulate the question clearly and precisely, and (3) you make a reasonable effort to search for an existing post (which can be difficult, especially when the relevant subject and jargon are unknown to you).
The formulation part is critical --- not just for the benefit of others (including possible respondents) --- but because it often obviates the need to actually post the question.  In precisely framing the question, the answer often becomes obvious --- or an inability to reify it may identify a flawed assumption or some other critical error in one's reasoning.  I've had both happen to me numerous times.
If the three criteria above are met, then I would argue you should post the question.  Chances are, others have encountered a similar obstacle --- perhaps not with regard to that precise problem but a related one.  Odds also are that any answer you get will be broader than just your question and may give future readers some useful insight, even if they aren't pursuing precisely the same problem.
Many interesting developments in mathematics started as "gee, this looks like a cool problem, I wonder if there's any meat to it."  Twenty treatises, many years, and a whole new field later, the answer turns out not only to be nonobvious but profoundly important.
I'm not saying this is common (or even remotely likely) or should motivate you, but it does illustrate that "random problems" are not necessarily uninteresting to others.  I've had seemingly simple problems (and I mean problems a high school student could understand) lead me to Markov Decision chains, Algebraic Geometry, the classification theory of Group Extensions, and Characteristic Classes.  In most of those cases, if I hadn't asked I never would have had a clue that I wasn't just missing something obvious --- and I never would have had the pleasure of exploring those fields.  Worse, I probably would have lost confidence or gotten frustrated and given up.  Sometimes, it really helps to have somebody tell you that you're barking up the wrong tree or that it's a very big tree with a thousand pound gorilla hidden in it.

Can I make a post just for curiosity?


Prove that $\forall a>0$ $\exists c\in [0,1]$ such that $\int_0^a e^{x^2} dx =\frac{c}{a}(e^{a^2}-1)$

Question: Prove that $\forall a>0$ $\exists c\in [0,1]$ such that $$\int_0^a e^{x^2} dx =\frac{c}{a}(e^{a^2}-1)$$
I initially tried to use Cauchy's Mean Value Theorem, but I wasn't successful. The fact that we have $e^{a^2}-1$, which is precisely $e^{x^2} \bigg |_{0}^{a}$, made me think about IBP, but this didn't work out either.
Answer: For $a\ge 0,$ define
$$f(a) = a\int_0^a e^{x^2}\,dx + 1 - e^{a^2}.$$
Then $f(0)=0$ and
$$f'(a) = \int_0^a e^{x^2}\,dx + ae^{a^2} - 2ae^{a^2} = \int_0^a e^{x^2}\,dx - ae^{a^2}.$$
Clearly the last expression is negative for $a>0.$ Thus $f$ is strictly decreasing on $[0,\infty).$ Hence $f(a)<0$ for $a>0.$ This implies
$$\tag 1 \int_0^a e^{x^2}\,dx < \frac{e^{a^2}-1}{a},\,a>0.$$
It follows that the left side of $(1)$ equals $c$ times the right side of $(1)$ for some $c\in (0,1).$
Comment: Very elegant (+1)
Comment: @an4s Thank you.
Answer: Express $c$ as follows,
$$c =\frac {\int_0^a e^{x^2} dx }{\frac1a(e^{a^2}-1)}
=\frac {\int_0^a e^{x^2} dx }{\int_0^ae^{ax}dx}
=\frac {\int_0^1 h(t) e^{a^2t}dt }{\int_0^1e^{a^2t}dt}$$
where $h(t)=e^{-a^2t(1-t)}$ and the substitute $x = at$ is made in the last step. For $0\le t \le 1$ and $a>0$, we have
$$0<e^{-a^2t(1-t)} \le 1$$
which leads to
$$0<\int_0^1 h(t) e^{a^2t}dt \le \int_0^1e^{a^2t}dt$$
and, hence,
$$0 < c \le 1$$


Apply a layer style to all frames

Question: I want to apply a same style to ten layers. The problem is that I'm working with gif and for some reason the layers style only apply to that one frame even tho i selected all frames. I do not want group them because grouping doesn't allow clipping mask. is there a way to apply layer style to all frames without the use of group? thanks in advance.
Comment: Right-click on a layer > "copy layer style" and then select multiple layers, right-click one of them and > "paste layer style". The Alt+drag method is probably faster/more convenient for <10 layers but with >10 layers copy&paste is probably better.
Answer: I don't think this is possible but a fast way to do this is to quick-duplicate the style with alt + drag or option + drag
Answer: select your frames, add a layer effect. Only the first selected has the effect, BUT reselect all frames, click again like you are going to modify the effect and only click ok, now all of them should have the effect applied !

Apply a layer style to all frames


Edit the archive-{custom_page}.php via WP editor

Question: Is there any way to edit the archive-{custom_posts}.php page via the WP page editor? I wan't to add some custom text and links...
Answer: Maybe if you go to appearance -> editor in the dashboard your page can show there. Or you can install this plugin.
Answer: Yes, I can recommend WP Editor - it is a plugin for WordPress that replaces the default plugin and theme editors as well as the page/post editor.  https://wordpress.org/plugins/wp-editor/
Answer: You can also use this plugin: https://wordpress.org/plugins/wpide/