Wednesday, March 4, 2015

Getting started with Cassandra Development in Eclipse (BEWARE of jdk8_40_ea, NoClassDefFoundError: ExtendedPlatformComponent)

I finally got back around to getting my environment setup for Cassandra development.  I ran into one snag, and couple things have changed so I figured I would capture the experience here.

Fork and Build

First, fork and clone from here:

Then run,

$> ant generate-eclipse-files

Eclipse Setup & Run Configuration

Then from Eclipse,
File -> Import -> Existing Projects into Workspace...

Navigate to your cassandra folder, and import the project.

Now, configure the run with:

Run Configurations -> Java Application -> Right-Click -> New

Main class:

Then use the following VM arguments:
-Dcassandra.config=file:///Users/bone/git/boneill42/cassandra/conf/cassandra.yaml -Dcassandra.storagedir=/tmp/cassandra -Dcassandra-foreground=yes

The gotcha: Make sure you are running jdk8_40 and NOT jdk8_40_ea!!!

If you are still running early access (_ea), you may see:
java.lang.NoClassDefFoundError: sun/management/ExtendedPlatformComponent


Next, it's useful to configure logging.  Cassandra changed from log4j to logback.  You can find the logback configuration in test/conf (logback-test.xml).

If you want to see DEBUG and/or INFO messages, edit this file and change the STDOUT element to:

  <appender name="STDOUT" target="System.out" class="ch.qos.logback.core.ConsoleAppender">

After that, you are good to go.  Click run, and you should have a live Cassandra in Eclipse

Monday, February 9, 2015

Our dream home, and a monthly mortgage rate calculator in ruby!

We just finished the construction of our dream home:

Now that construction is complete, we are converting from a construction loan into a normal mortgage, refinancing to get the best rate.   We are doing all the normal trade-offs, and being the geek that I am, I wanted to have a deeper look to find out if paying points was worth it, when the break-evens would be, etc.

So, I decided to write a short little ruby program that I could play around with.

It turns out that the math behind the monthly payment is actually kind of neat.  Have a look at the derivation for a fixed rate mortgage:

With the math already done, it was a simple problem to code.  Here is my work:
def money (x)
  sprintf("%05.2f", x)

balance = 500000
annual_rate = 3.25.to_f * 0.01
monthly_rate = annual_rate / 12.to_f
n = 15*12

puts "Loan term (Number of payments) [#{n}]"
puts "Annual interest rate [#{annual_rate*100}]"
puts "Monthly interest rate [#{monthly_rate}]"
term = (1 + monthly_rate)**n
puts "Term = [#{term}]"

monthly_payment = balance * (monthly_rate * term / (term - 1))
puts "Monthly Payment = [#{money(monthly_payment)}]"

while (balance > 0)
  interest_payment = balance * monthly_rate
  principal_payment = monthly_payment - interest_payment
  balance = balance - principal_payment
  puts("Interest [$#{money(interest_payment)}], Principal [$#{money(principal_payment)}], Balance = [$#{money(balance)}]")

Up top of the ruby are all the parameters.  For an example, I used $500K @ 3.25% for 15 years. (n = 15*12, where n is the number of months for the loan)

Then, you will see the loop where it outputs the principle payment, the interest payment, and the remaining balance.  For each month, your interest payment is always the interest rate multiplied by the remaining balance.  Then, whatever the difference is between that and the monthly payment is what gets applied to the principal.

It's kind of neat, and you can run multiple scenarios based on different initial outlays and percentage rates.

Hopefully someone finds this useful.  If not, no worries, it was my mental yoga for the day.