Archive for the ‘Code’ Category

26
Apr

LastPass – and Password Card

Posted by Scott

For quite a while I’ve used 1Password on my Mac to keep the 10,000 passwords I have to manage across all my accounts. This week I came across two tools that I’m very impressed with. The one problem with 1Password is that it doesn’t support google chrome (yet). And there’s no PC or Linux equivalent.

Well, Last Password (http://lastpass.com) is an amazing application that supports EVERY SINGLE browser I use. It stores all the information with one master password and early on I’ve been very impressed with it’s integration and utility.

The other nifty little tool I found via lifehacker.com. It’s a site called Password Card. (http://passwordcard.org). A Password card is quite clever. It’s basically a simple index card you carry in your wallet that allows you to create strong passwords and not have to remember them. How does that work?

Simple, you remember an index into the card, like square blue, or diamond green. Right now I’m playing with a triplet to recall like square white h9 or solidcircle purple v8. What does all that mean? You go to the solid circle symbol, then scan down to the purple row, and start reading off 8 characters vertically.

The reason for the 3rd option is that not all sites agree what makes a “strong” password. Some love the 8 random characters, symboles and digits, others need to see 9 before they thing a password is strong.

The genious of this system is that all you have to remember are simple things like a symbol name and a color, but the password itself is really difficult. You print the card, laminate it, and stick it in your wallet. Even if someone gets your wallet they won’t know what indexes to use to get your passwords. I’ve been using it for a few days, and so far I’ve been slowly upgrading all my passwords to “strong” passwords. It seems to work pretty well, especially with a tool like lastpass to help.

Update:  It’s harder than I thought it would be to remember things like color, symbol, direction count for each website.  And as good as last pass is, it can’t cover every situation.  Like desktop apps that need to login.  For example evernote, or iCal, or Mail.  Keeping track of the symbol / colors is trickier than I thought.

15
Mar

Adobe AIR

Posted by Scott

Adobe AIR Getting your Application Version

I couldn’t believe how hard this was to find. If you are programming with Javascript and HTML in Adobe AIR you might want to know what version your application is (the runtime has it’s own version). If you want to get it out of the XML application descriptor then you need to parse the XML file.

Personally I hate XML. Mostly because they made the brain dead decision to allow white space BETWEEN TAGS to count as a node. I don’t know who thought that was a good idea but it makes processing XML files REALLY hard and it encourages creating unreadable files that have no formatting.

But, here’s a simple function modified to allow you to pull the application version:

/**
 * getAppVersion
 * gets the application version from the application descriptor
 * Just for the record, I hate XML.
 * @returns ver {string}    The application version as a string
 */
function getAppVersion() {
    var xmlString = air.NativeApplication.nativeApplication.applicationDescriptor;
    var appXml = new DOMParser();
    var xmlobject = appXml.parseFromString(xmlString, "text/xml");
    var root = xmlobject.getElementsByTagName('application')[0];
    var appId = root.getElementsByTagName("id")[0].firstChild.data;
    var appVersion = root.getElementsByTagName("version")[0].firstChild.data;
    var appName = root.getElementsByTagName("filename")[0].firstChild.data;
    air.trace("appId: " + appId);
    air.trace("version: " + appVersion);
    air.trace("filename: " + appName);
    return appVersion;
}

Why I like AIR

I have become enamored with Adobe AIR (http://www.adobe.com/products/air/) because it lets me leverage my web programming for the desktop.  In college a classmate of mine once postulated his theory for the “Conservation of Stupidity”.  It goes like this, there is a finite amount of ignorance we all must carry around with us for our entire lives.  In order maintain that level every time we learn something new, we have to jettison something old.  The trouble is the brain doesn’t consult with us before it dumps the old to make room for the new.

For me, that theory manifests itself when I’m learning a new programming language.  I just love my children too much to run the risk of forgetting their names so I can learn a new programming language.  In reality, the real issue is that it takes time to get good at a programming language.  And it is really annoying to have to learn a new programming tool change, process, framework just so I can apply it in a new arena (e.g. the desktop).  Enter AIR.  With AIR (in theory) I don’t need to learn anything new.  At least as far as programming languages go.

I’ve started to have some fun with Wordpress plugins and my new favorite Javascript API JQuery.  I know Microsoft has some fantastic free tools, but I work on a Mac and all my websites are Linux based so no C-Sharp for me.

As for Apple, while I love my Mac, the overhead of learning CoaCoa doesn’t translate well into the web.  Of course there’s flash, but well… it’s Flash, and that too has it’s features.  But the real reason I like web programming is that modern browsers are so powerful, you can make some really sophisticated user interfaces and skin them with a few lines of Javascript, HTML and CSS.  And AIR lets me do that, but being Adobe they have a heavy preference for all things Flash and Flex.  Me, I like Javascript and PHP.  While they are supported there seems to be more examples of F/F than J/P.

So if I find something useful, I’m hoping the web crawling spider bots pick it up and share it.

– Scott

27
Feb

Joomla

Posted by Scott

Okay, while I love to write about baseball, occasionally I need to write about something technical. And I just can’t seem to find a good tutorial or document for Wordpress Developers trying to work with Joomla Templates. They just treat the problem so very differently.  I’m not going to waste time with the basics like CSS and HTML – and I am by no means an WP or Joomla expert. But this is what I learned.

With wordpress, you can use a combination of plugins and templates to do anything you want. Templates hold the layout, and word press php functions call various WordPress functions to load the templates up with Content.

On the plugin side, you have the notion of events you can “hook”. When WP gets so far in rendering a page, it will call one of your functions to do some additional work. A real common technique is to hook the “add_content” event with a custom function and scan the content for a key words embedded in the post or page and replace those keywords with your stuff.

Joomla behaves differently. With Joomla, templates define the layout of MODULES. Modules can appear anywhere on a page, Components can only appear in the content area of a page. Joomla uses custom tags like in the template to indicate where content will be displayed. Then, in the administrative portion of the tool, you can assign modules to the “names” or positions defined in your Template. Typically the JDOC tags are enclosed in DIV’s (overlays) that are formatted with CSS.

This gives Joomla a LOT of flexibility, but can also make it a real pain to track down where something is being rendered when you try to edit an existing template. The HTML / CSS you may need to edit most likely is NOT in the template, but in one of the Module files. But which one?
As an example, I wrote a simple Hello World template. Basically, it printed Hello Sno! whenver it was called. I had to:

  • Install it
  • Activate it.
  • Assign it to a position.

wpid-image-thumb1.w4jhN3HelpIt.jpg
The code for the plugin (1.5) was simple.
There were 6 files in the plugin and two of them were dummy stubs just to keep people from browsing the directory. It’s a nice trick.
Insert a dummy index.html in any directory you don’t want people to browse!
So the key files were:

  1. helper.php — contains helper logic.
  2. mod_sno.php — Implements module interface.
  3. mod_sno.xml — tells joomla how to load it and use it.
  4. tmpl/default.php — how to render the module data

Okay, this is a drag.  I didn’t have a code plugin for wordpress and the filtering software wiped out my original code.  I reinstalled joomla and lost my plugin.  I know I’ll need to do this again soon so I’ll try to repost the source.  But the big thing I want to capture is the idea that Wordpress operates off of hooks – in the Wordpress “loop”.  Joomla works differently, modules are activated and then need to be placed into an area of the template for display.

18
Feb

It’s amazing the free stuff on the internet

Posted by Scott

Every year I go into this crazy programming mode getting ready for little league.  There’s some thing I see that I think, “Hey I can automate that!”  Three years ago it was the Boundary Checker.  Just enter your address and it would use google maps to tell you if you fell inside the Tempe South Little League Boundary.  Last year it was my draft application.  A stand alone web page that sorted players for the draft.  I loaned it to one coach this year and of course it crashed (sigh), but it was a nifty bit of code.  Based on Tiddlywiki – a stand alone wiki app, the Draft Tool could even save itself to your hard drive.  But to update it for each years draft you needed to be a programmer.  Not very user friendly.
wpid-draft-tool-thumb.0LIpRLax1ehQ.jpg
This year was the biggest project I’ve undertaken yet.  I created a wordpress plugin to allow coaches to log into our website and reserve their fields.  A combination of jQuery based Javascript and wordpress php libraries, it’s a pretty slick application, if I do say so myself.  I just hope it works.  I’ve tested it, but there’s nothing like users to tell you what you did wrong.  If we get through this season without too much heart burn, I’ll turn it loose to the Wordpress community.  Usually though these things aren’t all that useful because they are so specific to the league you run.  As soon as you try to make it generic, that’s when it stops being a hobby and it turns into a real job.
But the main reason I wrote, this is I discovered (through one of my favorite websites lifehacker) an extremely cool tool called Jing.  (see jingproject.com).  This little screen capture tool runs on the PC or Mac and it not only lets you grab screens and annotate them – you can also grab Flash movies of you using a program and add audio as well.  This let me create a small video of how to actually use my new reservation tool.  And it only took like 2 minutes.  It’s hard to believe the “free” stuff that’s available these days.  It certainly helps guys like me give back to the communities we love so much.  I could never have done this stuff for Tempe if not for Wordpress, jQuery, Google, Jing and I’m sure many other projects and teams I’ve forgotten about.
I can’t wait for the season to start.  This is going to be fun.

23
Aug

Zend Framework

Posted by Scott

Okay, this little bit of  code is my attempt to give back to the Open Source community.

While there are some things I really love about the Zend_Framework.  Their documentation could be much better.  They really do a poor job of giving examples of how the options effect a given piece of code.  CakePHP does a much, much better job of showing how the options effect the outcome with examples.  One very bizarre thing I’ve noticed are people posting the exact same sample code over and over again as if it was their own.  None of it highlighting anything new.  What’s up with that?

Okay, enough whining.  If google finds this I hope it helps you.  It took me long enough to track it down and like most things, it was simple, but just not documented very well.

If you create a set of Radio Buttons with the Zend_Form_Element_Radio() class, you just might want to set a default button checked.  Here’s how you do it.

$myradio = new Zend_Form_Element_Radio(‘foo’);
$myradio->setLabel(‘Foo:’)
->addMultiOptions(array(‘v1′=>’Bar’,
‘v2′=>’Boo’,
‘v3′=>’baz’))
->setAttrib(‘class’,'coolcss’)
->setValue(‘v2′);

When you render this form in your view (maybe with a form->foo ?> call. All your options will be rendered and the radio button ‘Boo’ will be checked. That’s it. It’s that simple.

It’s not exactly obvious, but it’s simple. Why not obvious? Because check boxes in HTML are set with the attributed checked=”checked”. Setting a radio button value sets the value of the input – i.e. the value returned TO the server. It’s not necessarily obvious that setting the value of a radio controller makes it “checked”. Shame Zend didn’t stay consistent with HTML. But there it is and it works.

Happy Coding.
– Sno