Spree 1.0.0 debugging with Ruby 1.9.3p125

Here are the steps you need to get ruby-debug to work with Ruby 1.9.3p125 in the Spree sandbox.

Setup

  • rvm 1.10.3
  • ruby 1.9.3p125
  • Spree 1.0.x

Installing Gems

# download the source code for pre-release version of linecache, then install locally
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
gem install linecache19-0.5.13.gem

# download the source code for pre-release version of debug-base, then install locally
# using rvm installed source code (/Users/cmar/.rvm/rubies/ruby-1.9.3-p125/rubies/src)
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include="${MY_RUBY_HOME/rubies/src}"

Modify Spree Gemfile

group :development do
   gem 'linecache19', '0.5.13'
   gem 'ruby-debug-base19', '0.11.26'
   gem 'ruby-debug19', :require => 'ruby-debug'
end

Running Spree Sandbox

After you update the Spree gemfile, you can create a sandbox and run with the debugger

git clone https://github.com/spree/spree
cd spree
# edit Gemfiile (above)
bundle
bundle exec rake sandbox
cd sandbox
rails s --debugger
Posted in Rails, Spree | Leave a comment

SpreeConf 2012 NYC

Here are the slides from my talk at SpreeConf 2012 in New York City. I covered the new Preferences for Spree 1.0 and their usages in payments and promotions. I went pretty deep with a lot of interaction diagrams.

Posted in Rails, Spree | Leave a comment

My Steve Jobs Moment

On March 24, 2001, I was at the Apple Campus for a developer kitchen. Why is that date significant? It was the release of OS X 10.0 Cheetah. Being true Mac zealots, my friend and I drafted off an employee through the secure doors into the employee only cafeteria for lunch.

To our surprise, Steve Jobs came in and stood on top of a table next to me to casually address the employees. He was 5 feet from me as he held up a preview copy of the Wall Street Journal announcing the new operating system.

He read a review from Walt Mossberg gushing over the new OS. Steve thanked all the employees for their hard work and proclaimed that this was going to save the company. Just a few months earlier, rumors swirled that Sun was going to buy Apple. This was before the iPod was released later that year.

The most touching moment was when he stepped down from the table. Steve had a well deserved brash reputation. Most employees were scared to talk to him. But two older ladies, who obviously had been working at Apple for years, came up and thanked him for coming back and saving the company. He smiled and gave them a hug.

I’ll miss Steve Jobs. We don’t have long on this earth, we may never change the world as much as he has. But we can honor him by being the crazy ones. The ones who believe that they can change the world.

Posted in Apple | Tagged | Leave a comment

Pulling Back the Curtain on Core Data

I gave a talk on Core Data at iOS Dev Camp DC 2011. Rather then just another tutorial, I covered the concepts and explained the responsibilities of the big 3 – NSManagedObjectContext, NSPersistentStore and NSManagedObjectModel.

I like to understand what is happening behind the scenes. XCode throws a lot of code into your project if you include core data into your project. My talk and these slides try to help you understand the purpose of the code and the behaviors and relationships between the objects.

Posted in iOS | Leave a comment

10 Technical Screening Questions

In the past couple years, I’ve conducted a lot of phone interviews with the purpose of weeding out “Java Experts” with a technical screen of 10 questions. It’s unbelievable how many experienced programmers get these wrong and not attempt to use their analytical abilities to discuss a possible an answer.

While you can not completely judge a candidates ability through a simple phone screen, basic knowledge of the language and computer science sets a baseline.

I truly believe you could pass my screen by missing every single question. If you propose a solution and provide some insight, I’d be plenty impressed. “I don’t know the answer exactly, but I suspect it might have to do with memory, and this is why that would be important”.

I’ve used the questions on candidates with differing years of experience. The length of your resume and number of buzz words listed is usually inversely proportional to your ability to answer these questions. If your a tool guy, drag and drop coder or wizard dependent then I don’t want you on my team. If you understand the fundamentals of the language and taken time to understand basic computer concepts, then I believe you can learn the high level tools.

So, here are my questions. If you are doing research on me before we conduct an interview, good for you. I use the questions for Java programmers but half cover computer science concepts and are language agnostic.

1. What is the final keyword?

2. What is the contract between hashCode() and equals()?

3. How would you crash the JVM?

4. What is dependency injection?

5. What is the difference between Breadth First vs Depth First?

6. What happens after you type a URL in a browser?

7. Tell me a design pattern you’ve used and why it was useful.

8. What is the difference between a String vs StringBuffer?

9. What is the difference between an Inner and Outer JOIN?

10. Given a list of numbers how would you determine if 2 of them sum to 500?

Easy right? I’ve denied internal transfers, engineers with 10+ years of experience and have had to cut people off after a few questions.

Want to be judged more fairly on these questions? Don’t say your a Java expert if your not.

Posted in Java, Resumes and Hiring | Tagged | Leave a comment

3 Quick Resume Tips

There have been a lot of resumes coming across my desk for a Java Developer Position. Consistently, I see the same mistakes made by applicants. When I say many, I mean most and if you could avoid these simple mistakes you’ll stand out.

1. Send your resume as a PDF. There is no reason to send .doc files. I’m on a Mac. When I open your resume, I see bad formatting, missing fonts and in some cases I have to wait 5 minutes for OpenOffice to launch. Not a good way to start off. If you send me a PDF, the formatting is going to be correct and I can view it on my iPhone and iPad.

2. Keep your resume to 1 or 2 pages. At a big company, I’ll get a group of 20 resumes sent to me. If I open a document that covers your work life in a 6 page novel, I’m going to miss the most important aspects. If you have many pages, I’m going to skim the first and continue to the 2nd and be bored by the 3rd page.

If you send one page, I’ll read – not skim – the document. This gives you a chance to show me the most important reasons why I should consider you. I could care less about a job you had 10 years ago using outdated technologies.

If you want to provide more details on your experience, list it on LinkedIn. Don’t have a LinkedIn page? You better get one. It gives you a great place to expand on your experience and add less formal details about yourself. Add the URL of your LinkedIn page to the footer of your resume.

3. Don’t use internal project names. Do you really think anyone would understand “developed StratoPortal”? Use a simple description: “developed customer facing portal with JEE and Weblogic”. Only use project names if it is an external website that I can access.

Jobs are currently outpacing applicants but these tips will help you rise above the cruft. It is even more important when applying to a big company. HR will queue up a stack of resumes and send them to the hiring manager. The manager will forward them off to a team member to review. The team member is always busy with his regular work. Do you think you would be considered if you send a 6 page word document that assumes the reader would understand your internal project names?

Posted in Resumes and Hiring | Tagged | Leave a comment

Links in jQuery Accordion Headers

If you want to enable a link within the header of a jQuery Accordion, you have to capture the click to override the default behavior. I used the jQuery UI Accordion to build a left side menu. I wanted the top level header labels to act as a normal link. The expand and collapse overrides this by default. I couldn’t find an option to allow the links to have normal behavior, so I came up with the solution below.

The HTML looks like:

<div id="accordion">
   <h3><a href="/index.html">Home</a></h3>
   <ul>
      <li><a href="/custom.html">Custom</a>
   </ul>
   <h3><a href="/account">Account</a></h3>
   <ul>
      <li><a href="/account/avatar.html">Avatar</a>
   </ul>
</div>

To setup the accordion with jQuery


$(function() {

   //Turn the div into an accordion
   $("#accordion").accordion({
     header: 'h3'
   });

   //capture the click on the a tag
   $("#accordion h3 a").click(function() {
      window.location = $(this).attr('href');
      return false;
   });
            
});
 

Now, it behaves as an accordion. You can expand and collapse by clicking on the header. If you click on the label (link), it will take you to the href. We have overridden the default behavior. The click event is handled by the function and returns false so it doesn’t bubble up to the accordion code.

Posted in Javascript | Tagged | 22 Comments

Default iPad SplitView Project Relationships

I made this diagram to help me remember the relationships setup by XCode4 for an iPad SplitView Project.

The AppDelegate.h will have properties referencing all 3 controllers. There are subclasses for RootViewController and DetailViewController but it uses the base view controller for the split view. These reference are setup inside the MainWindow.xib file.

//YourAppDelegate.h
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;

The SplitViewController has a delegate which it notifies when it goes in and out of split view. The alternate view is when your iPad is in a vertical position and the view is not split. The details view will be full screen with a pop up for the root view. The DetailsViewController is setup as the delegate inside the MainWindow.xib file.

The DetailsViewController is setup to be the delegate for the SplitViewController to be notified when the orientation changes so it can make changes to its toolbar.

The RootViewController and DetailViewController are created for you. They know about each other through properties setup in the MainWindow.xib file. Both the Root and Detail ViewControllers know about their parent SplitViewController through a read only property in UIViewController.

The property “splitViewController” is part of all UIViewControllers but it is only non-null when one of your ancestors is a split view.

//from DetailViewController.h
@property (nonatomic, assign) IBOutlet RootViewController *rootViewController;

//from RootViewController.h
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;

The AppDelegate sets the window.rootViewController to be the splitViewController inside its implementation.

/- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // Add the split view controller's view to the window and display.
    self.window.rootViewController = self.splitViewController;
    [self.window makeKeyAndVisible];
    return YES;
}

In the end, the app delegate knows about everyone and all your views know about each other. The references are defined inside MainWindow.xib. XCode gives you a great start on an iPad project. I made this diagram to help me remember what is happening. It can be painful navigating around trying to figure out all the relationships. I hope this helps you.

Posted in iOS | Tagged , | Leave a comment

Searching Tweets with Processing

Here is a little source code to search Twitter using Processing. I tested it with Processing 1.5.

You will need the twitter4j-core jar which you can download from http://twitter4j.org. The download includes many jars but you will only need the core jar for this example.

Instructions

1. Open Processing and create a new sketch.
2. Drag and Drop the jar file onto the sketch. I used twitter4j-core-2.2.2.jar. This will copy the jar file into the sketch folder.
3. Copy and Paste the source code into your sketch and run.
4. You should get a list of recent tweets mentioning “apple” in the output window.

twitter4j.Twitter twitter;

void setup() {
 twitter = new TwitterFactory().getInstance();
 try {
        Query query = new Query("apple");

        QueryResult result = twitter.search(query);
        List<Tweet> tweets = result.getTweets();
        for (Tweet tweet : tweets) {
            println("@" + tweet.getFromUser() + " - " + tweet.getText());
        }
    } catch (TwitterException te) {
        te.printStackTrace();
        println("Failed to search tweets: " + te.getMessage());
    }
}

void draw() {

}
Posted in Java | Tagged , | 2 Comments

The Big Three in the Core Data Stack

If you create a new iOS project and include Core Data, the AppDelegate has three members in the “Core Data Stack”. NSManagedObjectModel, NSPersistentStoreCoordinator and NSManagedObjectContext work together to provide Object Relational Mapping (ORM) to the data store. These perform the same functions as Hibernate’s Session or Rails ActiveRecord.

These objects are lazy loaded. They initialize in a chain. When you ask for the managedObjectContext, it will lazy load the persistentStoreCoordinator. In turn, the persistentStoreCoordinator will lazy load the managedObjectModel. This diagram shows the 4 requests used to initialize the objects.

To access the persisted data, you request the managedObjectContext by calling the accessor on the AppDelegate.. This will return a perviously initialized object or lazy load it. The managedObjectContext does not access the data directly. It must use a persistentStoreCoordinator to retrieve or persist data to your storage. It makes a call to the persistentStoreCoordinator accessor.

- (NSManagedObjectContext *)managedObjectContext
{
    if (__managedObjectContext != nil)
    {
        return __managedObjectContext;
    }
    
    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil)
    {
        __managedObjectContext = [[NSManagedObjectContext alloc] init];
        [__managedObjectContext setPersistentStoreCoordinator:coordinator];
    }
    return __managedObjectContext;
}

The persistentStoreCoordinator accessor will return a previously initialized copy or construct a new one. For the persistentStoreCoordinator to work, it must know 3 things: the location of the storage (MyApp.sqlite), the type of storage (NSSQLiteStoreType) and a description of the data stored (managedObjectModel) . For the managedObjectModel, it calls the managedObjectModel accessor on the AppDelegate.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }
    
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyApp.sqlite"];
    
    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])

The managedObjectModel accessor is the last method in our lazy initialization chain. It gets initialized with the xcdatamodeld file. That file contains the schema of your data. It includes entity object descriptions and relationships. The ManagedObjectModel is used by the PersistentStoreCoordinator to understand the names of the tables, fields and relationships in the sqlite database.

- (NSManagedObjectModel *)managedObjectModel
{
    if (__managedObjectModel != nil)
    {
        return __managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyApp" withExtension:@"momd"];
    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
    return __managedObjectModel;
}

Thats it! The three objects required to use all the goodness of core data. The source code above is generated in XCode 4. You create a new iOS Window based project and check the box to use “core data”. This is just a quick introduction to the big 3. As you dive deeper, you’ll learn that you can create multiple persistentStoreCoordinators and aggregate them together in the ManagedObjectContext. You can also use different storage types. For most iOS applications, the generated template methods above are all you need.

Posted in iOS | Tagged , | Leave a comment