Chris Mar's Weblog Blog Different

Monday Mar 17, 2008

This weekend, I finally figured out a good method of propagating events on my web page to notify other elements to update themselves. When your working on an AJAX application there is a need to update other sections of a page based on an event. This can be done manually, but I'm dynamically building my page content and the event generator does not know ahead of time who might want to be notified. So, I present my solution below, I'm sure this is old news for the pros, but it took me a while of combing through documentation to figure it out.


First Lets create something to generate an "Event".

<% form_remote_tag  :update => "my_results_div",
	:url => { :controller => 'posts', :action => 'add_post' },
	:complete => "document.fire('posts:updated')" do -%>
	...
<% end -%>

The important part is the statement document.fire('posts:updated') on the complete. This is a prototype method to fire an event. You must put your event name within a namespace like so I prefixed mine with "posts:"


Now, create a listener for the event.


document.observe('posts:updated',  function() {
	new Ajax.Updater('post_titles', '/posts/titles_list', 
	{ method: 'get',
	  evalScripts: true
	});
  });

So, now anywhere in your page you can add the above statement document.observe('posts:updated'.... When someone calls document.fire all listeners will be notified, at which time they can update themselves. The above example does an ajax update of the div 'post_titles' with the results from my controller method '/posts/titles_list'.

I broke my page into lots of little dynamic widgets, and each widget self registers for the events they are interested in. Then I have my main section of the page fire the appropriate events at the right time.

The above code was shown using Rails and Prototype, but you could just use Prototype and your own scripting language.

Friday Mar 07, 2008

I didn't realize how difficult it would be to obtain a Time Capsule. I called every day this week and finally on Friday the Tyson's Corner Apple Store got 20 in stock, 10 of each size. They sold out in a couple of hours, luckily my wife was nice enough to leave work and pick it up for me. Judging by the comments from the Apple Store employee's these things are hot and they are dealing with tons of phone calls daily. Who knew it would be this hard to get a wireless router?


I did some initial speed tests from the other side of my house. I'm keeping the Time Capsule in 802.11n only mode:

Time Capsule Speed Tests

More updates soon as I figure out all the settings, this is more complicated then I normally expect from Apple :)

Monday Mar 03, 2008

When the new Mac Book Pros were released last week, I decided the Pynren and new touch pad didn't warrant an upgrade. So, I decided to upgrade my current 2.4 GHz Mac Book Pro. Here are a couple tips on ways to upgrade your current MBP and make it a Super Mac Book Pro.

Upgrade your memory to 4 GB

I was surprised how cheap laptop memory has become. You can get a 4GB matched set from Mac Sales for only $95.00 now. Amazing! Upgrading memory is very easy, Apple even has a help page.

Upgrade your Hard Drive to 320 GB

You can purchase this Western Digital 320 GB Passport 2.5" USB 2.0 Hard Drive for $169.99. Some guys at work found this drive for $149.00 at Best Buy. The trick is the drive inside is actually much nicer then the specifications posted on Amazon. Once you crack it open you will see that it is actually a Western Digital Scorpio (320 GB, 3 Gb/s, 8 MB Cache, 5400 RPM). A VERY nice drive for only $169.99.


Doing the upgrade is made very easy because of the external enclosure it comes with. You plug the drive in and use Disk Utility to "restore" your current drive to the external drive. Then you just have to crack open the drive, shown in this video being done one handed.


Once you have cracked open the WD case, you can open your mac book and perform the swap. I followed this photo walk through. After the 320GB drive has been installed, you can take your old drive and put it in the external case, so you still have 150GB external drive. I've decided to not reformat my old drive for about a month, just "in case".


The memory upgrade is very easy, the hard drive is a little more challenging. Please make sure you track all the screws and their locations because you pull a lot of them out and they are all different sizes. For tools you need a #00 screw driver and a T6 Trox. You can pick both up from Sears for about $4.00 each.


Note after your restart your computer from the hard drive swap. Spotlight will reindex everything. This took about 20 minutes and was spiking my CPU. At first I thought the new drive and memory was much slower, but once Spotlight (mdworker) stopped. Everything seemed much snappier then before I started.


Good Luck building your Super Mac Book Pro

Friday Feb 29, 2008

When doing straight JDBC coding, wouldn't it be nice if you could .merge() functionality even though you are not using ejb3? Recently, I discovered a way to do this using the Oracle statement "MERGE" to perform an "UPSERT" for me. UPSERT meaning please either update the existing record or create a new one for me.

The trick is using Oracle's MERGE command which is designed to merge records from 2 different tables. Since, I'm only inserting new data, I used a SELECT from dual to simulate selecting from a table. Then Oracle tries to see if an existing record is available based on the conditions specified in the "ON" for the "USING" statement.

This works perfect and is going into production on a system using Oracle 10g.

Enjoy, I've hand written a lot of UPSERT code in the past and it is never quite this elegant:

PreparedStatement statement = null;
try {
     statement = connection.prepareStatement("MERGE INTO ARTICLE a " +
                              "USING (SELECT ? title, ? author, ? body FROM dual) incoming " +
                              "ON (a.title = incoming.title AND a.author = incoming.author) " +
                              "WHEN MATCHED THEN " +
                              "UPDATE SET a.body = incoming.body " +
                              "WHEN NOT MATCHED THEN " +
                              "INSERT (a.title, a.author, a.body) " +
                              "VALUES (incoming.title, incoming.author, incoming.body)");

     statement.setString(1, "Title of Article");
     statement.setString(2, "Author Name");
     statement.setString(3, "A Cool Story from Last Night");
     statement.execute();
}

Tuesday Feb 05, 2008

Recently, I was upgrading some Rails projects to Rails 2.0. For some reason they changed the name of view files from ".rhtml" to ".html.erb". While your old file names will work, I like to keep things nice and neat. Here is a tool that will help you do the mass renaming, and its free! I wish I had this utility years ago.
Many Tricks Website

Wednesday Aug 22, 2007

 Products Sleevecases Images Prod Sleevecase Detail 5 After spending more time researching then any human should. I have finally found the perfect laptop sleeve for my Macbook Pro. Gary Waterfield hand makes these in San Francisco to custom fit your laptop. It is a soft neoprene covered with ballistic nylon. The stitching and seams are impeccable. I ordered mine with the extra d-rings and strap so I can use the sleeve as a light weight carrying case. I firmly believe in supporting Made in the USA products and the quality of this sleeve is a perfect example of what someone can accomplish when they build it themselves rather then outsourcing to overseas factories. You do pay a premium, but its well worth it. The quote from their website says it all.
No mass production or overseas workforce. WaterField bags are designed and made in San Francisco, where rent is high, labor is expensive and competition is intense. We wouldn’t go anywhere else!
http://www.sfbags.com/products/sleevecases/sleevecases.htm (I got the sleeve with the extra flap so I could use it in both my backpack and in a messenger bag)

Thursday May 04, 2006

Facebook has added Sun Microsystems. You can now join facebook with your sun.com email. There are already a good number of people in the Sun Microsystems network. Don't be left out! www.facebook.com

Make sure you join as "work", and it will automatically place you in the sun network.

Wednesday Apr 12, 2006

CNN/Money rated Software Engineer as the best job to have in America. I have to say I agree :)

Read the Full Story

Excerpt:

1. Software Engineer

Why it's great Software engineers are needed in virtually every part of the economy, making this one of the fastest-growing job titles in the U.S. Even so, it's not for everybody.


Designing, developing and testing computer programs requires some pretty advanced math skills and creative problem-solving ability. If you've got them, though, you can work and live where you want: Telecommuting is quickly becoming widespread.


The profession skews young -- the up-all-night-coding thing gets tired -- but consulting and management positions aren't hard to come by once you're experienced.


What's cool Cutting-edge projects, like designing a new video game or tweaking that military laser. Extra cash from freelance gigs. Plus, nothing says cool like great prospects.


What's not Jobs at the biggest companies tend to be less creative (think Neo, pre-Matrix). Outsourcing is a worry. Eyestrain and back, hand and wrist problems are common.


Top-paying job Release engineers, who are responsible for the final version of any software product, earn six figures.


Education Bachelor's degree, but moving up the ladder often requires a master's.

Wednesday Jun 29, 2005

Its midnight and I just got home from the rockin After Party at Java One. I can't believe the party Sun threw for us. They had 2 bands perform and Dennis Miller. The first band was an all female Led Zepplin cover band called Zepperella. They were really good, funny hearing a girl sing Robert Plant, because she sounded just like him. Then came Dennis Miller. He is so funny, he was killing tonight. Everyone seemed to be enjoying him. Most of the hour was his typical rants and satires on politics and current affairs. I'm sure most of the international attendees were offended or at least missed most of the jokes. He seems to have a lot of hatred towards the French and Germans. I laughed a lot, I guess thats all that matters. To end the evening, Sun brought out a band named Camp Freddy. This is a great cover band with members from Incubus, Janes Addiction, Alice in Chains, Sex Pistols and The Cult. They rocked the crowd, and even the geekest of us seemed to really enjoy them. Of course, Sun provided great food, and entertainment in the party. Plenty of video games, fooseball and pool tables. Thank you Sun!

Wednesday May 25, 2005

If you haven't been paying attention to the memory usage of your Dashboard Widgets, you should check out how much Active Memory they are taking up via your "/Applications/Utilities/Activity Monitor". If you hadn't noticed their memory usage is always increasing. After running 4 Apple supplied Widgets: Weather, Stocks, Calculator and Dictionary, for a week they were taking up to 20 MB each! They start around 6 MB when launched, but as time goes by they take more and more memory. I actually noticed my computers performance decreasing which lead me to this discovery. Others, have reported the same issue, with some people claiming their Widgets are using up to 300 MB.

For now, I've removed all Widgets from my Dashboard until Apple releases a patch. As a fix, you can restart the dock since the Dashboard process is owned by it. Or you can manually remove the Widgets from the Dashboard. Using Activity Monitor, you can "kill" the Widgets and they will restart.

If you guys check out your Widget memory usage and its huge, let me know. My friends Weather widget was taking 75 MB of Active Memory!

I can't believe the amount of hits this article is getting. Seems like more people are finally realizing this is a major issue. 10.4.2 is due soon, hopefully they will have a fix.

The current record holder in the comments is 517M for the Weather Widget!

Friday May 20, 2005

Last night, I finally graduated with my Masters in Computer Science from George Mason University. I say finally because I've been working on this degree for 6 years. Working full time, going to school at night and taking one class a semester really drags out the time it takes to complete your course work. Add that on top of having to take a few undergraduate courses since my bachalors degree is in Electricial Engineering. I knew it was something I wanted to do, didn't realize the amount of work that would be involved, but I can say that when i walked across the stage last night I got a little choked up.

Thursday May 05, 2005

After, upgrading my system to Tiger. I found that I could not click on any of the items on my desktop (They were accessabile via a finder window). During the upgrade, the desktop picture switched to a plain blue color. I could not switch the picture via System Preferences.

I was finally able to fix my issue by deleting the ~/Desktop/.DS_Store file and rebooting. This caused my desktop to rebuild itself. When the reboot came back, the image I had tried to select in System Preferences actually came up as well. Selecting of my desktop items returned as well. I'm feeling a little better about Tiger now :)

Note: if you are going to do this fix, you need to use Terminal to remove that file because its not visible via Finder.

Thursday Mar 17, 2005

We just fixed a bug in our code that was a result of Serialization and subclassing. We created an AbstractBase class that contained a few attributes. Our child classes all extended the AbstractBase and implemented Serializable. Well, the values in the AbstractBase did not get serialized when we sent our objects over JMS.

When the objects where inflated on the other side, the values in AbstractBase where reinitialized via the AbstractBase constructor. Because the default values were almost always the expected values, we missed this in testing. When we did our Junit tests the error did not show because the objects hadn't been sent over the wire via JMS.

Moral is the attributes of your parent don't get serialized if your parent doesn't explictly declare they are serializable.

Monday Mar 14, 2005

I was able to use the Sun Perks in 2 different stores this weekend. With a grand total savings of $68.00! First, I went to Franklin Covey to get a new binder. I just told the guy I worked for Sun Microsystems, and he gave me 20% off the purchase. I decided to go with a non-leather binder, after beating up my leather one so bad. Next up was Sharper Image. I used the http://sun.corporateperks.com to print out coupons that gave you $30 off of $150 at Sharper Image (in store or online). My wife and I went in and bought 2 of the new Bright as Day reading lamps. We didn't want to run into issues of who could use the reading lamp, so we, of course, had to get two. The lamps are great and they seem to live up to their claims of less strain on your eyes, less glare, and a more pleasent reading experience. Thats a grand total of $68.00 savings thanks to Sun Perks!