Hanging a hammer from a table and a stick so that its midpoint is outside of the support of the table I came across this pic on the internet today.  At beginning I thought it is just not possible because the centre of mass is way off so gravity will generate torque making the stick and hammer fall.  Later I thought that the heaviest part of hammer could've balanced the centre of mass and so it could be possible.
Still I'm confused.  Is it possible or not assuming that it is performed on our planet or with planet with similar g (acceleration due to gravity).

In other words: is the center of mass of the hammer usually in the metal part? (Because that would explain this picture)
And and if it is possible, and we get a function representing this equilibrium, what is your rough inference? is it dependent of acc. due to gravity?
 A: I don't know what question other people are trying to answer, but the real answer is simple: yes, the center of mass is in the metal part, or in the few centimeters of wood that are still under the table.
I just balanced a hammer on my finger and the C.O.M was a cm or 2 from the metal part. 
A: When you use an object to strike another object, there is a place called the "center of percussion" where you don't get a "sting" in your hand. This is sometimes called the "sweet spot" in sports (baseball bats, rackets, ... although vibration modes play a role there and the sweet spot is not automatically the center of percussion) and it results in efficient momentum transfer on impact (as well as comfort to the user).
Now, would you want your hammer to be such that you get efficient momentum transfer without hurting your hand? The answer is yes.
So - a good hammer has its center of percussion in line with the head. And it turns out that this is most easily achieved by putting the center of mass in (or very close to) the head. 
Conclusion: your picture is real, and it works because the center of mass of a hammer is very close to the head (which puts it below the supporting surface).
A: If you know where the center of mass is, the torque will be:
$$\boldsymbol{\tau}=\mathbf{R}\times\mathbf{W}$$
Where $\mathbf{R}$ is the vector from the hanging point that points to the center of mass and $\mathbf{W}$ is the weight vector pointing downward.
We conclude that the only possible arrangement for an equilibrium, here, is that the center of mass gets under the hanging point between the edge of the table and the end of the ruler.
This will make a self-regulating system. Which is the exactly the idea of a stable equilibrium.
If the system is pushed to any side, the torque will tend to pull the system back to its equilibrium state.

EDIT in response to the comment: 
I usually prefer to talk less and let my math talk you you, as much as I can.

My approach was straight forward using the most compact relations. I specified the relative necessary place of the COM for the arrangement to be in equilibrium. And as gravity is only a constant, the It won't make any difference.
The only part I think requires a little thinking is how I came to the conclusion of where the COM must be. This is how:
If you rotate the system clockwise (relative to the picture provided.) the hanging point will be the tip of the ruler. So the COM must be to the left of it.
If the system rotates CCW, the COM will be the touching point off ruler and the edge of the table, so the COM must be to the right of the hanging point.
The only possible place for the COM to satisfy the conditions above is that its projection to the table be between the two hanging points about which we talked about. And it must be below the table to make an stable equilibrium.
If you want more reliable equilibriums, you should increase the torque. You can increase the mass of the system so that $\mathbf{W}$ increases.
The other two ways are increasing the angle between two vectors and increasing the lever arm. I can't claim certainly about these two because they effect each other.
A: The ruler is actually being supported by the handle of the hammer to provide two points of support so the downward force from the string lies between the two and the system balances. 

Moment on the hammer in blue, forces on the ruler in red.
Edit:
To explain in a little more detail the center of mass of the hammer lies to the right of the string so the hammer would (if the ruler weren't there) rotate clockwise. The handle of the hammer can then be treated as a leaver pushing up against the bottom of the ruler.

The blue triangle represents the support from the string, the grey block our hammer head. For this problem we treat the handle as a weightless rod.
As you can see the left hand side of the rod will attempt to turn. This is what provides the supporting force on the ruler.
A: One thing not mentioned by the other answers so far is that the centre of mass of the hammer-ruler-string (viewed as a single object) must be under the table (to the right of the table edge in the image) for the setup to work. This is because the only forces external to it and acting on it are gravity and the forces from the table surface. If the centre of mass were not under the table, the table would not be able to provide a force that exactly counters the force on it due to gravity, and the torque will cause it to tilt so that the centre of mass goes towards the table. In this case that will cause the ruler to be touching the table only at the edge, and most combinations of ruler and table won't allow it to stay there without sliding off.
If it is hard to grasp that the centre of mass of a hammer is very near its head, there is an easy way to 'see' it. Simply put the hammer on the table with the handle sticking out off the edge of the table. You can easily get it to stick as far out as in the image in the question, for exactly the same reason. It makes sense because the metal part is much denser than the wood part, and intuitively one can understand it as meaning that it is harder to move a denser object so the wood part cannot easily pull the metal part off the table because it would have to make the metal part rise up first, which is difficult due to its much greater inertia. The density merely explains how a smaller part can have a larger inertia (reluctance to move). Of course, all this can be translated into a physics explanation, but I think it can serve as an intuitive help.
A: You can make two free body diagrams. One for the plank (with pink arrows), and one for the hammer (with blue arrows). Then examine if the forces can balance out.

The reaction force on the plank from the table has to equal the hammer weight $W$ and the plank weight $w$. In addition, it has to be in the line of action of the combined weight, but with opposite the sense.
The string tension $B$ lifts the hammer up (because string can't push, but only pull) and the contact in the end of the hammer $A$ pushes the hammer down because contact can only push and not pull.
Not only the sum of the forces must balance out, but also the sum of the moments. That is why $A$ is needed. Without it the hammer would swing to the right from the moment caused by (blue) $B$ and $W$ forces.
A: The position of center of mass is secondary confirmation to the main consideration of equilibrium (static balance) of forces and moments of two simply supported/ (pinned fulcrum)  beams. 
Essentially assuming a 5 inch  hammerhead weight of 12 oz ( weightless wooden grip)  and horizontal weightless beam simply supported 1 inch from right, the free-body diagram is drawn as below.

Force (in oz)  Balance $15 = 12 + 3 $
Moment Balance about left contact fulcrum  $ 4" X 15 = 5" X 12 $
Neglected weights can be added on, respecting force/moment equilibrium.
When considering design of the beams ( as an aside) it is noted that the shear force and bending moment are same ( mirroring)  at any location. If same uniform section is chosen for the two sticks, then stresses are same at any location along their lengths.
