Thursday, October 27, 2011

So LWUIT does that too?

I was recently developing a mobile app with the LightWeight UI Toolkit (LWUIT) that required me to save state in a database of some sort on the mobile phone and I didn't want to go in the way of manually saving bytes with the Record Management Store (RMS), so I opted for Floggy - a free object persistence framework for J2ME/MIDP applications. The main goal of this framework is to abstract the data persistence details from the developer, reducing the development and maintenance effort. In the process of reading up on Floggy, I stumbled on an old post by Shai where I discovered that LWUIT IO already has most of the persistence functionalities I need. So if at any time you need to go a little above what RMS offers, you can try out LWUIT IO, but if you'd rather not use LWUIT at all, you can give Floggy a trial instead.

Subscribe to the NEW Java Magazine

Java Magazine (1st Issue)

Oracle has just released a digital and mobile format of Java Magazine. Java Magazine will be published on a bi-monthly basis in digital and mobile formats and is an essential source of knowledge about Java technology, the Java programming language, and Java-based applications for people who rely on them in their professional careers, or who aspire to. You can sign up today here to stay informed on all things Java!

Thursday, October 20, 2011

Interesting JavaOne 2011 Content Slides and Catalog, Part 2

Here's the continuation of some interesting JavaOne 2011 tracks:

Java ME, Mobile, Embedded and Devices

Java SE, Client Side Technologies and Rich User Experiences

There are still quite a lot more interesting ones too numerous to list. You can peruse the whole catalog here. Sun in those days used to make available all the content catalog and slides as a single archive, but it seems Oracle would rather have you download them one by one in different windows.

Interesting JavaOne 2011 Content Slides & Content Catalog

The Content Catalog for JavaOne 2011 is available here. You can use the fields provided to narrow down your interest, or if you'd rather peruse the available tracks, just select the track you are interested in from the drop-down and then click the search button. When the list of sessions are displayed, click the PDF icon at the right-hand-side to download the associated slides for the session.

Here are the links to the slides (PDF) of the ones that caught my fancy:

Core Java Platform


(to be continued)

Ooops, but I didn't check this item.

It is always very important to read the changelog of libraries which you occasionally put to use. I would have spent the whole day trying to figure out why my checkbox selections weren't working well but luckily enough, I read through the changelog of jQuery 1.6 a few days ago, so immediately I discovered my checkboxes selections weren't being detected properly in the code, I knew who the culprit could be.

I recently modified some sections of a client website to use jQuery 1.6 because of the .data() method introduced in jQuery 1.5, which allows you to automatically import any data- attributes that were set on the element and convert them to JavaScript values using JSON semantics. This makes it easy to store the data you'd be using later on the node itself rather than parsing the DOM later to extract it. This feature also received a major change in the way it works in jQuery 1.6. In jQuery 1.6, this feature has been updated to match the W3C HTML5 spec with regards to camel-casing data attributes that have embedded dashes. So for example in jQuery 1.5.2, an attribute of data-max-value="15" would create a data object of { max-value: 15 } but as of jQuery 1.6 it sets { maxValue: 15 }.

Before jQuery 1.6, you can check if a particular checkbox is checked with $('#myCheckboxID').attr('checked') but that no longer works as expected in jQuery 1.6+. Previously, .attr("checked") returned the Boolean property value (true) but as of jQuery 1.6 it returns the actual value of the attribute (an empty string), which doesn’t change when the user clicks the checkbox to change its state.

In code that uses jQuery 1.6 or newer, the new method $(this).prop("checked") retrieves the same value as this.checked and is relatively fast. Finally, the expression $(this).is(":checked") works for all versions of jQuery.

So all I had to do was to change my previous code from $('#myCheckboxID').attr('checked') to $('#myCheckboxID').prop('checked'). If not that I had read the changelog earlier, I probably would have spent the whole day chasing around an unknown bug in my code.

Sunday, October 16, 2011

Hey ma'am, where are my cookies?


I recently made some big changes to a content management system I built for one of my clients about 5 years ago. I worked on the site's SEO, enabled clean URLs via .htaccess files because the CMS wasn't built with MVC where there would probably have being a main controller that routes requests to others.

The problem started after I had added all the necessary pages but spent the next few days worrying about a bug in one of my scripts, as the cookies added on some pages of the site do not propagate to other pages. Looking through Chrome Developer Tools and Firefox's Firebug, I could see all the cookies, but when I fetch the cookies via document.cookie, I only get to see some of the cookies and not all. I wondered why a script that was perfectly working before changes to it's routing stopped working. I spent several days modifying my script that manages cookies only to discover after almost a week of battling with it that you should think twice before leaving the path property of a cookie blank when creating it.

When you leave the path property of a cookie blank, it means that only websites in that domain (including the path) that set the cookie can retrieve it. For example, if you create a cookie on the page www.mywebsite.com/books and left the path property blank, it wouldn't be accessible from www.mywebsite.com/novels because the path for the created cookies are /books but you are trying to access it from /novels. So, to avoid unnecessary headache while managing cookies in your application or on your website, ensure that you set the path to the root .i.e. '/', instead of leaving it blank if you want it to be accessible from all paths within that domain.

The culprit in my case was:
document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

but I eventually overcame the problem by modifying the path of any created cookies to be '/' instead of leaving it blank as obtainable above.
document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

This StackOverflow answer saved my ass . You can read more about cookies here.

Where have you been?

It's been quite awhile since I last put up a post on this blog. I planned turning a new leaf earlier in the year but somehow couldn't as my engagements and activities kept me busy all throughout the year. There were lots of times I had a developmental challenges and plan posting the solutions I used to overcome the problems, but I just kept procrastinating all along. It was just today I decided to do it no matter what.

To start with, how has been the year so far? Beautiful I hope. Well, it has been beautiful for me too, though it wasn't without the usual ups and downs, but we however thank God we're still standing. We almost lost one of houses completely, earlier in the year as one of the tenants raised down two out of four flats with fire and disappeared into thin air, but we thank God for his mercy and faithfulness.

Was contacted earlier in the year by Microsoft via LinkedIn to send in my CV and fill the skills self-assessment document they sent to me. I had to let the Staffing Lead for MEA Services Recruitment know that I was more of open-source than closed source and last worked actively with some of their technology stacks over 3 years ago while I was at Quanteq, but they however still wanted me to go ahead and send my details. Funnily enough, I'm not even well versed with Windows 7. Seems I rated myself a 2/10 or 3/10 as I had not used the OS for more than probably 3 hours since it came out. It's not like I can't do serious stuff with it, but I've not dissected apart the way I've done with Windows XP, which is still what I use on my desktop machine. Whatever I can do on it would be with the knowledge I have with Windows XP. My OS of choice since the last two years has been Apple's Mac OS X. Anyway, the long and short of it is that the recruitment never pulled through as they needed someone with stronger MS Technical skills :)

However, if you think you have what it takes to do great stuff with Microsoft stack of technologies and would like to work with them, do contact me and if convinced, I'd forward your CV to the Staffing Lead for MEA.

It was a pity we lost our dear Steve Jobs. I never had the opportunity to meet him and never really dreamt of meeting him, but I must confess that he's touched my life in so many ways even though our paths have never crossed and beyond me being an apple fan-boy, of which I'm not one, I just love the way their products ooze cool and deliver beyond your expectations, even though my last iPod-Touch didn't last more than 3 months before it gave up the ghost. He touched our lives in so many personal, delightful & emotional ways, kept everyone on their toes & totally disrupted the industry leaving behind a few casualties. Android wouldn't have gotten this far if it hadn't been for SJ and his team, and the best Android phone today - Samsung Galaxy S II, would have had no one to steal ideas from. I couldn't control the tears as it dropped when I read the news around 3.30am the day after his death. Steve, though we never met, you were one of my greatest inspirations. Thanks for thinking different. Adieu!

Wednesday, March 24, 2010

Hollywood Actors star in Nollywood movie


Compliments to all my readers out there. Sorry I've been away for so long, it's being due to my very tight schedule, lots of codes to write, meetings to attend to and all. It's been a beautiful year so far. Hope yours too has been beautiful. I have a long list of posts lined up for this year which I'd try to post as soon as possible.

I stumbled across some information today that makes me very excited. Fred Amata is currently working on a movie in Kenya that stars big Hollywood actors like Sarah Wayne Calliese also known as Dr. Sara Tancredi in Prison Break - remember her? Hakeem Kae-Kazim (Pirates of the Carribean & Hotel Rwanda), William George “Billy” Zane Jr. (Titanic). It's a good thing to see actors like Fred Amata doing us proud by working on producing quality flicks with beautiful actors. Fred Amata has distinguished himself from the likes of Saint Obi who justified the production of substandard Nollywood movies at TED sometimes ago by telling us that they spend a million naira or thereabout to produce movies for Nigerians who spend below a dollar per day, rather than for those who live in glass houses and can afford to watch films like RobotCop. I'm really looking forward to watching the movie. You can get to read more here

Thursday, May 7, 2009

Dude, I won an SSLMatic SSL certificate!

It is very funny at-times how events unfold. Awhile back I stumbled on David Walsh's blog and I was immediately won over by the wealth of content and information available on his blog, so I subscribed to his feed via my Google reader. Last weekend, I saw his tweet via my desktop client (DestroyTwitter) that he has some free SSL certificates to giveaway and all I had to do to partake of the giveaway was to post my favorite actor/actress’ name with “FTW” after it. For example:
  • Christina Ricci FTW!
I went ahead to his blog and posted Jason Statham; who's one of my favourites because of a few of his movies that I've watched (Death Race - I'm a very gentle guy but I somehow liked the violence in this movie, probably because it made me feel as if I was playing the games I've missed in times past - , Transporter 1, 2; not yet watched 3, Crank - though a stupid movie). I rarely put in for such things because I don't believe much in them, but somehow that day I was lead to just put in my own submission and I was very surprised when I saw my name in the list of winners. Even while opening the mail pertaining to the list of winners, I just wanted to see what actors/actresses made winners of them, and there I was. Here's the comment David made about my pick:

(Jason Stathom) - The movie Snatch is unbelievable but ever since this guy’s been putting out crap. He went from a manly man to rubbish.


So Jason Statham, though as people rightly said that the movies you do these days are crappy, you made a winner outta me anyway. Thanks to David Walsh and SSLMatic.

Tuesday, April 28, 2009

The time has come...

“You may fool all the people some of the time, you can even fool some of the people all of the time, but you cannot fool all of the people all the time.” - Abraham Lincoln

Some of our leaders in power have been fooling us for years now by doctoring political elections and forcing their mandate on us such that we've lost confidence in elections in this country but I'm happy to announce that the tides are turning around for us in this country. Not everybody can be so easily bought, which was the case with Mrs. Ayoka Adebayo, the Resident Electoral Commissioner (REC) of INEC in Ekiti state, who resigned yesterday as a result of her not being comfortable with the way some elements who call themselves our leaders tried to manipulate the Ekiti elections as used to be the case with elections in this country. A copy of her resignation letter can be seen below:

The time has come when all of us who have been praying for Nigeria and who desire a change to stand up and say no to all forms of rigging and foiling of due processes in this country. Let us all be like Mrs.Adebayo and put the fear of God before us as we carry out our daily activities. If we can all imbibe this quality that has been found in Mrs.Adebayo, we'd attain Vision 2020 earlier in time. Mrs.Adebayo, heaven is proud of you with this action you've taken.


You can read more about what has been happening as regards Mrs.Adebayo case in the following links:

Mrs. Ayoka Adebayo's Resignation Letter

FG declares Ekiti State REC, Mrs. Ayoka Adebayo, Wanted!

As Ekiti State hurtles towards “June 12", FG Moves against INEC Commissioner, Mrs. Adebayo; But She Says "I am Not Hiding"

Saturday, April 11, 2009

Avoid that next coding migraine!

I discovered that reading some data into an array and dumping the whole array to disk, creates a corrupt file because null indices in the array are written to disk with each invocation of the I/O's write method that receives only the array as the argument. What I mean is this; assuming you have the following code:
URL zURL = new URL("http://www.some_server.com/some_zip_file.zip");
InputStream bstream = zURL.openStream();
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();


byte[] buf = new byte[4*1024];

int readByte = 0;
while (((readByte = bstream.read(buf)) != -1)) {
outBuffer.write(buf, 0, readByte);
curSize += readByte;

try {
Thread.sleep(20);
} catch (InterruptedException ex) {
Logger.getLogger(Extractor.class.getName()).log(Level.SEVERE, null, ex);
}
}

FileOutputStream outStr = new FileOutputStream(new File("C:/sample1.zip"));

outStr.write(outBuffer.toByteArray());


The file written to disk in the code above is corrupted even if the actual one downloaded was not, because of this line of the code:
outBuffer.write(buf);
which should have been:
outBuffer.write(buf, 0, readByte);
So please whenever you read into arrays like that, dump only the valid bytes to disk and not the whole array. This could be any oversight that will cause you headache or migraine. So please avoid that next migraine.

Wednesday, March 4, 2009

JQuery Selector Headache

Wasted some valuable time 4 days ago, very early in the morning trying to figure out what has gone wrong with JQuery-1.3.2 and even when I tried reverting to version 1.3.1, the problem still persisted and it left me wondering if there was a bug in the 1.3 releases.

To select an element with an attribute equal to a particular value, you'd write an attribute selector like the one below:

$item = $('div[@class=scrollable]");

which would select all elements matched by DIV tag that have a class value exactly equal to scrollable. I have used that feature a million times (just joking, but I've really used it so many times) and it had always worked only to fail me today. I consulted Jonathan Chaffer and Karl Swedberg's JQuery Reference Guide to cross-check if what I was doing was wrong or something; but it validated my code and I resorted to using an alternative, which was to give that element in question an ID and select it with JQuery using that ID. Of course, this would only work for cases where you can easily assign an ID to the element in question. If there are several occurrences of such an element in the document, giving each one an ID might not work for you, though you can resort to using a consistent naming scene for the IDs.

It was only after I got the script to work after selecting the element via its ID did I remember that I saved a copy of JQuery's 1.3 release features on my hard-drive. So I perused the document and discovered that such a feature as the one I used has been changed making the new 1.3 releases backwards incompatible with such selector expressions. I just felt like posting this per-adventure someone finds [her]himself in the same fix. I have always thought that I can just point my script to use the latest release of JQuery without breaking things but I have learnt my lesson that this is not always so. I also rarely take my time to read the releases features posted about the libraries I use, but now I know that it's not a good idea to be doing that. So the change in 1.3 releases as regards the attribute selector expression I used earlier is to remove the @ to upgrade. So we now have something like this:

$item = $('div[class=scrolable]"); - v1.3 upwards

Some other notable features that could break your old scripts are:
  • Triggered events now bubble up the DOM. Unsuspecting event handlers may accidentally capture more events than they're expecting.
  • The ready() method no longer tries to make any guarantees about waiting for all stylesheets to be loaded. Instead all CSS files should be included before the scripts on the page.
  • .isFunction is simpler now, it no longer handles some strange edge cases (in favor of simplicity and performance).
  • The order of "a, b, c" style selectors may change. Browsers that support querySelectorAll (Safari, Firefox 3.1+, Opera 10+, IE 8+) will return the elements in document order, other browsers will (currently) return them in the order specified. In an upcoming 1.3.x release all comma-separated selectors will be returned in document order.
  • The trigger and triggerHandler methods no longer accept event objects within the data array. Instead they should be specified directly as an argument.
  • The undocumented 'extra' function is gone from trigger and triggerHandler functions as well.
  • The internal jQuery.event.trigger no longer returns the last item returned by a handler, instead it return true or false as per the W3C specification. You should use a jQuery.Event object to capture the specific return value.
  • You should always be sure to run your page in standards mode. There are known issues with methods not working correctly in quirks mode (including errors in the selector engine in Safari).

The following properties have been deprecated (in favor of feature detection and jQuery.support, as discussed in the Overview).

  • jQuery.browser
  • jQuery.browser.version
  • jQuery.boxModel

The following browsers are no longer supported:
  • Safari 2