Friday, April 25, 2014

The Programming Dilemma

Software is code. Code is structure. Structure is meaning. Meaning requires structure. Almost by definition, structure does not change or adapt or otherwise it would lose meaning. So, in order to simulate "adaptable-ness", you have to make it configurable. But there is still structure, because there are still unchanging structures that information must flow through.

You could in theory make software completely dynamic (as in get or send anything from or to a system) but then you would have to do some kind of "programming" on the client side in order to use it. For example, say I want to make it possible from the client side to be able to get any information possible out of my software system. One option is just make every piece of data available in every possible known combination (a herculean task). Or create some kind of "query" language to get the data out of my system. In essence, the application just becomes a domain specific language on top of your database.

Programming is supposed to make it easier to to do things. Users want to point and click to make things happen. They don't want to write code to make it happen. But then people want things to adapt to their needs. So you add configuration. The tradeoff is that now the system is harder to understand how to use. Taken to the extreme for flexibleness, your application becomes a maze of knobs and switches. Which oddly enough, to setup, feels a bit like programming something. So you end up programming the program. I thought the point of programming was to not have to program?

I've come to the conclusion that an application is really only 100% useful for one company max. As soon as you involve more than one company, there are differing opinions on how things should be done. There are differing opinions within a company, but a least at a company level, policies can be adjusted. To support more than one company, you have to either be dogmatic and say "you have to do it this way" or make a configuration option. As soon as you begin down the road of configuration, it becomes harder and harder to know how to use the software. It's a problem that if is not checked will bring the software to it's knees and it will die a slow hard death.

Programming doesn't really solve problems very well. It solves one problem and creates ten other ones. It is inherently self-defeating. I've said it before and I'll say it again, "software is hard", and yes it always will be.

P.S. I think it is wise to keep an eagle eye out for what NOT to program rather than what to program. There is no shortage of things to program. It takes gutsy, courageous leadership to say "we are not going to program that because it will create to many additional [programming] problems".

Tuesday, June 11, 2013

Getting your iPhone 4,4S, 5, or 5S fully working on Straight Talk

If you want to use your iPhone 4, 4S, 5, or 5S on Straight Talk, it's usually pretty easy, or I should say was easy (as of this writing I don't think Straight Talk is offering any AT&T compatible SIM cards for purchase on their website). All you normally would have to do is install the correct configuration profile from http://www.unlockit.co.nz/unlockit/ and voilĂ  you had data. But not full MMS, only iPhone to iPhone over iMessage.

Since I'm picky when it comes to my phone, not having full MMS functionality did not sit well with me. The solution I came across was to use a t-mobile sim to activate the cellular data settings. The process I used is detailed below.

First some preliminaries:
  1. Get your iPhone factory unlocked. Either through AT&T here or by purchasing a factory unlock service on eBay. I had to do the eBay unlock service because the AT&T unlock didn't work for me. Either way, once one of those unlock methods work, you'll need to restore you phone in iTunes for the unlock to be effective. It will tell you that your phone is unlocked when the restore completes. I believe it is required in order for the Cellular Data Settings to come up when you use the t-mobile SIM later.
  2. Get an inactive T-Mobile micro SIM. eBay is great way to get one, just make sure it is a micro SIM, not a standard size SIM. Otherwise you will have to cut down the standard size sim to micro sim size, so save yourself the trouble and purchase a MICRO SIM.
Now for the actual process:
  1. Turn off wifi. Keep your existing APN configuration profile in place. It's good to have it there just in case the APN settings reset randomly. This has happened to me a few times.
  2. Open the Notes app so that it is in the background for later.
  3. Insert T-Mobile SIM into iPhone. Wait a few seconds and go to Settings > General > Cellular > Cellular Data Network. If you don't see the Cellular Data Network menu item, it might be because your phone is not unlocked.
  4. Switch to Notes app. Do this by double tapping home button and select the Notes app. Stay in the Notes app.
  5. Insert Straight Talk SIM. It's important that you stay in the Notes app for at least a minute as different things flash up in the upper left corner of the screen. Wait till it says HOME and stays on HOME.
  6. Switch back to Settings. Do this by double tapping home button and selecting Settings app. Settings should still be on the Cellular Data Network screen.
  7. Enter Straight Talk settings. The settings here should do the trick.
  8. Go back to General. Hit the back button in the upper left corner to get back to the General screen. Your settings should now be saved.
  9. At this point your phone should be good to go but you may need to reboot the phone for everything to take effect.
Some other things to think about:

You may find that updating to a new version of iOS, even if it is only a minor version upgrade will reset the settings. If that happens, just follow the process above again. Also, I would be wary about upgrading to the next major version such as iOS 7. There's no guarantee this workaround will still work.

Hopefully this process works for you, it did for me. However, if it didn't, you can always revert back to installing the Straight Talk profile from http://www.unlockit.co.nz/unlockit/ and still have data & MMS iPhone to iPhone.

Update 11/05/2013:
As of the iOS 7.0.3 update my Straight Talk SIM just works, no APN settings or config profiles needed. I still keep the APN config profile installed just in case. This is for the newer LTE SIMs, I don't know if this works for the older ones.

Straight Talk has AT&T compatible SIMs for sell now.

Thursday, June 7, 2012

Font Extensions


One issue in a system that I work on that was kind of side stepped around for awhile is the issue of custom fonts in reports, specifically reports built with the Jasper Reports framework. For a while we were just building all our reports in a standard font which was included in the build so this worked fine.

However, when we build custom reports for customers, they sometimes want text to be in specific fonts to match their branding. This is a completely reasonable requirement, but we just needed a sure fire way to deal with it.

In past times we would just take the font and install it on the customer's server however this was brittle since as soon as you would move the customer to another server, it would break their custom reports. Also this approach was problematic in rendering the PDFs correctly on any machine.

So the best way is to just include the fonts in the build. Fortunately Jasper Reports includes something called font extensions that make this very easy. Basically you just put a properties file in the default package called "jasperreports_extension.properties" and Jasper will automatically find the file. This file just sets a couple properties and tells Jasper where to find the font XML configuration file.

Example jasperreports_extension.properties:


net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.frsfamily=fonts/frsfontsfamily.xml

Next you create a "fonts" directory, place your True Type Format fonts in there, and create an XML file that configures the fonts.

Example XML font config file:

xml version="1.0" encoding="UTF-8"?>
<fontFamilies>

   <fontFamily name="NewsGothicBT-Roman">
       <normal>fonts/News Gothic.ttfnormal>
       <bold>fonts/News Gothic Bold.ttfbold>
       <pdfEmbedded>truepdfEmbedded>
   fontFamily>

   <fontFamily name="Planer">
       <normal>fonts/Planer_Reg.ttfnormal>
       <bold>fonts/planerdemibold.ttfbold>
       <pdfEmbedded>truepdfEmbedded>
   fontFamily>

fontFamilies>

Jasper reads the above XML and registers the fonts. Whenever the above font names are referenced in a report, the TTF fonts are used and embedded in the PDF itself (notice pdfEmbedded=true above) so that the PDF will be rendered correctly on any system that opens it.

So from now on whenever a custom font is needed, we just drop the TTF font files in the fonts directory, configure them in frsfontsfamily.xml and they are available everywhere.

Our next step might be to create a way to dynamically load fonts onto a live system allowing for more flexibility but for now we are happy with being able to include fonts in the build guaranteeing that they will be available and embedded in the PDFs.

Monday, February 27, 2012

Transparent Field Encryption/Decryption

Recently I have been working on expanding FRS integration with QuickBooks to include the Online Edition. While working on the transport pipe for QBOE (QuickBooks Online Edition), a realized requirement was the need to store a QBOE connection ticket. Something like this is usually a very simple task involving adding a new field to the appropriate domain object.

However in this case, one of the security rules that QBOE requires of an application is to store the connection ticket in an encrypted state. This is a common security requirement. Since the ticket acts as a key to QBOE, we don't want anybody with database access to get their hands on the actual ticket.

The first thought was to simply create a utility class to handle the encryption/decryption, possibly in a getter or setter. Another thought was to create a custom hibernate type that would handle the encryption/decryption by making use of an encryption utility class.

Upon doing some searching I came upon this: http://www.jasypt.org/  Basically Jasypt is just a java library that makes encryption extremely easy at the data layer. In fact all you need to do is get the appropriate jars on the classpath and do just a little configuration in the hibernate configuration, and voilĂ  encryption/decryption just works.

Here is an example of setting up the custom type in the hibernate configuration:

<typedef name="quickbooksEncryptedString" class="org.jasypt.hibernate3.type.EncryptedStringType">
      <param name="algorithm">PBEWithMD5AndDESparam>
      <param name="password">encyption-passwordparam>
      <param name="keyObtentionIterations">1000param>
typedef>

And the corresponding property mapping:

<property column="qb_online_connection_ticket" name="quickbooksOnlineConnectionTicket" type="quickbooksEncryptedString" length="1000"/>

Besides getting the Jasypt jars on the classpath, that is really all there is to it. With the above configuration the "quickbooksOnlineConnectionTicket" property is automatically encrypted when it is saved to the database and then automatically decrypted when it is retrieved. So from a coding perspective nothing changes. You can simply "set" the ticket and "get" the ticket whenever you need to.

Friday, May 13, 2011

School Update

I haven't blogged for a long time on the WGU school thing (in fact I haven't blogged much at all recently due to much busyness) but it has been coming right along. I am down to my final six classes and it appears I will be done this fall. It has been quite the ride. I have covered a ton of material in the last year and a half.

Two of the six classes remaining involves the final capstone project. My intention is to design & complete a small iPhone app to fulfill the capstone requirement. I am looking forward to getting into the world of mobile applications... it's been a long time coming.

Overall, WGU has been a good experience. I have gained a bunch of IT certifications one of which was the Sun Certified Java Programmer (SCJP). I had been wanting to achieve that one for a long time prior to even starting school. I have expanded my world quite a bit with general education studies. At times it was easy to fight their relevance, but I think they have a valid purpose... at least most of them anyway.

I am looking forward to completing the degree this fall. After that, I intend to utilize the degree as a foundation for my further pursuits in the field of software engineering. It's hard telling where the journey will lead.

Monday, November 1, 2010

JasperReports & the Format Factory

The more I work with JasperReports, the more I admire the project altogether. It seems like every time when I'm like "I wonder if JasperReports can handle that" it does, and it does it well.

Recently one of those issues had to do with localization, specifically date & number formatting. If you have worked with JasperReports you'll probably know that you can format dates & numbers with the pattern (e.g. "MM/dd/yyyy") attribute on a text field element. That is just fine when the pattern is known at design time. But what do you do when the patterns need to be localized or in other words dynamic?

No you can't use a String parameter as a pattern. The pattern attribute on a text field does not accept an expression, only a string literal. Another solution might be to have your application twiddle the JRXML and inject the proper patterns. But that would be hacky and could easily be error prone.

Enter the Format Factory. The Format Factory concept is simple but powerful. The FormatFactory is an interface in the net.sf.jasperreports.engine.util package that you implement to create your own date & number formats.

public class MyFormatFactory implements FormatFactory {

public DateFormat createDateFormat(String pattern, Locale locale, TimeZone timeZone) {
//create your date format here
return your-date-format ;
}

public NumberFormat createNumberFormat(String pattern, Locale locale) {
// create your number format here
return your-number-format ;
}

}

Essentially, your application takes over format creation instead of the JasperReports engine itself.

The best part of all this is your ability to create formats based on your own defined constants. You'll notice that the two methods in the class above have a "pattern" parameter. That is the pattern that you assign to the textfield.

You might say, hey I thought we weren't using explicit patterns anymore. You're right. But, we have to give a hint as to how the textfield needs to be formatted, so we would use format constants (e.g. SHORT_DATE, LONG_DATE, TIMESTAMP, etc). The constants are assigned to our text fields pattern attribute and get passed to our FormatFactory where we determine how to create a formatter based on those constants. Kinda cool, eh?

You might also notice the timezone & locale parameters in the methods above. Those are also parameters you can pass into the report itself which in turn get passed in to the format factory to assist you in creating the appropriate formats. For example, when you create a date format you'll need to know the time zone since that is an important part of actually formatting a date.

The Format Factory is a fantastic feature. This is especially true for large applications that already have formatting logic implemented in the application allowing you to reuse your existing format logic.


Friday, May 14, 2010

Thoughts on Flash from Jobs

So I just happened to log onto Apple's site today and noticed this article on Flash by Steve Jobs:

http://www.apple.com/hotnews/thoughts-on-flash/

So in summary here is why Flash isn't going to be on iPad, iPhone & iPods.

1) Flash is not an "open" standard
2) Apple mobile devices can already access tons of video content
3) Flash's reliability, security and performance on Macs is not good
4) Battery life
5) Flash and touch interface not a match
6) The dependability of a third party between Apple and developers

This sounds reasonable to me but I wonder if there still aren't other behind the scenes reasons. I'm sure Apple wants to collect all revenue through the App Store. What do you think?