Archive for April, 2006

Posted on April 20, 2006 at 12:28 pm

If you’re a fan of the YourSQL utililty for MySQL, and you’ve recently switched to an Intel based Mac you’ve probably found that it runs slowly (or not at all) under Rosetta. I’ve compiled an Intel only binary and am making it available here. This is the latest development build (1.8.0e). Just open the disk image and drag the YourSQL icon to your Applications folder.

You can download here, or click on the icon to download:

Posted on April 18, 2006 at 6:14 pm

If you’re heavily using the AJAX helpers in Ruby on Rails like I am, you may want to check out Thomas Fuchs’ awesome presentation from Canada on Rails 2006.

You may find a few little tasty morsels that aren’t adequately (at all?) documented.

My favorite? Call your own. Although… respond_to is a close runner up, though I’ve been aware of it for a whie now.

BTW- If you are still building new sites/application in PHP, can I just ask… WTF?

Posted on April 15, 2006 at 11:44 pm

I think this is as small as the amortization program can get without losing functionality. If you can make it smaller, please let me know about it.

def a(p,i,m)j=i/1200;Array.new(m){|n|p=(b=p-k=p*(j/(1-(1+j)**-m))-q=p*j);[n+1,b,q,k]}end

You can still use it the same way. To print a full amortization schedule, for $200,000 at 7.5% interest over 360 months:

puts "month,balance,interest,principle"
a(200000, 7.5, 360).each {|p|printf "%.2f,%.2f,%.2f\n",*p}
Posted on April 3, 2006 at 11:18 am

Lately I’ve been assigning myself these little programming challenges. I allow myself no more than 2 hours to work on them, but I rarely spend longer than 30-60 minutes on them. These are not usually things I intend to take any further, rather they are just fun projects to stretch my mind a little.

My little challenge last night was to come up with the smallest program that calculates an amortization schedule. It could probably be a little smaller, but here it is:

def amortize(p, i, m)
  Array.new(m){|n|p=(b=p-(cp=(mp=p*((mi=i/(1200))/(1-(1+mi)**-m)))-(ci=p*mi)));[n+1,b,ci,cp]}
end

Just call amortize with the principle, interest, and number of payments and you get back an array of month, balance, current month’s interest, and current month’s principle. Calling it like so will produce comma-delimited output that you can open in Excel or whatever.

puts "month,balance,interest,principle"
amortize(200000, 7.5, 360).each{|p|printf("%i, %1.2f, %1.2f, %1.2f\n",p[0],p[1],p[2],p[3])}

Partial output:

month,balance,interest,principle
1, 199851.57, 1250.00, 148.43
2, 199703.25, 1249.07, 148.32
3, 199555.04, 1248.15, 148.21
4, 199406.94, 1247.22, 148.10
5, 199258.96, 1246.29, 147.99
6, 199111.08, 1245.37, 147.88
7, 198963.31, 1244.44, 147.77
8, 198815.65, 1243.52, 147.66
9, 198668.10, 1242.60, 147.55
10, 198520.66, 1241.68, 147.44
11, 198373.33, 1240.75, 147.33
12, 198226.10, 1239.83, 147.22