Wednesday, December 26, 2007

Merry Belated Xmas: Take a stroll down Ext Lane

Took a bit of break from blogging and spent some time bonding with the family, doing some fun coding, watched a sick amount of movies and even did a bit of exercising. Wow, that seems like a lot to put in one sentence. Well, now it is time to get back blogging! It's almost the new year but I have plenty of articles left to write in 2007. Without further ado, let's take a stroll down Ext lane!

I spent a fair amount of time tinkering with new technology. At least new to me. I didn't really have a term for it, so I have dubbed it fun coding. Alas, I happened to go to Javascript, its nothing new to me but I haven't really gotten a chance to sit down and play with Ext 2.0 yet. I am amazed by what you can do with around 65 lines of code. Makes me want to learn more about what dynamic languages can do for me! Who wants verbose statically typed java/c# anymore! Ha, I kid. But, I could potentially cut my code base by half if I went to dynamic languages such as python, groovy, or ruby. I am sure there are others but the aforementioned languages came to mind. Anyway let's check out some ext code that I wrote up:

Ext.onReady(function(){
var north = new Ext.Panel(
new Ext.BoxComponent({ // raw element
region:'north',
el: 'north',
height:32
}));
var west = new Ext.Panel({
region: 'west',
contentEl: 'west',
title: 'Nav',
width: 200,
minSize: 175,
maxSize: 400,
collapsible: true,
margins: '0 0 5 5',
cmargins: '0 5 5 5',
layout: 'accordion',
layoutConfig: {
animate: true
},
items: [{
title: 'Nav1',
autoScroll: true,
border: false,
}, {
title: 'Nav2',
border: false,
autoScroll: true,
}]
});
var center = new Ext.TabPanel({
region: 'center',
contentEl: 'center',
border: false,
activeTab: 1,
tabPosition: 'top',
items: [{
html: '

Test Me

',
title: 'Tabby Tab',
autoScroll: true
}]
});
var south = new Ext.Panel({
region: 'south',
contentEl: 'south',
split: true,
height: 100,
minSize: 100,
maxSize: 200,
collapsible: true,
title: 'South',
margins: '0 0 0 0'
});

var viewport = new Ext.Viewport({
layout: 'border',
items: [north, west, center, south]
})
});

This is a basic skeleton that you could work with. You could refactor these parts to be extended ext objects, and then add your own custom functionality to these pieces, but I leave that as an exercise for the reader. This could be another blog post if someone is interested in it. Just holler!

Still did a bit of plugging away with GWT. I find it verbose, but manageable. I wanted to show you, but it is too much code. I will make another post specifically on GWT soon.

Still striving to make my way to a (close to) perfectly working, usable example of ext with a JEE middle tier, and , that hopefully you can use as a skeleton for your own projects. I have my basic interface designed but the database needs to be worked on. I am trying to be careful, because there are many potential features that could go into a workout program and there is only one person to maintain the code! Hence, I want to make the code as brief as possible.

I do hope you all had a great holiday and I will be posting soon. I figure I gotta talk about some of the movies I saw. Oh boy, there are some great ones (Live Free or Die Hard) and some really horrible, I-can't-believe-you-call-this-piece-of-trash-a-movie movie(Lions for Lambs).

Update: I need to find a better way to post code. Please bare with me for the time being!

Tuesday, December 18, 2007

Lead by example: spring/hibernate/shards

When I wrote the posts about using Hibernate and Hibernate shards, I did so offering very little code. I realize that doing so does not provide you, the reader, enough to go out there and actually want to try this technology. That is my fault.

I am happy to announce, that I am now working on a simple Spring/Hibernate example that you will be able to download and hack together however you please. Following that posting, I will dissect the main points of that project. At least, the main points that I derive from it, but I encourage comments that lead me to be even more clear about topics that I did not discuss. Some of the main ideas I want to hit on are:
  1. Hibernate => by example'
    1. Creating your data layer
    2. Basic ORM management
    3. Sharding
  2. Spring => Why use it?
    1. Dependency Injection
    2. Inversion of Control
    3. MVC
Yea, that's going to be a few posts. But I think it will be worth it. I hope you agree. I recently found a quote that lead me down this path that I am about to embark upon:

“Tell me and I'll forget; show me and I may remember; involve me and I'll understand.”

I think it is perfectly valid. You won't learn by just reading. You will learn by me showing you by example, and by interacting with my example. Hopefully at that point, you will understand it.


Monday, December 17, 2007

Free movie screenings!

My buddy John and I were walking around the Irvine spectrum, grabbing a bite to eat and taking in the ambiance of the first week of Xmas shopping. Yes, it was a mad rush, but they had all the Xmas classics playing over the outside speakers, like carol of the bells, twas the night before Xmas, etc. On our way going through the outdoor mall, we passed by the movie theatre and were astonished by how many people were in line.

We looked at each other and said what the hell is going on over here? What opened? Moments later a friendly gentlemen approached us and asked us if we wanted to know what all the commotion was about. We of course said, "YES! What is going on over here!" The dude, carrying a satchel explains to us that everyone is in line for a free screening of Get Smart, which does not come out until the summer. He then asked us if we wanted to go to the next show. We said hell ya! Free MOVIE!! WOO HOO!

We came back not more, then three hours later and stood in line for Get Smart, filling out some annoying questionnaires for the company that put on the screening. Small price to pay for a free flick in my opinion. There were lots of friendly people in line. There was a hardware designer in line asking us if my friend and I would like to work in the defense industry, to be glorified code monkeys. No thanks!!! He was a nice, old chap. The other people we met in line, were geek central, but they were fun! Naturally people just coming to the spectrum were interested in all the hub bub like I was and it was fun to play with them. The geeks and I were having fun telling people all sorts of things. Yes, we are in line for a free bucket of popcorn! Oh yes, we are in line for Batman, The Dark Knight! Pardon me, oh why are we in line, ah yes, we are here to get free movie tickets for a year! Oh it passed the time, we stood in line for a good ten hours. HA, just kidding, more like 45 min. We had fun talking with our new found friends.

I suppose I should actually talk about the movie. I had absolutely no expectations about this movie coming into it, so it would be pretty hard to disappoint me. Needless to say, I did enjoy it, and especially liked Steve Carell's performance. It was pretty damn funny too! Some of the jokes really were pretty adult. I'm laughing now about a few of them, but I would hate to give it away so I will stop there.

At the end of the movie, we had to fill out a form and give our opinion about several aspects of the moving. For example, we were asked to rate how the movie flowed in the beginning, middle an end. We had to rate the actor's performance, name five scenes we liked as well as five scenes we did not like. It was a good two pages of writing that we had to do, which I am sure is far more valuable then the free movie we got to see. But let's face it. I wasn't going to see this movie in the theater. So they made money off off of me, and I got to see a movie that I was pleasantly surprised with, that I would probably not have rented.

As we walked out of the theater, we were approached by the same guy that gave us the tickets. He asked us how we liked it, and we told him we did. He then said, well, how would guys like to see another screener?! I am a sucker for a free movie that no one else can see! Turned out to be Balls Out: The Gary Houseman Story. FREAKIN' HILARIOUS. You have to see that one, just go to the theater and see it!

Thursday, December 13, 2007

Scare Fest 07': Knott's Scary Farm Halloween Haunt Map!

As Promised, the map is here. Unfortunately it is gray scale and about 5 megs. But it does do the map justice as you can actually read the letters on the page and get a feel for how Knott's is laid out during this wonderful time of year.

Click here to download!

Enjoy!

Wednesday, December 12, 2007

Hibernate Shards

I suppose I have been on sort of a hibernate kick, but my buddy John was asking about this tonight. So I decided to give a short little description of what it is and why is it useful.

I have explained what Hibernate is, but not demonstrated it through a deployable example. So I apologize ahead of time, if you have not used Hibernate and are still scratching your head wondering what the hell I am actually talking about. That is my bad, and I will correct it.

Moving right along, lets describe what a shard is. Simply put, a shard is a database that exists in a set of databases that contain the same schema aka shards. What makes a single shard special is that it does not hold all of the information for the entire application. It holds a very specific amount of information that pertains to the rule that is given to the Shard Strategy algorithm. Let me give you an example. Let us assume you have a database full of users. Let us also assume that all of those users have contacts. We have a three shard solution. Now, I can implement a sharding algorithm that says, put all of the users that have a login name of A-J in shard 1, K-T in shard 2, and T-Z in shard 3.

What is the benefit of doing this? The obvious benefit is that I have now gone from one pipe of average size, to three pipes of average size. That is huge! The strategy I may have implemented is not perfect so I will not always get the benefit from having three pipes, but with a better Sharding Strategy, I can theoretically get three operations done at once a majority of the time.

This is basically a solution to provide horizontal scaling of a database. I can increase to any number of shards I want, as long as I specified at the beginning of the project how many shards I wanted to use at the beginning. If you did not, you can still do it, but it will be painful, so think long and hard about that. And I hope you have a nice DBA at that point :).

There are some drawbacks to this type of thinking. You cannot implement cross sharding joins. They are currently not supported. You can't increase the number of shards easily, from what I have described in the previous paragraph, so you would have to use something called virtual shards to make your process a bit easier. Distributed transactions are not supported by hibernate shards as well. Oh yea, and its in beta, so hopefully you won't come across too many bugs.

With that being said, I think the positives outweigh the negatives and if it worked for YouTube, I am fairly certain it might work with your project as well, if it gets to that size where you need to be concerned about database scaling and replication ( Vertical Database Scaling) is not able to cut the mustard.

Hopefully I have given you a really fundamental idea of what is going on with hibernate shards. Feel free to ask questions and I will answer them to the best of my ability. I will try to create a project to show off what this brilliant technology accomplishes!

Here is a link to documentation if you are interested:
http://www.hibernate.org/hib_docs/shards/reference/en/html/

Scare Fest 07': Knott's Part 2

Sorry Folks, didn't get the map in there. But I will once I find a nice color scanner that can do the Knott's Scary Farm map justice! But just a few more comments on this past years experience:

The Hanging was as biting as ever. It featured Mad Max in a futuristic world, with all the regular ribbing at the celebrities' expense. They roasted the Pirates of the Carribean, Paris, Britney, Lindsay, and Tom Cruise just to name a few of the celebrities that got RIPPED. And, as with tradition, a celebrity is hung at the end of the show. This year however, was truly lame; they hung Sanjaya from American Idol. Wow, did not expect that one! In fact, the field was so rich from all the idiot things celebrities have done this year that they most likely said, "Hey lets just choose someone that no one would expect. That will really throw them off!"

I went to see Hacks right after that so I could sit down for a bit. At this point I was walking around for around five hours and just wanted to rest. This show had its bright points for being staged. Some of the jokes were a bit racy, which made them that much funnier. If I had started this blog in October, I would be able to offer you examples of the funniness, but alas I didn't so you will have to wait for next year to hear them.

Lost Vegas was pretty good this year. This maze is set in twisted, twilight zone existence that became of Las Vegas. At first glance this maze doesn't look as intimidating as the scarier mazes that I went through, such as the log ride or the doll factory. But it was, they had some well placed black-out monsters. A black-out monster, if this is not obvious, is just a monster that blends into the background. The black-out monsters that I experienced were almost indistinguishable from the background and three of them came from all sides of me and made me jump onto the ceiling! It was terrifying. That and the hot girl that was on a strippers pole that made maze worthwhile.

That was it as far as Knott's was concerned, the rest of the mazes were ok, nothing really changed about them if you had gone the previous years. Until next year, I will not have pleasure of writing another one of these articles about the most storied haunt of them all!

Next haunted review: Shiprweck aboard the Queen Mary ship!

Monday, December 10, 2007

Scare Fest 07': A Year in Review

Ah, Halloween is such a festive, happy time of year for me. You get that first hint of briskness in the air. The leaves start to change color. It starts to get a little darker at night. These are the signs to me that Halloween is coming soon. The time to be scared is upon us! Unfortunately 2007's season has come and pass leaving me to look forward to the next. But what makes this season so special?

Typically, I like to enjoy Halloween by going to several Haunted Houses and to Disneyland. I prepare myself for this special month by seeing lots of scary movies. Since I never watched scary films until seven years ago, I have missed quite a lot, and there are plenty for me to digest every year. I say every year like I have been doing this for a while. In all honesty, I have only been celebrating Halloween seriously for the last two years. Those two years have been such a good time, I now consider it a tradition! And by far, going to Haunts is the most fun tradition to have.

Going to Haunted Houses is such a great rush. This year I went to three different haunted houses. The first Haunted House I went to this season was Knott's Scary Farm. This particular haunt has been around for 35 years. They started the haunt business. For those of you who have not heard of it, it's Knott's Berry Farm dressed up for Halloween. The nice people at cedar fair haunt the ENTIRE park. That includes 13 mazes (more like labyrinths) and four scare zones. Scare zones are areas of the park where monsters like to be sneaky, and try to catch you off guard and scare the pants off you. They are very good at that. Tomorrow I will upload a map of the park but for now here is a list of the mazes, scare zones and shows:

Mazes:
  • Feary Tales
  • The Asylum
  • 13 Axe Murder Manor
  • The Doll Factory
  • Lost Vegas in 3-D
  • Black Widow's Cavern
  • Pyromaniax
  • Killer Klown Kollege
  • Dark Realm - Laser Rage
  • The Grudge II
  • Lore of the Vampire
  • Red Beard's Revenge
  • Labyrinth into Darkness
Scare Zones
  • Ghost Town
  • Silver Bullet Mining Town
  • The Gauntlet
  • CarnEVIL
  • Fortune Tellers
Shows
  • The Rocketz
  • The Hanging
  • Death of Dr. Cleaver
  • Hacks!
  • Inferno
  • The Chipper Lowell Experience
  • Zamora's Side Show of the Bizarre
Now I'll be the first to tell you that this is almost impossible to do in one night, even on a slow night. You might be able to do half of the park on a very busy night. But as you can see, that is a lot of stuff to do. So where do we start? Everyone loves a good maze.

One of my favorite mazes is Red Beards Revenge. This maze is set aboard a pirate ship...surprised right?! It was well decked out with a unsteady bridge that you cross with pirates coming down from the ceiling which absolutely terrified me.

Pyromaniax is terrifying. Let me try to paint the picture. Have you ever been on the Matterhorn at Disneyland? If not picture yourself on a canoe going down a white water river. Now, imagine yourself going down a white water river where toxic waste has mutated all of the townsfolk. Monster's pop out of every hidden corner and get right in your face. This was by far the best maze Knott's had to offer.

Another maze I liked this year was the doll factory. Knott's put a lot of detail into this one! This might have been mimicked from the movie Dead Silence, and that was pretty creepy. Anything involving dolls is creepy!

I just realized this post is getting quite long so I am going to break up my review of Knott's Scary Farm into a two part special treat. I will post the map tomorrow so you can get a general idea of what I am talking about.

Friday, December 7, 2007

My Big Move

Sorry for being incommunicado lately, I am in the process of moving out of sunny, warm California to the freezing, snow covered east coast! I have recently accepted a software engineering position out here and I can't wait to start. With that being said, I haven't had access to a computer for a couple days, so just wanted you all to know, about a few articles I have been thinking about that I am planning on writing:
  • Hibernate: A more concrete example that will show off the full capability hibernate offers.
  • Scare Fest 07', Belated Haunt Reviews!
  • Spring 101
  • The MVC approach
  • Practical Programming
  • Free movie screenings!

That is coming up!! Not necessarily in that order, as I am really excited to talk about the Halloween goodness that came and went in October. It was one of the most fun months I have ever had this last year. But we can talk about that later.

Hope you like what I have in store!

Tuesday, December 4, 2007

Hibernate: What is it, and why should I use it?

If you had asked me this question a few years ago, I would not have known how to answer it. I might have said, "Sure, isn't that what animals do in the winter time to conserve energy?!!!" ERRRRRRR, wrong! Well, it's partially correct. They do, but that is not what we are talking about here. It actually is also a great piece of software that I am not sure how prevalent it is inside the developer community. Hence, I will try to give you a quick intro to describe what hibernate is. Hibernate is an ORM, also known as an Object Relational Mapper. It maps database tables to Java or C# objects. You can use XML to map the elements of the table, or, if your using Java, the advancement of JPA (Java Persistence API) allows you to map the elements of the database table inside the class. That may be a lot to suck down so let me try to explain all of this with some sample code.

Here is a sample table from a database:
mysql> CREATE TABLE Car(
id INT,
data VARCHAR(100),
color VARCHAR(20),
engine VARCHAR(20),
type VARCHAR(20)
);
So now we have a table named car in a mysql database. Let's make a pojo using JPA, which makes use of Java annotations:

@Entity
@Table(name = "Car")
public class Car {
private Integer id;
private String data;
private String color;
private String engine;
private String type;

public Car () {
}

@Id
@Column(name = "id", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId(){
return this.id;
}

public void setId(Integer id){
this.id = id;
}

@Column(name = "data", length = 100)
public String getData() {
return this.data;
}

public void setData(String data){
this.data= data;
}

@Column(name = "color", length = 20)
public String getColor() {
return this.color;
}

public void setData(String color){
this.color= color;
}

@Column(name = "engine", length = 20)
public String getEngine() {
return this.engine;
}

public void setEngine(String engine){
this.engine= engine;
}

@Column(name = "type", length = 20)
public String getType() {
return this.type;
}

public void setType(String type){
this.type= type;
}
}

Now we have a pojo that is mapped to a database table. This is the heart of the matter. So what good does this do for me? This leads us to question why should I use it.

Simply put, this is a very quick way to abstract a data layer for any project that needs access to a database. If you have a team of programmer's that have a limited knowledge of SQL, and mostly have knowledge of Java or C#, the results that hibernate will provide in productivity alone are worth it. Here are a few reasons off the top of my head that I have come up with:
  1. It is just not worth writing inefficient stored procedure's that your dev team will struggle with, that will ultimately have to be replaced later. Changes to these SP's could percolate all the way down to the business logic layer of your app. Definitely not good.

  2. An even worse solution if your team does not know about sp's would be to use inline SQL in code. This should be avoided at all cost unless you have only one or two tables and you don't really care about the application you are writing about. Inline SQL IS THAT BAD. Please avoid it to make your application easier to support. Support will love you for this! Not only that, new features will be easier to add, and database modifications will be easier to make since you have confined all of your logic to one layer.

  3. Hibernate is pretty easy to implement, check out the documentation and in about a day you will have a data layer you did not have to write from scratch. You can then focus more of your time on other equally important aspects of your application, like the business logic layer and the front end.
Things get more interesting when you start to relate tables and later on I will give you a more complete example. Hopefully I have explained what ORM's are and you can start digging in and checking out what these ORM's could offer you and your company in the future! Leave a comment and I will answer questions to the best of my ability.

Hope this helps!

Sunday, December 2, 2007

(In)Formal Introduction

Welcome to the Life, Code and the Pursuit of Happiness. These are articles conjured up in my head, from situations that arise in my life, most likely stemming from one of the three principles from the title. I am hoping to delve into all three of these topics from time to time but mostly focus on my passion in life; code. I use a lot of different tools, languages, principles to create my projects but primarily, use technology on the following list:
  • Java (JEE)
  • .Net (C#/WFC)
  • JavaScript (particularly the EXT framework)
  • Spring
  • Ruby
  • SOA
  • Web Services
  • IDE's (Eclipse,MSVS)
Ok, so code is not all of my life. Sometimes I play video games. So, occasionally I will talk about them. I do not play world of warcraft, or other mmorpg's(massively multiplayer online role playing games), those are way too fancy. Well, that and just way too addictive. But hey, to each their own.

I might also talk a movie or two, since I love them. Who doesn't? Well if you don't, I won't hold it against you.

Anyway, welcome to my blog!