Tudor Barbu's blog

Ramblings about software development

This post was sitting in my Drafts folder for quite some time. It’s about setting the application environment in Zend Framework applications. As you might already know, ZF applications can run in different environments – usually dev / staging / production – and the environment is set in the vhost. In most examples, you’ll find something like:

SetEnv APPLICATION_ENV development

I really don’t agree with this approach. I think that the application environment should be set in a configuration file. This way, it’s available application wide – not only to pages dispatched under Apache. For example, if the application has a cron job that runs daily and sends emails to the users – such as birthday cards or daily digests – the CLI application won’t be able to access the information stored in the vhost file and this will create all sort of problems. How I do it:

In index.php, in the first part, before bootstrapping the application:

// Load the application environment
$environmentPath = APPLICATION_PATH . '/configs/environment.php';
if (!file_exists($environmentPath)) {
	require_once 'Zend/Exception.php';
    throw new Zend_Exception(
        sprintf(
            'Configuration file %1$s is not found. To create one, please read the comments in %1$s.example!',
            $environmentPath
        )
    );
}

require_once $environmentPath;

…then I create a simple application/configs/environment.php file:

define('APPLICATION_ENV', 'development');

…and, in order to avoid conflicts, I add the following entry in Git’s .gitignore file:

application/configs/environment.php

And voila! A much better way of setting the application environment!

TODAY IS THE INTERNATIONAL CAPS LOCK DAY. CHECK OUT WIKIPEDIA. IF YOU WANT TO ADAPT YOUR SITE, JUST ADD THE FOLLOWING LINE TO YOUR CSS:

* {
    text-transform: uppercase;
}

HAPPY INTERNATIONAL CAPS LOCK DAY :)

From time to time I post articles & reviews about products, services and events I like or support. This is one of those times, when I’m going to talk about two events scheduled to take place later this year:

PoolPlay Summer Academy

While not directed strictly to developers but to creatives from different industries – of course, programmers are also welcomed, in the end code is poetry, right? – PoolPlay Summer Academy is a 2 weeks camp in South Tyrol, where they improvise theatre in an empty pool. Might be worth it to go there just to turn on the water while everybody else is in the pool :P .

You can check out the PoolPlay website and / or read their flyer.

PS: they also look like they need a web designer :P

Oxygen Accelerator

Oxygen Accelerator – the programme in which I enrolled last year – is starting again, so if you have a business idea and looking for funding, mentorship and help developing your business, consider applying for Oxygen 2.0.

Now the accelerator offers a much better deal than it did last year, with up to €40,000 cash investment and 26 weeks of incubation. Check out their blog post.

19 Jun

Linus Torvalds is the MAN

Posted by Tudor. Tags:

…I remember how hard is was to get the drivers working for an Nvidia card!

16 Apr

Validate URLs in Zend Framework

Posted by Tudor. Tags: ,

I was doing some dev work, as usual in ZF, and I was surprised to find out that there’s no Zend_Validate_Url or Zend_Validate_Uri class among the framework’s default validators. Which is a bit weird, as validating URLs in a very common task in web development, much more common than, let’s say, validating a barcode or an IBAN.

But validating a URI is easy using a combination of Zend_Validate_Callback and Zend_Uri. Check it out:

$url = new Zend_Form_Element_Text('url');
$url->setOptions(
	array(
		'label'      => 'Enter the URL',
		'filters'    => array(
							'StringTrim',
							'StripTags',
						),
		'validators' => array(
							'NotEmpty',
							array(
								'Callback',
								true,
								array(
									'callback' => function($value) {
										return Zend_Uri::check($value);
									}
								),
								'messages' => array(
									Zend_Validate_Callback::INVALID_VALUE => 'Please enter a valid URL',
								),
							),
						),
	)
);

It still puzzles me why there’s not a standard URI validator…

13 Mar

Open .ai files in Gimp under MacOS

Posted by Tudor. Tags:

Do you know what a web designer is? A guy that wasn’t man enough to become a software developer yet not gay enough to become a fashion designer. Leaving the joke aside, design is an important part of web development. As with everything, looks do matter.

And you truly see the value of a designer when you don’t have one on the team. Like me now. I needed some graphical changes and didn’t have anyone to do them. Big problem. But I’m quite good at solving problems, and I’m not scared to try new things, so I dove in. I had some Photoshop and Illustrator files from the previous the previous designer and I thought it shouldn’t be too hard to change some colors.

The only problem was that I didn’t have Photoshop installed on my laptop. Given that Photoshop is quite pricey and I don’t want to spend money on a piece of software I use once every 6 months, I started looking for alternatives to Photoshop that work under MacOS. And the first one that popped into my mind was GIMP. Which is a good piece of software, but it comes with X11, so all MacOS shortcuts don’t work – CMD + C / CMD + V have to be replaced with CTRL + C / CTRL + V and so on, which is a bit annoying, but hey, it’s free and it does the job. Or not.

I had to open an .ai file – Adobe Illustrator – which GIMP does not support. I know that this might sound stupid, but I never used image editing software. After some googling around, I found out that GIMP is not supposed to open .ai images as these are vectorial. So I needed something that can open vectorial image formats, was free or extremely cheap. And I did: Inkscape.

So, for all developers out there, if you want to open an .ai file and don’t have Photoshop / Illustrator, install GIMP and Inkscape, open the file in Inkscape and then import it in GIMP. Maybe it will save you several hours of googling around.

23 Feb

Cisco VPN blocking other connections

Posted by Tudor. Tags: ,

I had a weird problem today with my VPN connection: when I was connected, my Cisco VPN client seemed to block all other HTTP connections. Skype & Yahoo! Messenger were working but all HTTP(S) connections on both browsers (Chrome & FF) were down. Which is extremely weird and I couldn’t pinpoint to the core of the problem.

So I did what any responsible IT person would do: googled. But I couldn’t find anything relevant. One article suggested going to “Modify » Transport” and check the “Allow Local LAN Access”. Which I did but didn’t work.

So I started playing with the network settings and at some point I got it working by changing the DNS servers to 8.8.8.8 – Google’s DNS. While I’m not sure what cause the problem or if this is the right solution, I’m posting it here so maybe it will work for somebody else.

I’m quite sure that by now everyone has heard of ACTA. It’s an international treaty negotiated in secret by a bunch of spineless, unelected wankers set to fulfil the wishes of their Hollywood paymasters. Just read my previous post to find out more.

Under ACTA everything we do online will be tracked and our privacy will be violated just to enforce the IP rights of some media giants. Big Content companies will have the right to ask ISPs for our data directly, without any judicial supervision, without having to even consider obtaining a search warrant. The only way our privacy would be violated more is if the government – or private companies to follow ACTA’s trend – install video cameras in our apartments.

And, for the time being, the European Parliament is okay with ACTA.

I’m not saying that European MPs are complete idiots, not all of them anyway, just the majority required to pass a bill. And not any bill, I’m talking about the 2009/136/EC Directive or the so called “Cookie Law”. This law prevents websites from using cookies without asking for user consent. If you’re a tekkie, you know what a cookie is and what impact this law will have on the internet. If you’re not, well, just trust me on this one: over 90% of sites are illegal under this law. And complying with the law is a messy, expensive and time consuming process that will cripple EU technology companies trying to compete with their American or Asian counterparts.

And why this directive, you ask!? Well, to protect the average EU citizen’s right to privacy. Yes! The same body – EU parliament – enacted both ACTA and Directive 2009/136/EC. Just to put things in perspective, the last EU election was held in June 2009 and the directive was passed in November 2009, so the exact same people that passed the Cookie Law are thinking of passing ACTA. It’s not even a different legislature.

This is how I picture a normal day in the European Parliament:

I think that we should vote a new law in place, so all members of the EU parliament to be forced to take an IQ test before being sworn in office. Just to see whether they’re smarter than door knob or not. A regular door knob, not a fancy electrical one!

This is a post I’ve wanted to write for a long time, perhaps it will be useful to others. It’s about using Zend_Db_Table_Select and the SQL LIKE statement. I remember it giving me some headaches in the past, so here it is:

The problem is that Zend’s implementation is a bit counterintuitive, as the % sign is part of the query – as it has a special significance in SQL – and not of the string being search. So the first thing in my mind was:

My_Table_Example extends Zend_Db_Table
{
    public function search($value)
    {
        $select = $this->select();
        $select->where('column LIKE ?%', $value);

        // ...
    }
}

Which doesn’t quite work. Of course, one can always use good ol’ string concatenation, do it like this:

My_Table_Example extends Zend_Db_Table
{
    public function search($value)
    {
        $select = $this->select();
        $select->where('column LIKE "' . $value . '%"'); 

        // ...
    }
}

…and risk an SQL Injection attack. Definitely not the best approach! In the end I found the best solution to do it is:

My_Table_Example extends Zend_Db_Table
{
    public function search($value)
    {
        $select = $this->select();
        $select->where($this->_db->quoteInto('column LIKE ?', $value . '%'));

        // ...
    }
}

…which, as previously stated, it’s quite counterintuitive. But hey, it works :)

Few days ago I was asked if I can review on of uCertify prepkits. I wrote a review some time ago for a different prepkit – full review here XK0-002: Linux + PrepKit – and at the time I was impressed with the quality of the kit. So I agreed to do it again. This time, I picked the prepkit for the Certified Ethical Hacker or CEH certification. For those of you who don’t know it, this is the Chuck Norris of security certifications.

I downloaded the Windows executable version of the prepkit, in hope that I will be able to make it work on my Macbook. No such luck. I tried Wine and CrossOver, but it kept on crashing. After several hours of frustration I emailed back the guys at uCertify with the issue. They suggested using the web version of the prepkit – at the the time I didn’t know there was a web version – which worked like a charm on all platform. So, first lesson learned – if you have a Linux / Mac system – go straight to the web version.

Usability, look and feel

I found the prepkit to be particularly easy to use. The interface is really straight forward, very clean, with good typography that doesn’t tire your eyes. Typography is particularly in this case, as geeks – myself included – wear glasses and don’t like hard to read “artistic” fonts.

The information is structured in a logical manner, everything is where you expect it to be. Just have a quick look to the screenshot on the right!

Maximum score to usability & ease of use.

Features

The information is divided into 3 main areas: Learn & Practice, Study Material and Performance Assessment and Analytics and each section is divided into multiple sub-sections.

The Learn & Practice section is comprised of various tests, which can be used to mimic a real life exam (Test mode), study (Learning mode) or to review your knowledge (Review mode). Screenshot to the right!

Study Material is comprised of:

  • Subject/Exam Standards & Objectives
  • Study notes
  • Articles
  • Flash Cards
  • Key Terms
  • Glossary
  • Online Reference Library
  • Study Tips

…and Performance Assessment and Analytics of:

  • Study Planner
  • Progress reports
  • My Activity
  • Daily Snapshot
  • My Focus
  • Performance on Practice Tests
  • Readiness Report

Some of the features are really cool, I especially liked the Study Planner, which helps you plan and keep track of your progress, a very important tool as we all know that IT guys are generally lazy and don’t like reading manuals.

Although getting messages like:

Your preparation is about 0.5% complete. You took 1 days to complete 0.5%. At this pace you will need another 6 Months, 2 Weeks, 5 Days, to be fully prepared for the exam.

might be a bit demotivational.

Usefulness

To make things clear from the start, this is not an online course for beginners. The prepkit targets experienced professionals, not learners or script kiddies. But that’s not necessarily bad, as the last two categories are not even eligible for certification according to EC-Council’s eligibility form.

As I have yet to take the CEH exam, I can’t say how accurate or useful the questions are in a real life scenario, but given uCertify’s vast experience in the area of preparation kits for top IT certifications, I’m sure it’s useful.

Conclusion

I found the prepkit easy to use, filled with high quality information and well structured. I think it’s a good deal for $119.99 (aprox. €91 / £75), especially since uCertify offers a full refund if you fail the exam. Give it a try. Or if my review didn’t convince you, try it for your self. There’s a demo version available here.