Thursday, November 7, 2013

Another primitive File I/O gotcha!

A part of the feature I'm writing is to load multiple regex from a file. The file is simple, each line represents a regular expression.

\b(cat|kitten)\b
\b(dog|curr)\b
\b(buffalo|tamaraw)\b

Now I needed to test my method that uses these regex:

public class Animals {
private List regexes;
public Animals(List regexes) {
this.regexes = regexes;
}
public String detectAnimal(String input) {
// for each regex, create a java.util.Pattern and at the first match, return Matcher.group()
}
}

The test data for animals is around 1 million that is stored in DB. For me to be able to test this is to use Groovy's DataSet to loop through the test data. For each iteration, run the detectAnimal method and save to DB. Easy enough.

Now here's the big Gotcha. Below is the Groovy code I used to build my List of regexes. Note that I used this code only for testing purposes.

File file = new File(Animals.class.getResource(Animals.DEFAULT_CONFIG_FILE).getFile()) Animals animal = new Animal(Arrays.asList(file.getText().split('\n')))

A character '\r' was not removed from the resulting list of regex which looks like this:
\b(cat|kitten)\b\r
\b(dog|curr)\b\r
\b(buffalo|tamaraw)\b
This essentially breaks all the regexes except the last one: \b(buffalo|tamaraw)\b Debugging this (I used Eclipse) was tricky since '\r' or carriage return is non-printable character.

To make this much more complicated, in the Java code, I have already written the code that loads the config file which uses Apache Commons IO FileUtils. This code was located in a Project wite Utils class which uses a java static block to load config files. Which, honestly, I don't like. Since using static blocks is a bad practice.

Honestly, this might have clouded my judgement of not using this Utils class. Also since Groovy is a shiny new language, so I was excited in using the new & improved File class. But apparently, Groovy's File class does not have readLines as opposed to FileUtils from Apache Commons.

TODO, make this post more readable

Tuesday, October 30, 2012

Pokémon Exception Handling

from http://www.codinghorror.com/blog/2012/07/new-programming-jargon.html

Pokémon Exception Handling

Pokemon
For when you just Gotta Catch 'Em All.
try {
}
catch (Exception ex) {
   // Gotcha!
} 

Friday, March 25, 2011

Rivals Schools' NEW ALBUM is here! got worn-out in coding, I'll enjoy music for now :)

Rival Schools, a New York based Post-hardcore band, one of my favorite underrated music. For me, Walter Schreifels (vocals & guitar) is a gifted music genius who writes good lines & riffs.

If you are a fan of underrated music, or looking for one, this is definite constant, no exception.

They're new album titled "Pedals" is a long-awaited album for fans, after the former "United By Fate", Walter has been busy with his solo album and side projects.

Track listing

  1. "Wring It Out" – 3:28
  2. "69 Guns" – 3:22
  3. "Eyes Wide Open" – 3:00
  4. "Choose Your Adventure" – 3:25
  5. "Racing to Red Lights" – 4:03
  6. "Shot After Shot" – 3:14
  7. "A Parts for B Actors" – 3:38
  8. "Big Waves" – 2:59
  9. "Small Doses" – 3:59
  10. "The Ghost Is Out There" – 3:20

Personally I like '69 Guns', (great live performance below).
live@ spinner's The Interface, austin, tx


see the lyrics here

You can also listen to purevolume for the Album's single & an exclusive live.

sources: wikipedia.org, wikia.com, spinner.com

Thursday, March 24, 2011

A Junior Java Software Developer Diary # 2

Funny day long of coding. While we (me, justin & gladys) our team does our very own daily conference (chat) methodology :), I got caught typing a jejemon style word. "paupdatezzzz", was just me telling that I'm already tired.


I am neutral with all the kill em' all jejemon buzz, but it got interesting and funny. 

There are already a lot of jejemon stuff including a wikipedia article and a cool http://www.jejeschool.com :) And as for my idea, jejemon programming language!

I already made a sample for the language construct :D Happy coding!

Monday, March 21, 2011

A Junior Java Software Developer Diary

A Junior Java Software Developer Diary

Since around a month ago I've been learning a ton of information from a Godlike Java Architech ;)
So before I forget some of these priceless lessons & experience, I'll  be making a series of log about it :0.

Everything from real-world requirements gathering, proposing a design, architecture design, tools to everyday coding.

I'm really feeling lucky ;)

Thursday, March 17, 2011

My Android App in Progress!

Finally got my first Android App in progress!
thanks to Chris (http://www.kreci.net/) for the inspiration. I'll describe more of this on my next post, I need to sleep now, it's 2:23AM already.

Tuesday, February 22, 2011

Black in Black

I'm back from the depths of the void ;)
Very long since my last post here. So much have happened, unfortunately undocumented.

Fortunately, I've found a new sense of importance in logging (web). Three things.

(1)Most importantly is to have a record of your thoughts. Because definitely tomorrow will be another big day and it's likely that you'll forget most of what happened today.

(2)Next is to share, well I hope my posts do help someone out there :D

(3)And last is to monetize, though commonly thought as the root of all evil (it can), it's also an important thing for us humans to live.

Right now, so much is happening, so much stuff I'd like to todo:
  1. Android
  2. Make a great Blog
  3. My fulltime Software Engineer Job (busy)
  4. Prepare & Sell my PC
I'd like to attribute this comback post to AIC's comeback album BGWTB. I'm happy I am able to log again here ;) till next post!