Updating Google Analytics Tracking on your Magento e-shop

Google Analytics has recently changed the tracking scripts from ga.js to a more optimised version analytics.js that can be used if you set your analytics account to “Universal tracking”
Yet, Magento’s Google Analytics module is still using the old ga.js.
Of course, there are a couple of new plugins that claim to fix this, but why use a plugin to slow down your shop instead of updating 2 files and not affecting in any way the performance of your website?

Wait! Did I say updating? That should already ring a bell for a Magento developer.
The internet is full of blog articles and answers on StackOverflow advising to actually edit the existing GoogleAnalytics Module and Template files.
One could never be more wrong than that. It’s one of the first things a developer should learn about developing and extending Magento features. Never touch the core/default Modules and Templates. Create new ones under the “local” folder.

This, together with the Google Analytics Universal Tracking documentation should give you all the necessary hints and information in order to update your tracking code.

If you still can’t get it done, contact me and we can talk about contracting me to do it for you, or contracting me to provide you with a training on how you can do it yourself. 

Setting-up Ruby development environment on MacOS 10.8.5

MacOS X 10.8.5 (and a few versions earlier) is coming with a pre-installed Ruby 1.8.x. That might not be enough though for what a developer needs.
Just as any respectable programming language, Ruby is continuously developed and upgraded. Us, as developers, of course will always want to update the version of Ruby installed on our development machine.
But MacOS doesn’t make it that easy. As a matter of fact, any server-side programming language you might want to develop on a MacOS machine, you get into the same problem: Upgrading requires you to manually reinstall it or recompile it.

If you’re a geek like me, you don’t want to use package managers to install/update things on your MacBook and you find it rather challenging and cool to compile yourself the software, then you may read this further.

Things you need to download:
1. Ruby: https://www.ruby-lang.org/en/downloads/
(I wanted to upgrade to Ruby 1.9.3 so I used this link: http://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p448.tar.gz )
2. LibYAML: http://pyyaml.org/wiki/LibYAML
(latest stable version available at the time I’m writing this: http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz )

Other pre-requisites:
X-Code: https://developer.apple.com/xcode/
Why do you need X-Code? MacOS by default does not have the C compiler installed. By installing X-Code you will also get everything you need to be able to compile from C sources yourself.

Installation steps:
1. You need to compile and install LibYAML before you compile Ruby.
This will run pretty easy and fast, instructions are also to be found on LibYAML website

./configure --prefix=/usr
make
sudo make install

2. After successfully installing LibYAML, we can now proceed to install the new version of Ruby
The procedure is the same as for LibYAML

./configure --prefix=/usr
make
sudo make install

But after that, we will also want to update the gem module and eventually install some other gems we need for development

sudo gem update --system

On Viget’s blog I also found a cool article on configuring autotest to run through Growl, thus using MacOS native file scans and reducing processor usage and battery consumption: http://viget.com/extend/how-why-to-run-autotest-on-your-mac

Mac OS X 10.9 Mavericks and PHP

I was waiting the official release of Mavericks since about half a year. I was positively surprise to find out the update came free of charge. So I updated my Mac OS the moment the update was made available on AppStore. It was no surprise to see the upgraded versions of PHP, Ruby, Python, mysql and so on. It was nevertheless no surprise to see that the PHP configuration would not completely meet my development requirements. One of the most frustrating features missing from the PHP installation was the Intl package. I can hardly understand how Apple would miss compiling PHP with the Intl package, as this is required by the Locale class (yes, internationalisation is the key word here). One could say PECL will handle that for you automatically. Been there, done that, failed! Reason: PECL does nothing else but download the package and tries to compile it against the php sources. But a freshly installed MacOS has almost no sources for any of the software installed on your machine. And since we don’t have any official package manager, we should download, configure and compile ourselves everything we need. There are a lot of users who would advocate using an unofficial package manager (like mac ports or homebrew) but I’m a geek, I’d rather compile everything myself and have some more fun while I’m at it. Also, since it’s a fresh OS realease/update, I’m not sure if those package manager are still working flawlessly Now, let’s start our little adventure: downloading sources and compiling PHP and its modules. I’ll present you here a list of links where you can download the sources of the packages that come with Mavericks.

  • PHP 5.4.17 (or, since you’re at it, why not upgrade your PHP version to the latest stable release PHP 5.5.5 ?)
  • Apache 2.2.24
  • Open SSL (Package is required since the default compilation options of PHP on Mavericks contains –with-openssl .I recommend downloading the latest stable version)
  • Zlib ( –with-zlib )
  • BZIP2 ( –with-bz2 )
  • cURL ( –with-curl )
  • iconv ( –with-iconv )
  • LDAP ( –with-ldap=/path/to/executable )
  • BerkeleyDB ( required by LDAP installation )
  • SASL2 ( –with-ldap-sasl=/path/to/executable )
  • LibEdit ( –with-libedit=/path/to/executable )
  • LibTidy ( –with-tidy )
  • autoconf  (required to compile LibTidy )
  • automake (required to compile LibTidy )
  • libtoolize ( required to compile LibTidy )

Each package comes with a readme or install.txt file which explains how to compile it.
Almost all of them only require a


./configure
make
sudo make install

In some cases you would also have to specify a path there to install the library. Everybody recommends using /usr/local for compiling/installing yourself anything you want to compile manually. This also has a reason. If by any chance Apple decided to support ONLY the version and specific configuration delivered with the OS, you would be able to switch back to it without having to re-install the hole operating system.

ATTENTION!
Before compiling PHP, first check which is the compile option used for the OS-default installation of PHP.
Try to stick to that compile options and add new options that you require, or remove the options that you know for sure it would create problems for your project ( I’ve worked on a project that specifically required to disable the suhosin plugin for PHPm which comes enabled by default to most of the PHP installations )

Now run the ./configure command with all the options you need, followed by “make” and “sudo make install”.
Giving that you had a successful compilation, you will now have PHP freshly re-configured/re-installed and you can proceed further with your project’s development.
After this freshly re-compile, you can now also use PECL to install new packages and modules.

This is not a complete guide, but I will try to improve it bit by bit.
If you have any suggestions or if you tried the above suggestions and encountered errors, please send me a message and I will try to cover those problems here.

DNS cache reset on Mac OS

Well, this is annoying. Sometimes you just need to refresh (or clear) your local DNS cache. If you, by any chance are using a Mac OS powered machine, you’ll have to first check what version of Mac OS is running on your machine. The command was changed at least twice during the evolution of the OS

MacOS 10.7 and 10.8 :
sudo killall -HUP mDNSResponder

MacOS 10.5 and 10.6:
sudo dscacheutil -flushcache

MacOS 10.4 and earlier:
lookupd -flushcache

replace part of a string in a mySQL table

Situation: you have a mySQL table with thousands or millions of records. You need to replace in most of the records a part of a string.
Classical example of such a situation is moving a WordPress website to another URL.

Solution:

UPDATE `table-name` 
SET `field-name` = REPLACE(`field-name`,'part of the string you want to replace','corrected part of the string') 
WHERE `field-name` LIKE '%part of the string you want to replace%'

Missing wget on MacOS?

Yeah, I was surprised today to discover wget is not installed by default on MacOS 10.8.

Luckily the available solutions are fast and simple:

1. The faster one: use cURL ( curl -O http://www.something.org/file.txt )
2. Install wget. And for this you can either use a package manager or proced the hardcore way, which in this case is pretty easy: compile wget yourself.
- guide to compile wget: http://osxdaily.com/2012/05/22/install-wget-mac-os-x/

 

What is a “Senior developer” ?

What does it take to be considered a senior developer? Number of years in the resume/CV or number of projects and clients worked for?
Are you willing to  hire a senior developer? Are you sure your recruiter has any idea what he should be looking for?

I see lots of job postings requesting a “Senior developer” and I see lots of resumes/CVs/Profiles of software developers presenting themselves as “Senior developer”
But it is rather unclear what this should mean. When will you say a software developer is “Senior” ? What are the criteria to distinguish  a senior from a non-senior developer?

Some would say a senior developer is one that has at least a certain amount of years experience of working as a software developer. But is that a valid criteria?
I’d say not even by far. I’ve seen cases (and not few) of software developers working for years in a company, for the same project, using the same architecture, handling almost the same bugs and problems. I don’t call that “experience”, I call that “routine”.
When, for years and years one only keeps himself busy with routine and nothing else, he would become specialised and  a quick solver of that particular routine.
But we’re talking here about software development, we’re talking here about software architecture.
In order to be able to find a good solution for a project’s requirements, it’s necessary that you already met a lot of situations, code styles, infrastructures, and you are able to identify patterns that best apply for the analysed project.

I would say, a senior software developer, not only needs to have years of experience, he/she also needs to have worked on at least a certain number of types of projects and different technologies.

Not only the client should be selective with the developers.

As a programmer applying for a new project or a new job, your employer will always ask to see samples of your code, will always ask you to pass a technical test. But this test should also be taken by the employer. He/they should also provide samples of the existing code in the project, they should also provide with honest information about the members of the team and their experience and skill levels.

It happend to me, not only once to be a bit too enthusiastic because I found a new client. In an age of financial crisis and budget cuts, I was actually feeling happy to still be able to find contracts as a freelancer.
Being so enthusiastic and an easy victim of marketing and sales persons, most of the times I was just giving my clients credit when they were talking about their own company and the project they were hiring me for.
But now, I just consider that the perfect key to a failure or frustrating project.

At the time I was getting close to the finish date of a contract with a really cool company in Berlin (Rocket Internet), I was contacted by the CEO of a new grounded Start-up. That made me happy. I find it very challenging and rewarding to work for Start-up companies, get to know new people, new ideas, new technologies, being able to contribute and in the same time to learn great number of interesting things.
The project is really cool. It does not only sound cool, but it is actually fun and I see a nice future for it.
During our initial talks (so called interviews), of course I got to the point where I also had to ask questions about them and their project.
I was initially pleasantly surprise to find out they’re not using an open-source framework. Nowadays, when someone is telling me they are not using an open-source solution, and they have their own developed framework, let me understand that at least one member of the team is an experienced software architect building eventually something very specific and very optimised for the project.
So, I signed the contract and canceled any other meetings/interviews I had planned at that time.

The moment of truth

Part 1: checking out the project from SVN, installing/configuring the project and trying to take a look at the code.
I’m not complaining about using SVN in an age where git is The King. As long as there is a versioning system used, I’m pleased with it. But what amazed me was the coding style.
All the classes in the project were created in the PHP4 style. Do you remember the time when PHP was not using __construct(), but instead one was supposed to write a function with the same name as the classe’s name? EXACTLY!
That also means no real OOP architecture, no encapsulation, no abstract classes, no interfaces, no inheritance.
Database? It sounds like a fairy tale, but … there is no foreign key whatsoever, let alone transactions.
The explanation for this was: “The project was started a long time ago and we just developed further that code.

Part 2: expressing concerns and suggesting improvements. 
I’m not happy (at all) working with this kind of code and I did not want to end-up being forced to develop THAT code. So I stated my concerns loud and clear: The code is bad. We cannot talk about a refactoring, this needs to be re-written from the scratch.
The reaction was somewhere between what I was hoping and  worst-case-scenario: “Yes, you are right, but we need to show something to investors to get more founds. There is no time to re-write this now, we will have to go further with what we have till we can show something to the investors.
Although I don’t like that, I cannot argue with the “investors & funds” part. I do want my invoices paid, after all.

Conclusion: now I am trapped in a project that frustrates me because of a code written without any coherent architecture in mind.
From time to time, I do check when and how they are planning on re-writing the app.
And yes, I did consider starting the new code/architecture by myself, developing it in parallel. But there are 2 problems here.

1. Since they are not planning on re-writing the project very soon, they don’t actually foresee any budget for that right now.
2. If find it unethical to develop it as a personal project. It’s not my business idea. They put in a considerable effort to develop the project’s ideas and specifications.

I’m wondering if I should do it in my personal time and when I’m ready with my first version just to present it and hand it over together with an invoice for the time I spend developing it.

Anyway, the lesson is learned. When applying for the next job, no matter it is as a freelancer or as an employee, I have to get to know both the team members and the code BEFORE signing the contract.