The Moon's phase isn't easy to calculate accurately. Fortunately, the 4 main phases (new moon, first quarter, full moon, last quarter) are a bit more stable than the intermediate phases. Good main phase algorithms use a dozen or so sine calculations for the new or full moon, and a similar number for the first or last quarter. Those two algorithms you linked use very simple approximations so their results are rather crude.
The period of the Moon's phase cycle (the synodic month) is stable over the long term, but it drifts considerably over the short term. So algorithms like those in your links are usable over a rather long time span, and they can be useful first approximations to feed to better algorithms, but by themselves they only yield precision results by accident. ;)
The guru of amateur astronomical calculations for bodies in the solar system is Jean Meeus, so if you want quality algorithms make sure they reference Meeus. :)
For seriously accurate ephemerides, especially if you need to cover a wide time span, consider using the work of JPL. You can access their ephemerides at the Horizons Web page; an API, telnet and an email-based interface are also provided.
If you want to do precise astronomical calculations (eg, for eclipse prediction) you'll need to learn about the various time systems used in astronomy, in particular Terrestrial Time and its forerunner, Ephemeris Time.
I see from your SO profile that you're familiar with Python. Good stand-alone Python moon phase code isn't easy to find online, but eventually I did find keturn's py-moon-phase, which is a Python port of the core code of John Walker's rather ancient Moontool, which uses algorithms from Meeus and also from Peter Duffett-Smith. I haven't actually tested John Walker / keturn's code, but it does look rather good (although it uses UTC instead of Ephemeris Time or Terrestrial Time). I have very similar (but rather messy) C code that's generally accurate to half a minute or better over the 20th century.
However, there's a package called PyEphem that can do all sorts of astronomical calculations. James K notes in the comments that PyEphem is now discouraged for new projects. The PyEphem developers recommend Skyfield instead. Astropy can also do a lot of what PyEphem does, and much more.