Monday, November 19, 2012

Irritating things I seem to forget how to do (Android Version)

So one of the most basic things you can do in Android is start a new intent it is super simple (this is not what I forget - I'll get to that in a minute):


Intent i = new Intent(this, AwesomeIntent.class);
startActivity(i);

See? very simple.  Now if you want to pass data back from an activity that you just created you have to start the Inent slightly different:

Intent i = new Intent(this, AwesomeIntent.class);
startActivityForResult(i, REQUEST_CODE_FOR_MY_INTENT);

Even that was pretty easy wasn't it?  

It doesn't take long though before you want to pass information into an intent, and of course you have to return data from the intent (and process it as well).  Here is how you do that:

Intent i = new Intent(this, AwesomeIntent.class);
i.putExtra(Key, Value);

The documentation says that should work however this seems to work better:

Intent i = new Intent(this, AwesomeIntent.class);
Bundle b = new Bundle();
b.putString("KEY", "VALUE");
i.putExtras(b);

startActivity(i);


You can get that extra data you passed in (often in the onCreate method) like this:

Bundle b = getIntent().getExtras();
magicKey = b.getString(key);

Now the whole reason I created the post when you are in an Activity that was created by a "startActivityForResult".  Inside the method where your activity finishes up just do this:

Intent intent = this.getIntent();
intent.putExtra("SOMETHING", "EXTRAS");
this.setResult(RESULT_OK, intent);
finish();

And lastly the class that started it all needs to implement this method:

protected void onActivityResult(int requestCode, int resultCode, Intent intentData) 
{
   if (requestCode == REQUEST_CODE_FOR_MY_INTENT)
   {
     //do some cool stuff here
   }
}


Pretty simple basic stuff - but for whatever reason I always seem to have to look it up.

Happy Coding!

-Aaron

Friday, November 16, 2012

Removing SVN cruft

I'm slowly converting some of my old SVN projects to bitbucket (using git).  Bit Bucket is really the coolest thing when it comes to source code control.  If you can get over the GIT learning curve there are so many features that bit bucket gives you free (Issue Tracking, WIKI, source code browsing - just to name a few).  I don't know how or why but I love those guys...

 One of the odd / irritating svn does is create that .svn folder in all of your directories if you check a project out.  I suppose you could use the .gitignore for these but I stumbled upon a much better way to do this.  At the root of your project execute this command:
find . -type d -name .svn -exec rm -rf {} \;

Now if you are running windows... well... stop that go get linux or a mac!

By the way I found this little goody over at stackoverflow.


-Aaron

Tuesday, February 21, 2012

SSH Public Key Authentication

Here is a link to a super simple explanation of how to set this up: http://www.petefreitag.com/item/532.cfm

In case it goes away here is the content copied and pasted - this is not my work it is from Pete Freitag :



Setting up public key authentication over SSH

Every time I want to setup public key authentication over SSH, I have to look it up, and I've never found a simple guide, so here's mine.
Generate key on local machine

ssh-keygen -t rsa
It will ask you for a password but you can leave it blank.
Note you could also pick -t dsa if you prefer.
Ensure that the remote server has a .ssh directory

Make sure the server your connecting to has a .ssh directory in your home directory. If it doesn't exist you can run the ssh-keygen command above, and it will create one with the correct permissions.
Copy your local public key to the remote server

If your remote server doesn't have a file called ~/.ssh/authorized_keys2 then we can create it. If that file already exists, you need to append to it instead of overwriting it, which the command below would do:
scp ~/.ssh/id_rsa.pub remote.server.com:.ssh/authorized_keys2
Now ssh to the remote server

Now you can ssh to the remote server without entering your password.
Security

Now keep in mind that all someone needs to login to the remote server, is the file on your local machine~/.ssh/id_rsa, so make sure it is secure.

Tuesday, January 17, 2012

Git and Dropbox


I've been using git along with Dropbox for a little while and think it is a pretty awesome way to setup a code repository.

This is usually how I end up doing.  Create a new project happily coding along and then it occurs to me I should probably start versioning this little gem.  Which is very easy to do with git simply "git init" and you're done.

So that is all find and good but then I start to get nervous... what if my hard drive crashes... how can I keep this repository save and sound?

Again git has a very easy to use command that if you put it in your dropbox folder you have a code repository that easy to manage and access!

Here is the command for git:

git clone --bare  /gitrepo/gitproject.git

I get tired of having to type git push /gitrepo/gitproject.git  whenever I want to push code out into the safe region of Dropbox so I usually end up writing a simple little script that looks like this:


#!/bin/sh
git push /gitrepo/gitproject.git

obviously pull is just as easy....

Enjoy!

-A

Monday, January 09, 2012

Making Xcode less difficult

Writing Objective-C code in Xcode can be very difficult.  Especially if you're coming from a different language like Java; not only do you have to learn the new syntax of Objective-C you also have to learn the new development environment and remember what it's like to code in a non-managed environment (i.e. not having the JVM hold your hand when things go awry).

I started working with Xcode and Objective-C about 4 years ago and after many frustrating days (and nights) I found out some great information in an iTunes University video called Advanced IOS Development put out by Madison College.  

It's a very long video, about 3 hours and I'm only about half way through it but I have found some great information in it already that I wanted to share.

Problem: you're running your app on the emulator and it seeming crashes randomly.  You don't get any information about why it crashed the app just quits.

Solution: in Xcode you can set global break points that can stop your app when it crashes, the debugger puts you right on the line that causes the problem!  
Here is how you do it:
  • In Xcode open the Breakpoint Navigator
  • In the bottom left corner of the view is a plus sign click on it to add a new breakpoint.  You will be asked to add an "Exception Breakpoint" or a "Symbolic Breakpoint" choose symbolic.
  • After selecting "Symbolic Breakpoint" a popover window will open fill it in as follows:
    • Symbol: objc_exception_throw
    • Module: libobjc.A.dylib

  • Follow those same steps again to add a new symbolic breakpoint as follows:
    • Symbol: -[NSException raise]
    • Module: CoreFoundation


  • To make the breakpoints global right click (command click - double finger tab - whatever) the break points to move them to the User context


And there you have next time you make a mistake Xcode will stop your app where it breaks - assuming it breaks in your code.  If you tell the frameworks to do something that doesn't work (such as loading a ViewController that won't load for some reason) you're back to the drawing board.

Hope that helps!

-Aaron




Monday, May 23, 2011

Universal iOs Applications

I've spent this afternoon looking at building a universal application for an iPhone application.

First of all I would like to go on the record that I think in general this is a bad software engineering practice - at least in theory .

Having your code check to see if what kind of device it is running and then execute a different set of functions based on the answer feels very hackish to me - at least from a conceptual level.

However, from a user perspective it is sweet software magic that is incredibly awesome - especially when dealing with "markets" similar to what Apple and Google have. For example you only can buy an application once and it can be run on the iPhone or iPad. It's like getting two great applications for the price of one.

I finally decided to buckle down and work through this and as you may expect it is much easier than I expected it to be. I started by:

  • creating a brand new iPhone application
  • then clicked on Application in the top left pane
  • and selected "Universal" in the Deployment Target drop down

Here is a screen shot:

Once xCode runs through it's magic you get a new folder called iPad that contains a new "Window" called "MainWindow-iPad.xib".

Now if you run the application you will be able to run in full iPad mode but the layout will be used by both the iPhone and iPad emulator and that is not what I intended to happen... To get this to change first of all you need another ViewController for the iPad to run so go ahead and create one of those using:
File -> New -> New File... c'mon you know the rest...

So... how do we get our new controller instantiated? Probably have to link into the app delegate, check the InterfaceIdiom to find out what kind of device we're running right?

Nope - not at all. You can handle all of this magic in the Interface Designer. No code change is actually needed! Here is how to do it:
Click on the new "MainWindow-iPad.xib" that xCode created for us
Select the View object in the hierarchy
and change the class under the "Identity Inspector"




Now if you run it you will still get the old layout (and probably crash). What you have to do is tell interface builder to load a different nib file:


Now you can run either emulator and you will get the correct view controller magically instantiated and the correct nib will be laoded.

That doesn't feel very hackish at all now does it?

-A





Monday, February 21, 2011

Google Makes me feel like a Genius!

It's true, just about every time I work on my Android applications - I get that weird maniacal evil genius laugh... You know what I'm talking about - admit it.

If you use CBI you should know that there is a backup feature included that exports your collection as a CSV file [CSV is kind of like an open source spread sheet format].

I've been wanting to send the backup file to Google Docs for awhile now but haven't gotten around to it. Last week I downloaded the source to Google's Client API source code and have been tinkering around with it. And have it backing up my spreadsheet now.

I still have to get the restoration working but I think that will be even easier than the backup.... Maybe I'll post some code for posterity in a bit but right now I have to get back to my mad genius cackling....

Here is a link to my spreadsheet so you can check out the format: My Collection

Tell me what other Comic Book Application will let you do that!

-A


Tuesday, February 15, 2011

Objective C can really stink

Let me preface this by saying I am not a very good Objective C programmer. I come from a strong background in Java and enjoy Objective C becuase it's a new technology (for me) and it solves problems different from Java... well at least the API backed by Cocoa Touch solves them in a different way.

Coming from Java I will tell you this - Exception handling in Objective C is horrible! I've spent all morning dinking around trying to get a table view to display. I've been doing Objective C for 2 years now (not exclusively - but I'm not a complete newbie) so to be having problems with something this basic is pretty frustrating.

The problem really starts with me becoming more familiar with the language. As comfort levels increase I begin exploring how to solve things in slightly different ways... This is what happened today. I'm using a NavigationController to pop on a series of views (successfully until this morning).

I have this little block of boiler plate I toss around to pop a view on the NavController that looks like this:

NewViewController *vc = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
NSArray *items = [NSArray arrayWithObjects:@"Item 1", @"Item 2", @"Item 3", nil];
[vc setItems:items];
[vc setTitle:@"Items"];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
[items release];

Here is the logic behind the code -

  1. Create a new view controller
  2. Create a new list to slam into the table view for the view controller and pop it in
  3. Set the items array into the view controller
  4. push the view controller into the navigation controller
  5. releace the memory for the view controller as it is now owned by the navigation controller
  6. and release the array since it is now owned by the view controller

Even now just looking at the code I just figured out what the problem is - I'm not actually creating a new instance of the items array. So by releasing it - my new view controller crashes because it's retain call got mistakenly released by someone else.

Simple problem - no big deal at all. My frustration really is that the app just crashes without any type of error at all... just a *blip* application died... Occasionally it would spit out this error:

Program received signal: “EXC_BAD_ACCESS”.

Which is not helpful at all - basically that means we accessed memory that we shouldn't have.

I agree whole heartedly that this is not a problem with Objective C - it all comes from my ignorance and lack of experience - however, it is still very frustrating.

-A

Thursday, February 10, 2011

Anxious, Silly things

I have a 1st grader at home. She goes through boughts of anxiety here and there - nothing major but enough to be mildly concerning... At night she often makes sure the windows and doors are locked. Of course there is the general fear of the dark - and as of late does not want to go to school - because she misses her family...

Nothing major or probably outside of normal behavior - but I find myself going through all kinds of things in the morning to get her mind off of the looming drive to school - that often ends in tears...

Today she was rather sad so I drew a picture of her face and hair, in an attempt to get her to smile (no luck) but she did end up drawing in the body and crown(?!) to go with it...


The morning drop off went decent this morning - I'm not sure the picture helped but it was silly drawing on a anxious morning...

-A

Sunday, February 06, 2011

Best Wallpaper

So, I have this little app called Comic Book Inventory or CBI for short. CBI (as the name might imply) lets you inventory your comic book collection, once you get your collection added you can look up issues by Title, Author, Penciler, Inker, Colorist etc.

You can also do some pretty fancy things like find missing issues, get the weekly release list of comics, create a "pull list" (and lots more). My favorite feature of CBI is that you can set your android wallpaper to a comic book cover; actually you can select up to 4 covers and CBI will mash them together.

So here is one of my favorite desktops I've created lately: It's the cover of "Lady Mechanika" #0




Here is another desktop showing a multi-cover desktop.


If you haven't read Lady Mechanika you should check it out. It is creator owned comic published by Aspen Comics and owned by Joe Benitez.

There are only 2 issues out (#0 and #1) but so far the story and art are fantastic!

-Aaron

Tuesday, July 13, 2010

How to measure iPhone vs. Android

There is a lot of noise out there about which platform is better: iPhone or Android?

I am in an unusual position as I have an iPhone 3Gs and several Android devices (G1, ION, Droid, EVO, Nexus). In the early days of Android there was no comparison - Apple ruled the mobile space. Howver with Sprint's EVO being released I see a lot of happy Android users walking around trying to tell me how great Android is.

Don't get me wrong - I know Android is great! There are a lot of ways to measure how great a platform is. This is the best way to measure how great your platform is: The next time someone from either camp starts to tell you how great their phone is ask them a simple question "What is your favorite application that you spent money on?"

It's a simple and fair question don't you think?

Almost everyone I know that has Android has the same answer "Well I haven't actually bought an application before." To contrast almost everyone I know that has an iPhone has bought some kind of app whether it's one to decode the laundry symbols on your clothing (yes there is an app for that) or a really fun game - they usually have a favorite.

A lot of reason Android users tell me they don't buy apps is because they say that they haven't found anything worth buying. The Android market place is kind of a catch 22 since no one is buying apps no one is building any apps worth buying.

As an Android developer and user here is my list of favorite for pay applications:

  • $2.99 Comic Book Inventory (CBI) <- this is my application so of course I love it
  • $.99 Picture This (Free version available) - a fun little picture game
  • $4.99 BeyondPod Podcast (Free Demo available) - a great podcast listening app
  • $.99 Power Manager (Free Demo available) - an almost obsolete power manager

There are several really good free applications available as well - NPR News, Shazam, Photoshop Mobile, Droid Comic Viewer, The Weather Channel, Pandora - are just a few of great applications for Android.

For the record here is a list of my paid iPhone applications

  • $2.99 - mSecure
  • $.99 Mars Explore
  • $0.00 Marvel Comics - in app purchase
  • $3.99 ComicZeal
  • $1.99 Crush the Castle
  • $1.99 CW-Gunner
  • $3.99 Field Runners
  • $1.99 Finger Physics
  • $0.00 Zombie Farm - in app purchase
  • $.99 Stick Wars

These are estimates the apps may have cost slightly more or less than what I listed, and with the exception of maybe 1 or 2 apps all have been more than worth the little bit I payed.

So the bottom line is this - all of you Android users out there who think your phone is awesome. Go out and buy an app! Support your Android developers or they will turn into Apple developers - right now there is more money to be made on the Apple side until that changes Android will never be able to catch up (Regardless of how you hold your phone).

-Aaron


Friday, December 04, 2009

A What?!

Objective-C has a concept called "Categories" - I just learned about these things a couple of days ago listening to a podcast and wasn't quite sure when or where it would be appropriate to use something like this.

At a high level a "Category" is a way to change (add or modify) the behavior of an existing object. For example - if you needed to print a string backwards in your application; one option would be to subclass the string object. Another option would be to create a category to add a method to perform this operation.

The benefit of a category is that the new method is available to all of the Objects of that type. Another cool benefit is that you don't have to change any code at all to take advantage of the behavior change. All types of the categorized object get the new behavior.

The downside to this? I'm not sure it seems pretty powerful but as they say "with great power comes a great responsibility"

Here is the problem and the solution I solved by using categories:

(IMHO) The Apple API has a bug in the MapKit. If you add a MKPinAnnotationView the CallOut has a (seemingly) random z-index defined which causes the following to happen:

You can see the red pins are on top of the call out window. Very irritating - I was about to give up when I googled one last time and found this posting. Here is how I fixed it by using a category:

Here is the header:

#import <MapKit/MapKit.h>


@interface MKPinAnnotationView (ZIndexFix)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
@end

and here is the Implementation:

#import "AEBMapViewCategory.h"


@implementation MKPinAnnotationView (ZIndexFix)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.superview bringSubviewToFront:self];
[super touchesBegan:touches withEvent:event];
}
@end

So basically I overrode the default behavior of the [touchesBegan: withEvent:] method.

That is all the code I changed to make the picture above look like this:

Pretty sweet huh?

If anyone else solved this problem differently I'd love to hear about it.

-Aaron


Tuesday, December 01, 2009

Testing and xCode

Java developers are spoiled.

I was a late comer to the testing band wagon. I'm not a test nazi by any stretch but there is a certain amount of confidence that testing gives you.

I miss that when I'm coding in Objective-C.

I was so happy today when I found out today that xCode has built in support for unit testing. But it sucks horribly. Granted much of my problem may be that I have not fully grokked the underpinnings of this environment. But I have spent all day and most of the night trying to figure it out and this is the extent of what I have figured out.

Unit tests that exercise simple parts of the application (non-framework/Cocoa stuff) can be tested after a build is performed. However:

  • Debugging is not an option
  • Capturing output from sysout is not an option
  • Decent reports don't seem to be available
  • Decent error reporting doesn't seem to be available

It's hard to believe that unit testing is so far behind on this platform. Java developers don't know how good they have it.


Monday, November 09, 2009

ADC2 Results

<sigh> so the results for the ADC2 are out. Unfortunately, DungeonTrainer was not one of the winners. I was a little bummed - they haven't released the numbers in each category but I'm guessing that there was a lot of competition in the casual game arena.

One of my good friends submitted an app and made the first round of cuts (his app was in the education category). So, congratulations to him and "Mobi Professor".

-Aaron


Sunday, November 01, 2009

New Mac Blogging Software

I'm trying out some new blogging software for my mac called blogo. I've been using a windows vm with LiveWriter installed - which is a spectacular piece of software for my blog postings up until now. I tried blog about a year ago and got very frustrated with it and happily uninstalled it - I hear it's a lot better now - we'll see.


My last post I was lamenting about the use of of timestamps in the iPhone SDK specifically CoreLocation, and as usual it takes me proving my ignorance before I can figure something out. So, here is what was going on...

If you remember back in your first C programming class - you learned about the function called printf. I specifically remember my instructor explaining the function and that the %d symbol meant to format an integer value and %f meant to format a float value. This information was lost to the deep recesses of my memories. This is important as I was using the %d to for logging -basically to output the age of the calculation - trying to understand what was going on and getting crazy - seemingly random values for the age.

Anyway this is the correct way to get the age from a CLLocation object:

float age = fabs([[newLocation timestamp] timeIntervalSinceNow]);

Armed with the value of age you can proceed with confidence that you are calculating the age of your location correctly.

-Aaron


Monday, October 12, 2009

Who wrote this crap?

It never ceases to amaze me how code that is written 2 or 3 months ago almost always ends up being crap.  I am exaggerating of course, but a lot of time the code I write when I revisit later is just crazy. 

I'm sure part of that is because the code I write on my own is often done at 2 or 3 in the morning.  It is interesting though, I can clearly see where the coding sessions were broken up instead of flowing smoothly in one session.


So, CoreLocation is one of the frameworks in the iPhone SDK.  I used it quite a bit with the LifeAware iPhone app and am using it again for my current project.  In both project I ran into the cached location issue.  Now if you read the SDK and even look at the sample code for this framwork you will see things like this:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    [locationMeasurements addObject:newLocation];
    // test the age of the location measurement to determine i
f the measurement is cached
    // in most cases you will not want to rely on cached measurements
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0) return;

This code does not seem to work.  I tried so many variations and it just doesn't work.  I'm sure it worked for Apple and maybe it works for you.  If so that's great, good for you.  But for me it didn't work so here is how I did it.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"Found a new location %@",  newLocation);
    NSDate *now = [[NSDate alloc] init];
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setDateFormat:@"HH:mm EEEE MMMM d"];
    NSString *nowTimeString = [outputFormatter stringFromDate:now];
    NSString *locationTimeString = [outputFormatter stringFromDate:newLocation.timestamp];
    NSLog(@"The age of the location is: %@", nowTimeString);
    NSLog(@"The age of the location is: %@", locationTimeString);
    if ([nowTimeString compare:locationTimeString] == NSOrderedSame){

Basically I take the timestamp from the location object and create a new one for "now".  Convert the two to string representations and compare the strings for equality.  This gives me a location that is less than a minute old. It seems just a little bit hackish but I think it's a pretty decent solution to a flaw in the API, seriously why wouldn't you say something like:

[locationManager startUpdatingLocation useCached:NO];

Happy coding!

-Aaron

Sunday, October 11, 2009

Been a while...

So it's been a while since I last posted a blog entry.  A whole lot of things have been going on.  First of all I finished my entry to the Android Developer Challenge 2 it is a game called Dungeon Trainer

Dungeon Trainer is a simple RPG game that lets you create and train characters by battling other characters.  Once your character is created you can upload them to share with players around the world.  You level up, buy weapons and armor and then battle (train).  It is a simple game for a couple of reasons

  1. The time constraint of the challenge was very tight I started designing on June 16th and had to develop it all from concept to final product by Austst 28th.  Ruffly 2.5 months.
  2. Mobile games should be simple.  Having a game like Baler's Gate or Diablo on your phone would be cool but it would be hard to pick up and put down quickly.  Or casually play in a meeting that you were bored at.
  3. It was the first game I ever wrote so I wanted to start simple and build on it.

As of October 6th the first round of judging is complete.  I haven't heard any results yet, I'll let you know when the winners are announced though.

I'm also working on another iPhone app.  This one is pretty cool and much simpler than the LifeAware iPhone app.  I can't say much about it except that I am still doing iPhone stuff.

It is kind of a cool contrast between the 2 platforms though(android an iPhone).  My day job is Java so the Android platform was a super easy transition.  The iPhone was not easy in any way, even still I kind of enjoy developing for it.  It kind of reminds me of VB in a way although you have all the power of C to hang yourself...

I'll put some little code snippets of the iPhone out. I"m sure if I have struggled with these parts other people have as well. 

Until then ciao'.

-Aaron

Tuesday, June 02, 2009

Test Driven Development

So I posted an entry a little while ago... ok perhaps it was more of a rant about unit tests.

I don't disagree with the post, however I have learned a little bit more about testing.  Specifically what testing is and what it is not.  I recently was able to attend a JUnit class that was given by J.B. Rainsberger.  He also authored the JUnit Recipes book it really is a good book and worth the price.

Some of the things I have taken away from the class is that unit testing pretty much sucks.  However, behavior driven design is pretty cool.  Unit testing (IMO) is going through code (usually code that exists prior to the test being written) and writing a test to figure out how the code works.  This is a very effective way to trouble shoot existing code but is a very large effort, both in time and mental CPU cycles.

Behavior Driven Design is a technique that lets developers take an abstract concept (or a problem) and get it into code.  Testing frameworks like JUnit and JMock are helpful tools to do this with but don't get confused you aren't testing anything.  You can't test anything because the code doesn't exist yet - you are modeling the behavior you want your code to exhibit.  This is a powerful technique and I have done it many times on many projects but I never had a name for it.

I recently implemented a restful webservice using a new java framework called cxf.  I was itching to try out the techniques of Behavior Driven Design that J.B. showed us .  Unfortunately, I didn't have a good understanding of cxf so I was unable to use BDD effectively for quite a while.  I fell into the difficult place that java developers fall into of iterating over configuration changes and server restarts.  This is an important point not all of our efforts as developers can be boiled down into writing test cases or even BDD.  In fact, I did try to do some BDD work prior to getting the frameworks working but ended up throwing all the code away. The cxf framework changed how I thought the code would eventually work.

If anyone is interested I'll post some code examples of how the code ended up looking.  But the point I am trying to make is that doing Behavior Driven Design, although leaves a whole lot of unit tests lying around as artifacts of the process that is not the goal.  Unit testing on the other hand is an extreme effort that we do as either a last resort or as an ego trip to get our testing coverage up to 100%.

Don't confuse behavior modeling with unit testing - they are worlds apart.

 

-Aaron

Monday, June 01, 2009

It's been a little while

So with all of the fancy iPhone, AppEngine, GWT, Android development I've been involved with I was on the job the other day and someone asked me how to do something in Javascript.  Her problem was a tricky one but it basically built upon a very simple foundation.  When a user selected something she needed some text and a style to change.  I knew immediately how to do it but the syntax escaped me for a bit so I thought I'd stick it out here for the next time I needed it.

The problem is pretty simple click a button change some text and the color of the text.  So here is my very simple solution.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
   <head>
   <title> Switch </title>
      <script type="text/javascript">
         function change()
         {
            var styleClass = 'required';
            var textValue = 'Else'
            if (document.getElementById('sigDate').className == 'required')
            {     
               styleClass='standard';
               textValue='Something';
            }
            document.getElementById('sigDate').innerHTML=textValue;
            document.getElementById('sigDate').className=styleClass;
         }
      </script>
      <style type="text/css">
         .required{
            color: RED;
         }
         .standard{
            color: BLUE;
         }
      </style>
   </head>
   <body>
      <input type="button" value="Switch" onclick="change()" />
      <div id="sigDate" class="standard">
         Something
      </div>
   </body>
</html>

Like I said a very simple solution to build a very complex solution upon.

 

-Aaron

Wednesday, March 18, 2009

St. Patricks Day run

I guess there were 3,100 people at the run.  It was 4 miles long.  My time was a stready 41.5 minutes - one of the guys I went with ran it in 26 minutes though!!!