I write a java program in which i accessed different servers and access some files.  Currently i am only accessing a linux server and executing some command. Actually this is now very specific to the linux environment.  I want that when i access the server , my program will check that weather is Linux environment or windows. If it is windows environment it will execute the command or if it is Linux environment it will execute the command for Linux. How can i check the platform pragmatically.
I would like to determine the operating system of the host that my Java program is running programmatically (for example: I would like to be able to load different properties based on whether I am on a Windows or Unix platform). What is the safest way to do this with 100% reliability?
Are C++ Templates just Macros in disguise? I've been programming in C++ for a few years, and I've used STL quite a bit and have created my own template classes a few times to see how it's done.  Now I'm trying to integrate templates deeper into my OO design, and a nagging thought keeps coming back to me: They're just a macros, really... You could implement (rather UGLY) auto_ptrs using #defines, if you really wanted to.  This way of thinking about templates helps me understand how my code will actually work, but I feel that I must be missing the point somehow. Macros are meant evil incarnate, yet "template metaprogramming" is all the rage.  So, what ARE the real distinctions? and how can templates avoid the dangers that #define leads you into, like   Inscrutable compiler errors in places where you don't expect them? Code bloat?  Difficulty in tracing code? Setting Debugger Breakpoints? Creating account didn't log me in / didn't create an account Perturbation property of Orthonormal basis for Hilbert space What does the notation like 8.6e-28 mean? What is the 'e' for? You can't see the question owner's special color How do I copy a folder keeping owners and permissions intact? So I was going to back up my home folder by copying it to an external drive as follows:  sudo cp -r /home/my_home /media/backup/my_home   With the result that all folders on the external drives are now owned by root:root. How can I have cp keep the ownership and permissions from the original? Bravo for allowing comment editing, but what's the explanation for enforcing a five-minute window?  I think this might be over-engineering. If I have a spelling mistake or an inaccuracy I'd like to fix, I don't think the fact that five minutes has elapsed should prevent me from fixing it.  Further, if you are worried people will edit their comments in a way that makes the comment thread nonsensical, they can already do this by deleting their comment. So, limiting the ability to edit isn't really helping much in that regard.  Update  If people don't like this idea, I'm definitely open to hearing your reasons. For now, it seems like an unnecessary limitation of a quite awesome feature.  Update 2  Regarding John's scenario...     Me: Obama is cool!   You: You are right, man!      My edit: Obama is an idiot!   You: You are right, man!   ...this problem can still occur with deletions...     user1: Obama is cool!   user2: No, McCain is cool!   you: You are right, man!        user1: Obama is cool!   ---- deleted -----   you: You are right, man!     So, yes, editing could be abused as you suggest, but discontinuities can occur already because of deletions (and as someone else mentioned, because upvoted comments get prioritized upward).  As for Jeff's argument about rate limiting, I agree that is important, but I don't understand why you can't just use a CAPTCHA to prevent too many edits in a short period of time. I'm in a conversation and I don't really want to leave because the people there keep adding me back so it's just whatever. But I would like to mute the conversation or something like I do on Facebook so I won't take notifications or anything from there unless I press on the group and see what's going on. Because for now I have my Skype having a new notifications every half a second.  Any solutions to that? Better explanation of the common general relativity illustration (stretched sheet of fabric) I've seen many science popularisation documentaries and read few books (obviously not being scientist myself). I am able to process and understand basic ideas behind most of these. However for general relativity there is this one illustration, which is being used over and over (image from Wikipedia):    I always thought that general relativity gives another way how you can describe gravity. However for this illustration to work, there needs to be another force, pulling the object down (referring to a direction in the attached image). If I put two non-moving objects in the image, what force will pull them together?  So where is my understanding incorrect? Or is general relativity not about explaining gravity and just describes how heavy objects bends spacetime (in that case the analogy is being used not correctly in my opinion)?    UPDATE Thank you for the answers and comments. Namely the XKCD comics is a spot on. I understand that the analogy with bent sheet of fabric pretty bad, but it seems that it can be fixed if you don't bent the fabric, but just distort the drawn grid.   Would you be so kind and answer the second part of the question as well - whether general relativity is explaining gravitational force. To me it seems that it is not (bending of spacetime simply can not affect two non-moving objects). However most of the time it is being presented that it does. Following are other questions which I think I need to know:   From a non X Session? (meaning root isn't logged into X) If multiple people were logged in on X, could I auto-detect who was on which screen, and thus programmatically detect which screen I need to launch the app on? Can I launch the app as the user? ( ok I'm 99.999% sure this is a yes ) Can I detect if users of group X are logged in to X? Top angular speed of electric motor I recently came across a question asking the following:     If a motor is switched on, it quickly reaches a top speed. Why does it not just go faster and faster and faster?   I thought it might be related to the fact that the electrical power is constant, so I tried approaching with $P=\tau \cdot \omega$. However I still do not have any clue to reaching the conclusion.  Is it somehow related to the energy loss (due to friction)? Like the terminal speed of a parachute or something? But I was thinking that friction should be constant ($f=\mu \cdot N$) while air drag is related to the speed, so this may not be the answer.  Thank you. I am a non-EU national, permanent UK Resident. Recently, my work issued me with a multiple Schengen visa with Norway as the first (main) point of entry. Now I want to go on holidays to Greece - do I need to apply to Schengen visa again, as Greece is not Norway and I am not going there for work? Ball to Ball Collision - Detection and Handling With the help of the Stack Overflow community I've written a pretty basic-but fun physics simulator.    You click and drag the mouse to launch a ball.  It will bounce around and eventually stop on the "floor".  My next big feature I want to add in is ball to ball collision.  The ball's movement is broken up into a x and y speed vector.  I have gravity (small reduction of the y vector each step), I have friction (small reduction of both vectors each collision with a wall). The balls honestly move around in a surprisingly realistic way.  I guess my question has two parts:   What is the best method to detect ball to ball collision? Do I just have an O(n^2) loop that iterates over each ball and checks every other ball to see if it's radius overlaps? What equations do I use to handle the ball to ball collisions? Physics 101 How does it effect the two balls speed x/y vectors?  What is the resulting direction the two balls head off in?  How do I apply this to each ball?     Handling the collision detection of the "walls" and the resulting vector changes were easy but I see more complications with ball-ball collisions.  With walls I simply had to take the negative of the appropriate x or y vector and off it would go in the correct direction.  With balls I don't think it is that way.  Some quick clarifications: for simplicity I'm ok with a perfectly elastic collision for now, also all my balls have the same mass right now, but I might change that in the future.    Edit: Resources I have found useful  2d Ball physics with vectors:  2d Ball collision detection example:     Success!  I have the ball collision detection and response working great!  Relevant code:  Collision Detection:  for (int i = 0; i &lt; ballCount; i++)   {       for (int j = i + 1; j &lt; ballCount; j++)       {           if (balls[i].colliding(balls[j]))           {             balls[i].resolveCollision(balls[j]);         }     } }   This will check for collisions between every ball but skip redundant checks (if you have to check if ball 1 collides with ball 2 then you don't need to check if ball 2 collides with ball 1.  Also, it skips checking for collisions with itself).  Then, in my ball class I have my colliding() and resolveCollision() methods:  public boolean colliding(Ball ball) {     float xd = position.getX() - ball.position.getX();     float yd = position.getY() - ball.position.getY();      float sumRadius = getRadius() + ball.getRadius();     float sqrRadius = sumRadius * sumRadius;      float distSqr = (xd * xd) + (yd * yd);      if (distSqr &lt;= sqrRadius)     {         return true;     }      return false; }  public void resolveCollision(Ball ball) {     // get the mtd     Vector2d delta = (position.subtract(ball.position));     float d = delta.getLength();     // minimum translation distance to push balls apart after intersecting     Vector2d mtd = delta.multiply(((getRadius() + ball.getRadius())-d)/d);        // resolve intersection --     // inverse mass quantities     float im1 = 1 / getMass();      float im2 = 1 / ball.getMass();      // push-pull them apart based off their mass     position = position.add(mtd.multiply(im1 / (im1 + im2)));     ball.position = ball.position.subtract(mtd.multiply(im2 / (im1 + im2)));      // impact speed     Vector2d v = (this.velocity.subtract(ball.velocity));     float vn = v.dot(mtd.normalize());      // sphere intersecting but moving away from each other already     if (vn &gt; 0.0f) return;      // collision impulse     float i = (-(1.0f + Constants.restitution) * vn) / (im1 + im2);     Vector2d impulse = mtd.normalize().multiply(i);      // change in momentum     this.velocity = this.velocity.add(impulse.multiply(im1));     ball.velocity = ball.velocity.subtract(impulse.multiply(im2));  }   Source Code:     If anyone has some suggestions for how to improve this basic physics simulator let me know!  One thing I have yet to add is angular momentum so the balls will roll more realistically.  Any other suggestions?  Leave a comment! Site being repeatedly hacked: any useful tips for tracking down entry point? Proof for alternative definition of the derivative I read somewhere recently that you can define the derivative as follows:  $$f'(x) = \lim_{h, k \to 0^+} \frac{f(x +h) - f(x - k)}{h + k}$$   I have been trying to prove this for about 2 hours, and can't seem to get it done. How should I proceed?  Edit: Assume $f$ is differentiable for all $x \in (x - \delta, x + \delta)$ for some $\delta &gt; 0$. How can I automatically download lyrics in iTunes? Is there a way to automatically download lyrics in iTunes? How to interpret Mean Decrease in Accuracy and Mean Decrease GINI in Random Forest models How to Translate Content type name using i18n module? I am developing a multilingual site that supports English and Norsk bokmal. I have set English as my default language. I wanted to translate the contents and the other things in the site.  My real problem started when I found that I was unable to see the translation of the content type's name. I went to admin/config/regional/translate/translate and translated everything, but still my content type's name is not translated.  I have attached a screenshot of the translation page. Still I don't find a way to translate the content type's name. You may have encountered a situation in which Mac changes the order of desktops based on some events like alerts on a program or a web page in browser. How could I disable this logical change? Note: I'm using El Capitan, but I had this problem since Mavericks. Why use swap when there is more than enough free space in RAM? Using swap space instead of RAM can drastically slow down a PC.  So why, when I have more than enough RAM available, does my Linux system (Arch) use the swap?  Checkout my conky output below:    Also, could this be the cause of speed and system-responsiveness issues I'm having?  Output of free -m :  $ free -m              total       used       free     shared    buffers     cached Mem:          1257       1004        252          0         51        778 -/+ buffers/cache:        174       1082 Swap:          502        144        357