How NOT to pass The Symfony Dependency Injection Container as an argument

This is the (almost undocumented) best practice for using the dependency injection container in Symfony, so Sensiolabs Insights won’t return an error that states “The Symfony Dependency Injection Container should not be passed as an argument“.

Any class that needs to use the container service should implement the ContainerAwareInterface interface and in addition use the ContainerAwareTrait trait. Here’s an example with a Doctrine migration:

Continue reading

Object Calisthenics · maintainability, readability, testability, and comprehensibility of code

Object Calisthenics are programming exercises, formalized as a set of 9 rules invented by Jeff Bay in his book The ThoughWorks Anthology. The word Object is related to Object Oriented Programming. The word Calisthenics is derived from greek, and means exercises under the context of gymnastics. By trying to follow these rules as much as possible, you will naturally change how you write code. It doesn’t mean you have to follow all these rules, all the time. Find your balance with these rules, use some of them only if you feel comfortable with them.

Source: Object Calisthenics · William Durand

  1. Only One Level Of Indentation Per Method
  2. Don’t Use The ELSE Keyword
  3. Wrap All Primitives And Strings
  4. First Class Collections
  5. One Dot Per Line
  6. Don’t Abbreviate
  7. Keep All Entities Small
  8. No Classes With More Than Two Instance Variables
  9. No Getters/Setters/Properties

5 Mandrill Alternatives for Your Transactional Email

All of a sudden, Mandrill has decided to merge back with MailChimp (originally, Mandrill was a startup within MailChimp, but operating independently, with their own model, databases, prices, etc.), and while doing so, they’ve basically forced their users to start spending up to 4x as much for the service.

Source: 5 Mandrill Alternatives for Your Transactional Email

Context: Mandrill Blog

The two guys you always forget, but you have to have on your hackathon team

This weekend I participated in the hack.summit() virtual hackathon 2016 along 5 other guys – one from UK, one from Switzerland, two from India, and another one who was silent on Slack for the whole time.

We were 6 guys skilled for back-end. Guess what? We failed. The thing we missed the most was someone to articulate our technical ideas. Continue reading

How I fell in love with JavaScript

A few weeks ago I heard about Code Fights during an interview at a cool web development firm. Those guys rocked it hard, told me the HR girl. I tried a few practice rounds against bots just to see how I compare to them. Math, bugfixes, code recovery and free code, all timed. It was fun.

Then I discovered challenges. Oh my. Challenges. Gotta love challenges. Solve a problem writing the shortest code possible. I tried my hands at a few with PHP, it was so … verbose. JS Gods rocked with 60-70 chars and I barely got under 120 chars in PHP. Up until then I pretty much hated JavaScript.

Continue reading

How to put some JavaScript in your JavaScript template: Jade

if we want to use any JavaScript at template compilation time—in other words, to write executable JavaScript code that manipulates the output of the Jade (i.e., HTML)—we can use the -, =, or != symbols. This might come in handy when we output HTML elements and inject JavaScript. Obviously, these types of things should be done carefully to avoid cross-site scripting (XSS) attacks. For example, if we want to define an array and output symbols, we can use !=.
Continue reading