Thursday, December 22, 2011

Cleared Check Server v2 - what about adding data?

Yes it's ugly and full of smells but it works. However, what about adding in new cleared checks as they are downloaded or pulled from a cd.

First thing to do is pull out some of the logic into its own class and also add methods to append to the csv file.

Then lets add some more routes to app.rb, most of this was borrowed from the internet

and then some more borrowed code

Still smelly? You betcha. Still need tests? Absolutely.

Cleared Check Server v1

Here's the simplest solution I could come up with for serving cleared checks using sinatra and loading the csv into a global variable. All sorts of bad but its all about the iteration...

Wednesday, December 21, 2011

Opening a dbf file

The final piece of backing up the bank cds came from the last few months where the bank cds switched from using a xml file to a dbf file. Since it was only a few months, I decided to just open the dbf files rather than creating a script. But what opens a dbf file...the answer is OpenOffice which opened the files perfectly. I know its not very elegant but I then copied and pasted the data into the csv file created from the last post. Now, I'm ready to create a server piece so that all employees can discover if a check has cleared.

Creating a csv file from xml using groovy

Following up on the last article where I backed up the bank cds, I wanted to be able to query all of the cds at once to see if a check had cleared. In order to accomplish this, I mounted one of the backed up iso files, explored and found that most of the months used an xml file to list the cleared checks. I pulled the xml file from each iso into a directory and then used the following groovy code to read the file. Why groovy?, I guess it was the flavor of the day

This accomplished reading the file but then I wanted to output to a csv file. I decided to use the opencsv java package. After adding the import to the groovy script for import au.com.bytecode.opencsv.*, I then wrote the following code

Unfortunately the script did not run as opencsv expects a Listof String[] and did not like the groovy lists that it was given. Here's the exception:
Caught: java.lang.ClassCastException: [Ljava.util.ArrayList; cannot be cast to java.util.List at CheckClearer$_run_closure2.doCall(CheckClearer.groovy:30) at CheckClearer.run(CheckClearer.groovy:30)
I explicitly had to create String[]s and then pass them to CSVWriter. Here's the final script:

Backing up cds using a macbook and snow leopard

Our cleared checks come on a cd from the bank each month. The cds desperately needed to be backed up.  Here are the steps I used to accomplish.  


Using a macbook with snow leopard and a slashdot article on creating an iso from a cd slightly modified, I was able to accomplish this fairly easily.


First, find where the disc is located


drutil status


Look for the name output, which in my case was


/dev/disk1


On the slashdot article, they were able to dd /dev/disk1 but in my case I had to go one step further and first list the sessions


ls /dev/disk1*


which listed 


/dev/disk1 and /dev/disk1s0


Next unmount the cd using


diskutil unmountDisk /dev/disk1


and then create an iso file from the cd


dd if=/dev/disk1s0 of=file.iso bs=2048


I know this can be automated even further but I chose the long way and went through the steps for each cd. I was able to eliminate the drutil and ls commands on subsequent runs as /dev/disk1s0 remained constant with every cd.

Friday, May 15, 2009

Ruby meet Groovy. Groovy,Ruby meet Jasper

I had a longstanding user request to produce a JasperReport that was tied to an old as400 datasource.  When rails came on the scene the report was no longer valid, but was needed for ongoing operations.  Short term I decided to retool the report, query, and parameters using iReport. The user would let me know when she needed the report which I would run directly from iReport locally and email to her. However, I was not happy and more importantly the user was very dissatisfied.  So my first reaction was to create a pdf using prawn which worked but did not look near as good as the old report.  My next thought was to reformat the prawn code but this would take considerable time and I already had a very nice looking report but required java, jasperreports, and some groovy.  Soon visions of queues, schema changes, new models, jruby deployment started stirring along with the realization that I did not have the time to make it happen.  So I continued the clunky way until today when I realized that I could web enable the report simply my uploading the relevant jrxml to the java app server, making small changes to the groovlet, and a simple redirect from a rails controller.  In less than 15 minutes I created the following rails code:

class ScodesController < ApplicationController
  def create
    scodes_url = "#{BASE_SCODES_URL}?startDate=#{start_date}&endDate=#{end_date}"
    redirect_to scodes_url
  end
end



and groovy code:

import groovy.sql.Sql
import java.sql.ResultSet
import java.sql.SQLException
import net.sf.jasperreports.engine.*
import net.sf.jasperreports.engine.design.JasperDesign
import net.sf.jasperreports.engine.xml.JRXmlLoader
import com.baldwinmutual.BmicJasper

String path = context.getRealPath("forms") + "/sCodeListForLegacy.jrxml"
reportParameters = new HashMap()
def startDate = params.startDate
def endDate   = params.endDate
db = Sql.newInstance('jdbc:mysql://legacy.bmic/legacy_bmic_production',
                     'user','pass',
                     'com.mysql.jdbc.Driver')
reportParameters.put("EFFDA",startDate)
reportParameters.put("EXPDA",endDate)
inputFile = new File(path);
baos = new ByteArrayOutputStream()
jasperizer = new BmicJasper(db.getConnection())
baos = jasperizer.setParameters( reportParameters )
                 .compileReport( inputFile )
                 .fillReport()
                 .createReportStream()
response.setHeader("Expires", "30")
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0")
response.setHeader("Pragma", "public")
// setting the content type
response.setContentType("application/pdf")
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ot = response.getOutputStream()
baos.writeTo(ot)
ot.flush()

Wednesday, August 13, 2008

Is keyczar a possible solution to no gae ssl?

My security knowledge is very lackluster but I do know that not having ssl will hamper google appengine's uptake. Therefore, I was extremely interested to see this: keyczar. Since it has a python implementation, it seems reasonable to my security small mind that it could be used to implement security over http.

Tuesday, August 12, 2008

Execution, execution, execution

This time from Merlin Mann

Yegge does it again

Another great post by Steve Yegge Condensed


Build something you want and/or need:

"You don't need an original idea to be successful. You really don't. You just need to make something that people want"

"In any event, originality is overrated"

A successful product comes down to execution and execution comes down to passion which stems from giving a damn about what you are doing.

If you don't have anything you really want or need, then:

"Don't gather business requirements: hire domain experts."

I actually disagree with this a bit. If you don't have something you want or need, then listen to your friends, colleagues, or family that give a damn but are missing one critical ingredient, ie a great ruby programmer. In my opinion, there is usually no need to hire the domain expert, they are all around you...

Sunday, August 10, 2008

Prettify code on blogger

Just a quick post on getting pretty code on blogger using prettify

I first followed the instructions on sunday-lab but when trying to save the template after pasting the css and js into the "Edit HTML" in layout settings of blogger, I kept getting the following:

We were unable to save your template

Please correct the error below, and submit your template again.
Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: The content of elements must consist of well-formed character data or markup.

and before someone posts a comment stating the obvious, closing tags were in place. I then continued my pursuit and found some slightly alternate instructions on HyveUp that did the same so here's what I finally had to do to get this to work:
  1. Copy the prettify.css and paste right above the]]></b:skin>]]> closing tag
  2. Insert


    <script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'/>

    right above the closing </head> tag
  3. Save Template

The world has been missing out...

on my thoughts so I've finally used my Sunday morning to setup this blog where I'll record my thoughts on insurance, programming, tech in general, the food supply and any other deep thoughts that come to mind.