Category Archives: Programming

RIP Dennis Ritchie

Dennis Ritchie invented the C Programming Language while working at Bell Labs.  His contributions to Computer Science, Unix and more cannot even be expressed in this little blog post.

I was first introduced to Ritchie’s work in college during my first programming class in the fall of 1998.  I’ll never forget the first program I compiled.  I was working with the Borland Turbo C Compiler and my professor had taught us how to write a simple “Hello World” program.

We saved our little programs onto a 3.5″ floppy disk and inserted it into the professor’s computer.  He then had us run a verification program that would test our “Hello World” app to make sure it worked correctly.

This was all very exciting for a geek like me.

Ritchie’s work on C paved the way for Object-Oriented programming with C++ (a clever way to say “The Next Iteration of C”) by Bjarne Stroustrup.  This work eventually spawned Java by James Gosling.

Java, originally written to power toasters and appliances, would  eventually become the core technology that powered the web for several years.  It’s funny how life works like that sometimes.

C eventually would be the backbone of Perl which ultimately spawned PHP.

Apple, Inc uses Objective-C (another object-oriented flavor of C) for the lion-share (pun intended) of their development.

Where would technology be without Mr. Ritchie’s contributions?


Announcing Remora

What is it?

Remora is a pixel-tracking framework written in JavaScript/PHP for tracking events and behavior.

Why “Remora”

A remora is a fish that attaches itself to something swimming by.  In the same way, Remora, attaches itself to your page, tracks an event and can run offline rules against that data.

You can read the wiki and checkout the latest version here.  It is FULLY FUNCTIONAL in its current state.

https://github.com/rmillsap/remora


Gushing over Web Frameworks

I’ve worked with a LOT of different web technologies out there.  In fact, I think I’ve probably touched just about everything in my 12 year career.  From the early days of web development using Classic ASP (barf!), moaning through the growing pains of web advancement as Java Servlets were en vogue, total misfires like .NET (Visual Basic and C#) and Coldfusion until finally settling into a PHP/Perl/Rails/Python world.

I’m sort of “known” for my diversity, in fact, a colleague of mine groaned to me about my web agnosticism the other day, “Robby, you just need to pick something and stick with it.”

Ha.

OK, if I had to choose right now.  Robby, you get to work with one web framework for the rest of your life, what would it be?

Now, there are great things in all the latter technologies I mentioned above. Settling on a single a framework, no doubt, means sacrifice.  But I still feel confident in my answer.

The ultimate web framework is….PHP SYMFONY

And here’s why:

  • Scaffolding, auto-generation is possibly on-par, if only mildly inferior to Rails (much of Symfony is based on Rails)
  • Great IDE support in NetBeans (including xdebug)
  • Great sandbox, dev and testing environment
  • Components!  Partials!  So many goodies to choose from
  • It’s 1000x simpler than Zend or other crazy frameworks
  • It’s incredibly organized
  • PHP is a widely known language and requires less ramp-up than Ruby
What do you think?

 


No thanks, Magento

I had this conversation with a colleague the other day.

Person: How do you get a request variable in Magento?

Robby: Magento has a shortcut…lemme look it up

Robby: $this->getRequest()->getContainer()->getManager()->init()->setFilter(“request”)->getParameterHandler()->getValue(“foo”);

I’m joking, but seriously, if my career for the next twenty-years was going to consist of working in Magento, I think I’d join an improvisational dance troupe tomorrow morning.  Magento is a juggernaut, behemoth of an environment with spotty, outdated documentation and tons of active bugs and compatibility issues.

It’s time for a super-light commerce system built in Rails.

Your thoughts?


Debugging PHP

With the XDEBUG module, Apache can be configured to open a socket for the remote debugging of a PHP application.  This illicits cheers from oldschool Java guys like me who live and die by remote debugging in Eclipse.  There’s just one problem…it doesn’t work very well.

PHP has emerged as the leader of the web, I think, because of it’s flexibility:  I can throw a page together in seconds, reference functions that were previously loaded God-knows-where, and it runs nicely on Linux.  However, since PHP is interpreted instead of being loaded into memory like Java, we face a problem with the debugger–it never can seem to trace beyond a single class at a time.  This means if I have two distinct classes that talk to each other, I can’t step into a method like I would in Java unless that referenced class has been interpreted by the debugger in this request.

Every time I work on a Java project I feel as though I’ve been given a giant chocolate cupcake.  Life is happy again.  I have a memory heap and all my classes are indexed and accounted for.  I can trace everything!  Sigh…


Creating a Custom Admin Module in Magento

Magento (magentocommerce.com) is a powerful e-commerce solution written in PHP that is offered as Commercial Open-Source.  It has quickly surpassed other PHP solutions (Zencart,etc) to become a quality product for the amateur and for a budding enterprise.

There are several challenges, though, when you try and develop in Magento.  Documentation is somewhat sparse and there are a multitude of assumptions in naming conventions that hold the fate of your application in its invisible hands.  So I’ve created this blog entry to demonstrate how to create a custom administration module–a screen that can be used by your site administrators with custom functionality.

I’m going to create an app called “Foo”

Step 1 – Register your new module

First, locate the following folder inside your Magento installation:

app/etc/modules

This is where Magento learns about Modules that have been installed.  Create a file for your module named RobbyMillsap_Foo.xml.  The contents of my file look like this:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<RobbyMillsap_Foo>
<active>true</active>
<codePool>local</codePool>
</RobbyMillsap_Foo>
</modules>
</config>

Here’s the thing…

Magento has a few naming conventions you’re going to have to become intimately familiar with.  Where you store your code and design files will be dependent on how you named this module.  In our example above, the namespace we are using is called RobbyMillsap and the module is called Foo.

Step 2 – Create an Admin controller

I’m assuming you are familiar with how an Model-View-Controller (MVC) architecture works.  Here is the concept in one line: the Model is the representation of your data, the View is responsible for rendering the screen and the Controller is responsible for handling user action and communicating with the services (DB, web services, etc).

Our controller is going to be located in this folder:

app/code/local/RobbyMillsap/AdminTab/controllers/FooController.php

This is a perfect example of what I was saying about Magento’s tricky naming assumptions.  How would else would you know that this is the exact place for your admin controller to be created unless I told you?  Well, they have some tutorials, granted.  But it would make more sense, in my opinion, if they let you register this WITH the module definition…but back to our project.  Let’s create the controller class.  Here is mine:

class RobbyMillsap_AdminTab_FooController extends Mage_Adminhtml_Controller_Action{
  public function indexAction(){
  }
}

Ok, so again with the naming conventions.  You have to use <namespace>_AdminTab_<module> as the name of your class again here or else it will not be picked up by Magento’s interpreter.

Step 3 – Create a simple view

A file with a .phtml extensions can serve both plain HTML and PHP code.  This is the convention used for Magento template files.  For our view, let’s create a template file in the following location

app/design/adminhtml/default/default/template/foo/index.html

Again, so many assumptions made here by Magento.  But oh well; it doesn’t matter what you put in this file, perhaps just the phrase “Hello world” for now.  It will be rendered inside Magento  template when are done.

Step 4 – Load your view in the controller

Now that the controller has been created you can create a simple template and have it rendered on the screen.  Here’s the code to put inside your indexAction() function:

$block = $this->getLayout()->createBlock('Mage_Core_Block_Template','foo', array('template' => 'foo/index.phtml') );
$this->getLayout()->getBlock('content')->append($block);

$this->renderLayout();

This code loads a view object and saves it as block.  We can assign objects to be passed to the view later (like a collection of database rows).

That’s all for now

Ok folks, that’s all for now.  As you can see, Magento has A LOT of moving pieces, a lot of configuration files, and a lot of unclear naming assumptions.  It’s still a powerful e-commerce tool, but not for the faint of heart.


Installing DBD::mysql on OSX (Snow Leopard)

I’m a Perl enthusiast.  For quick scripting nothing is easier and faster for me than to whip up a Perl script to process some data, scan some web pages, or work with a database.

However, I guess it had been a while since I last tried to insert some records into MySQL using my local Perl installation because my script was met with all sorts of problems.  First I got this dreaded Perl error while using DBD::mysql (through the super cinchy DBI interface):

Symbol not found: _mysql_init

Huh?  Had it really been so long since I used Perl on my Macbook Pro?  But then I did the math, I was a little late upgrading to Snow Leopard.  There was so much talk of things not working that I was hesitant to take the plunge.  I knew right away this had to be the issue.

My first instinct was that my 64-bit Perl installation was out of sync with my 32-bit MySQL 5.0 installation.  No worries.  I went to the MySQL website and downloaded the latest 64-bit Mac OSX edition.  Installed it by running the following command:

%> scripts/scripts/mysql_install_db --user=mysql

Nothing could be easier. I then updated both DBI and DBD::mysql

sudo perl -MCPAN -e 'install DBI'
and
sudo perl -MCPAN -e 'install "DBD::mysql"'

So far so good. Then I updated my path (~/.bash_profile) to make sure I was pointing to the symbolic link (/usr/local/mysql). All good. Then I ran my script and got the following error:


Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
Referenced from: /Library/Perl/5.10.xxx/xxx/mysql.bundle

What the?

Here is the solution:

You must change the path of to the reference library in mysql.bundle.  To do this, use a tool called install_name_tool. Here is the solution:

<code>%> install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Perl/5.10/xxxx.xxx/mysql.bundle</code>

Why it works

This updates the mysql.bundle file with the new location of “libmysqlclient.18.dylib”.  Hopefully this blog post will help you.  I spent hours (about a half day) working out the solution to this one.  It was very frustrating.  If this blog post helped you, hit me up on Twitter (/robbymillsap).

Cheers!


Follow

Get every new post delivered to your Inbox.