In what scenario do we need to implement Singleton Class in javascript as below  var Singleton = (function () {     var instance;      function createInstance() {         var object = new Object("I am the instance");         return object;     }      return {         getInstance: function () {             if (!instance) {                 instance = createInstance();             }             return instance;         }     }; })();  function run() {      var instance1 = Singleton.getInstance();     var instance2 = Singleton.getInstance();      alert("Same instance? " + (instance1 === instance2));   }
The glorified global variable - becomes a gloried global class. Some say breaking object-oriented design.  Give me scenarios, other than the good old logger where it makes sense to use the singleton.
Area of intersection between two circles Suppose you have 2 circles that intersect each other in such a way that each circle passes through the other's center. What is the area between the circle(or common area) i.e. area between the centres of the circles? What is the proper use of [square brackets] in quotes? network manager says "device not managed" How do I integrate the following? $\int{\frac{(1+x^{2})\mathrm dx}{(1-x^{2})\sqrt{1+x^{4}}}}$ How to prove the continuity of the metric function? What's the point of Hamiltonian mechanics? I've just finished a Classical Mechanics course, and looking back on it some things are not quite clear. In the first half we covered the Lagrangian formalism, which I thought was pretty cool. I specially appreciated the freedom you have when choosing coordinates, and the fact that you can basically ignore constraint forces. Of course, most simple situations you can solve using good old $F=ma$, but for more complicated stuff the whole formalism comes in pretty handy.  Then in the second half we switched to Hamiltonian mechanics, and that's where I began to lose sight of why we were doing things the way we were. I don't have any problem understanding the Hamiltonian, or Hamilton's equations, or the Hamilton-Jacobi equation, or what have you. My issue is that I don't understand why would someone bother developing all this to do the same things you did before but in a different way. In fact, in most cases you need to start with a Lagrangian and get the momenta from $p = \frac{\partial L}{\partial \dot{q}}$, and the Hamiltonian from $H = \sum \dot{q_i}p_i - L$. But if you already have the Lagrangian, why not just solve the Euler-Lagrange equations?  I guess maybe there are interesting uses of the Hamiltion formalism and we just didn't do a whole lot of examples (it was the harmonic oscillator the whole way, pretty much). I've also heard that it allows a somewhat smooth transition into quantum mechanics. We did work out a way to get Schrödinger's equation doing stuff with the action. But still something's not clicking.  My questions are the following: Why do people use the Hamiltonian formalism? Is it better for theoretical work? Are there problems that are more easily solved using Hamilton's mechanics instead of Lagrange's? What are some examples of that? Chance of selecting the last k pages in correct order from a set of n pages Prove that $ m_{a} \geq m_{g} \geq m_{h} $ using strict inequalities unless $ a = b $. $ m_{a} = \frac{1}{2} (a + b) $   $ m_{g} =  \sqrt{ab} $   $ \frac{1}{m_{h}} = \frac{1}{2}(\frac{1}{a} + \frac{1}{b})$   Attempted Solution:  I believe I have shown the first step, which is $ m_{a} \geq m_{g} $ but i'm stuck on showing $ m_{g} \geq m_{h} $  $ \frac{a + b}{2} &gt; \sqrt{ab} $  $ (\frac{a + b}{2})^2 &gt; (\sqrt{ab})^2 $  $\frac{a^2 + 2ab + b^2}{4} &gt; ab$  $a^2 + 2ab + b^2 &gt; 4ab $  $a^2 -2ab + b^2 &gt; 0 $  $(a - b)^2 &gt; 0 $   so if $a = b$ we have $(a -b)^2 \geq 0$  Therefore, $m_{a} \geq m_{g} $  Now, i'm not sure if that is correct or not, if not can you please guide me to the complete solution or if I am correct on this part, provide a solution for $m_{g} \geq m_{h} $ Let's say I have Windows installed on drive C, however I install all of my programs on the D drive, and I keep my user profile on the D drive as well (things like My Documents). How can I have Windows use those folders instead of the ones on the C drive? How do I know if an ability is magical? I want to stop having to use sudo everytime I work in /var/www. How can I do that? I simply want to put all of my sites into this directory and work with them without too much pain. GNOME 3.26 - Clicking one window brings another in the foreground (Ubuntu 17.10) I'm on Ubuntu 17.10 with GNOME 3.26.  Often I have windows tiled on the left and right side of the screen. A typical setup is to have a browser and text editor on the left, a PDF reader and terminal on the right.  Something I've seen happen very often: I'm reading the PDF on the right, having the window in focus. The text editor on the left. When I click on the text editor to write something, it brings forward another window on the right (say the file browser), covering the PDF reader.  This seems to have something to do with the Alt-Tab view history.  My question is: Is it possible to remove the automatic bring-to-front of windows? I don't understand why unrelated windows are brought to the front when I click on another application. $\limsup$ and cluster points Let $(x_n)$ be a sequence in $\mathbb R$. We call $y$ a cluster point of $(x_n)$ iff for every neighborhood $N$ of $y$ there are infinitely many $n$ such that $x_n \in N$. Let $C$ denote the set of cluster points of $(x_n)$.   By definition, $\limsup_{n \to \infty} x_n = \inf_n \sup_{k \geq n} x_k$.  Can you show me how to prove $\limsup_n x_n = \sup C$? Thanks. Ubuntu 13.10 Macbook Air Mavericks Parallels 9 Black Screen I can install Ubuntu 13.10 in parallels ok and then log in.  Problem is Ubuntu does an update and I get black screen / desktop such that I can't see any app windows that I open.  I've tried a few of the other suggestions and they don't work for me. Input string was not in a correct format I have Ubuntu on my MacBook 2007 with a Spanish keyboard, on MacOS the @-sign was typed using Alt (Option) + 2, but on Ubuntu I have no idea. I have to copy and paste it every time. How do I type an at sign? Given that indexing is so important as your data set increases in size, can someone explain how indexing works at a database-agnostic level?  For information on queries to index a field, check out . How to get a cross-origin resource sharing (CORS) post request working How does remittance work? How does it differ from direct money transfer? I have a bank account in Germany in which I receive my salary in Euros. I want to deposit a part of it in my Indian bank account for personal savings. My Indian bank account is in INR. As I see it, I have two options:   To use a remittance service that converts my Euros into INR and deposits in my account. I am not sure how it works. The service (which I know is reliable) I signed up for asks me to deposit Euros in a certain account ("funding") which will be converted to INR and deposited in my account. How does that work exactly? Use my bank's service to make a international bank transfer to my account. Is that even possible, given that my Indian account is in INR? Will I incur higher conversion fees and lower exchange rate?   In general, what are the pros and cons of each of the above methods? And are there any other methods? escaping double quotes and percent signs (%) in cron The following command works from prompt but not from crontab.   grep abc  /var/log/messages | grep "`date '+%B %d'`" | mail -s"abc log of `hostname`" shantanu.oak+`hostname`@gmail.com   I need to add it to daily cron.