Dec 15 2008

Keeping database.yml dry

That would be dry as in Don’t Repeat Yourself

defaults: &defaults
adapter: mysql
encoding: utf8
username: root
password: root
#Wherever mysqld.sock is located
socket: /opt/local/var/run/mysql5/mysqld.sock

development:
database: blog_development
<<: *defaults

test:
database: blog_test
<<: *defaults

production:
database: blog_production
<<: *defaults


Aug 11 2008

Why implement PHP in Java?

First of all, why not? Everything else can run on the jvm (yes… even c#), so why not php? Well… I certainly don’t see why not… Java is a fairly robust language with a pile of different libraries and (as you saw if you clicked on any of those links) languages that can run on it. It is ideal!

Don’t like php’s random function? Why not use Java’s? Not your cup of tea? Use ruby’s instead, or python’s, or  write one in COBOL if you are really brave.

It also means that you can implement the functionality in Java, the database transactions in Ruby, then write all of the presentation in PHP, no clearer MVC separation than that eh? Admitedly it might get a bit confusing and I may be over exaggerating about the possibility of these implementation’s cross communication abilities… but it would be great if you could (I might test it later…).

http://www.caucho.com/resin-3.0/quercus/index.xtp

Go check it out!


Jul 19 2007

The answer in Ruby (so far)

a = [1,2,3,5,7,8,9,10,12,13,19,200,900,901,902,903,904,905,1000]
l = a[0]
f = a[0]
z = a.length
i = 0
s = ""
until i == z
  if (a[i]+1 == a[i+1])
    l = a[i+1]
  end
  if (a[i]+1 != a[i+1])
    if f == l
      s = s+"#{f}"
      if i+1 != z
        s = s+","
      end
  end
  if f != l
        s = s+"#{f}=&gt;#{l}"
        if i+1 != z
          s = s+","
        end
    end
    f = a[i+1]
    l = f
  end
  i+=1
end
 
puts s