Automatically installing all Ansible role dependencies

I think it was a couple of months ago now that I first started to fiddle around with Ansible. Being used to work with Puppet as a system provision tool before, Ansible seemed to make this task I disliked so bad before very easy. Almost fun I guess.

One thing that I found missing though, was a way to automatically install all the role dependencies. This still seems to be a task you have to do manually. Or anyway, I can’t find a way how to do it with the current Ansible version. So, being a programmer and all, I wrote a script for it.

The script itself is very simple:

  1. Loops through every role installed in roles/
  2. For every role, it fetches dependencies from meta/main.yml
  3. Installs the dependencies via Ansible galaxy

Personally I haven’t found a use case for other features, but if you do, please let me know.

The script source is available here: GitHub link
Available for download here: Direct download

Happy coding!

Charles is my superhero!

As a true geek I am a big fan of several superheroes. Actually, Iron Man is by far my favourite one. Or actually, the coolest part about Iron Man is J.A.R.V.I.S. if you ask me. The Just A Rather Very Intelligent System, is a clever system that assists Tony Stark in virtually everything that he considers “everyday tasks”.

Unfortonately I do not embody a superhero, but I do have several tools that assist me with my everyday tasks, and one of these tools is Charles Proxy.
Like my IDE helps me with being productive in writing, testing and troubleshooting code, Charles Web Debugging Proxy helps me with most of the things that are related to HTTP. And as a web developer, you know, that’s a lot. Here are some of the most significant contributions of Charles in my everyday work.

Communication insight

Specifically when developing APIs, a lot of communication is happening “under water”. A website does a request to an API, or a mobile device calls some webservices, and you want to know what’s going on. As with most proxies, Charles can show the HTTP-client requests. What’s connecting when, to where, and with what headers, cookies, request/response bodies etc.

Request tampering

Screen Shot 2013-07-25 at 20.34.59By setting a breakpoint on a specific request, you can modify the entire HTTP request the client is sending to the server. Change headers, cookies, request bodies, query parameters. In short, everything that you need to troubleshoot most common HTTP-related issues. Activate this in the context menu of a specific request -> Breakpoints, and the next time your client requests this URL, charles will break on the request.

Give colleagues and devices access to your dev environment

Another very convenient feature is that if you set your proxy server as a system-wide proxy on let’s say, your mobile device or colleagues’ machine, that they can see everything web-accessible on the machine you’re running Charles on.
So in practice, it means that you can check out your application that’s running on let’s say, a host-only connected virtual machine. This is something that we use a lot here in the office. Pretty neat, huh?

But there’s more…

Actually, the list above is just the tip of the iceberg of Charles’ features. There are a lot more features in the application, like: Bandwidth throttling, Request filtering, Recording/Replaying and saving sessions, DNS spoofing, SSL proxying, and there’s still more.

So, why a blog about Charles’ features while I could also visit it’s website?

Well, if you’ve read this far, I’ve got your attention. And that’s exactly what I was after. My goal with this post is to show that there’s a tool that can help you with things that can be very cumbersome without a proxy. And more! Charles is just great, and every web developer should at least know about it’s existence.

Of course, Charles is not the only Proxy program out there, and probably there are tools that have more or less the same features. If you know such a tool, could you let me know in the comments?
Oh, and Charles runs on virtually every desktop platform!

New writing tool: Getting in the zone

Usually when I am writing, I get distracted a lot. And I mean a lot. And this is one of the reasons that i don’t write as much as I want to.

However tonight I found this tool called OmmWriter. And it is specifically designed to zone yourself out from all distractions and write. Just write. It helps me a lot to do productive writing.

ommwriter-logo-main

When starting the application, which runs in full-screen mode only, it suggests that it works best with your headphones on. And this is where the zoning out begins. After the splash screen the application plays a soothing ambient song in the background. And it helps me focus on my screen.
Music normally distracts my thought from the task at hand, but this music does not. Excellent!

As soon as you start typing you hear the sound of your keyboard. A little something that the application adds. I think it works motivating to hear the ticks of the keyboard. It motivates to stick to the rhythm of typing.

Proof that this works is that last night I’ve written a 900 word blogpost in under an hour. Possibly one of the longest blogposts that I’ve ever written. Now that’s some productive writing!

If you are interested in this application, you can download the application for free at the OmmWriter website. It is available for Mac, Windows, and iPad.

See, another 200+ word blogpost done in under 10 minutes. Way to go!

Javascript minification in capistrano/webistrano

Photo: http://www.sxc.hu/photo/347930

Recently i had to automate the minification of specific javascripts. Since we don’t have a real build tool, i thought it was best to do this during deployment.
For (automatic) deployments our tool of choice is Webistrano, which is based on Capistrano, which is written in Ruby.

Capistrano has this concept of recipes, which are small scripts that you write to do specific tasks during deployment.
So, one of these tasks could be the minification of some javascript.

But for the minification and deployment of that, i was bound to some constraints:

  • We’re using the yuicompressor (java)
  • Deploy target machines do not have java installed
  • So we have to do the minification locally

After doing some initial research it was quite easy to do, and i came up with the following code:

The approach can be considered somewhat unusual, as the project’s files are first uploaded to the server. And after that the javascript is minified and uploaded seperately. This is mainly because I couldn’t find another hook within capistrano that fits my need.
Of course, you can rewrite this script to work with any other local command too.

Note/disclaimer: This script uses the copy_cache directive. I’m not a capistrano expert, but this variable might not be available to all deployment strategies. This script might not work for you if copied 1:1. But i suppose you get the idea.

Productivity ABC: A

Automation

Gears

© 2011 foxbit – sxc.hu

Automation can be very profitable when it comes to boosting productivity. Not only because you don’t have to do an action manually, but there are other productivity gains.

Eliminating the possibility of human error is one of them. Automation is especially useful for repetitive tasks. Tasks which are more often than not boring as waiting for grass to grow.
Waiting, or being bored decreases focus and causes the need for distraction. And losing focus on the task at hand is the worst thing that can happen to your productivity.

There are a lot of tools that can help you with automating different type of tasks. As a software developer i usually make small scripts for tasks i need to automate. Therefore i don’t use many automation tools. However, if you have suggestions for productivity tools, please leave a comment!
Some of my favourite automation languages: PHP & shell.

Attention span

Oh look, a butterfly!

Distraction: “Oh look, a butterfly!” – © 2012 irum – sxc.hu

Try to find out what your average attention span is, and always take a short break after that period.
It doesn’t have to be a long break. Just grab a coffee, stretch, do a small (but different) task, or anything like that. You need this to re-focus on the task. If you start on the original task again, work while your attention span lasts, and then take a break again to refocus after that.

It may sound that you will lose a lot of time because of all the breaks, but this is not true. (if your breaks are short enough, hehe).
Working longer on a task longer than your full attention lasts will result in working less efficient, and what you do is possibly more prone to errors. So taking a break every now and then will most likely boost your productivity.

Finding out how long your attention span lasts can be quite a challenge. It might be good to know that the maximum attention span lies somewhere between 3 minutes (young children) and 20 minutes (adults).
The easiest way to find your attention span is to start a stopwatch, and start working on the task you want to complete. Stop the stopwatch and remember what time is on the stopwatch. Reset and start the stopwatch and continue on the task. Do this a couple of times and you’ve found your average attention span.

For more information on attention span visit Wikipedia.

Is success the key to happiness, or the other way around?

Yesterday I was watching this TED talk from Shawn Achor and this question hasn’t left my mind since. The speaker talks about that being happy makes you work and learn more effective, and claims that therefore you can be more successful. I think this statement, or rather, fact is very valid and is worth to stop and think about for a minute.

Shawn mentions that chasing happiness by working towards successes that we want to have is a never ending one, as we constantly set new targets and raise the bar. Or, quoting Shawn “If happiness is on the opposite side of success, your brain never gets there.”

Standing still by what we have achieved so far makes one happy, and let’s you do and focus on what you like and love. Which, according do Gary Vaynerchuck (you should read his book Crush It! and The Thank You Economy) is the key to success and personal development. Which, in turn, raises your level of success and if you stick to this approach, your level of happiness.

Think about it. What is your attitude to happiness and success?

I found this all very interesting and worth thinking of. If you are reading this and are looking for more in-depth info I can recommend you to view Shawn’s presentation.

Fast search and replace in large files with sed

Last week i had to search and replace all occurences of a string inside a relatively big MySQL database dump file. My previous experiences with search and replace actions in files of similiar size or bigger suggested that this was going to take me a while. Normally i would write a small PHP script to do the search and replace action for me. However, recently i’ve been looking to find better, more productive, ways to do everyday things. So after a quick google i found the *nix tool sed.

What sed is, is best described from it’s manual:

Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed’s ability to filter text in a pipeline which particularly distinguishes it from other types of editors.

The command to search and replace is similar to the syntax you would use in vi.
Let’s say you have a file database.sql and want to replace every occurence of myolddomain.com to mynewdomain.com. You would use the following sed command:

$ sed -i 's/myolddomain.com/mynewdomain.com/g' database.sql

By executing this command sed will go through your file, searching and replacing every occurence of myolddomain.com within moments. In my case, on files of 18MB and 32MB, the search and replace took under a second. But will take just moments on files much bigger than that.
Since sed is a command line tool and accepts all kinds of input, be it streamed or piped, it is a tool that is suited for a lot of different use cases.

Sed is probably good for a lot more than just search and replace. But i’ll have to look more into it to write something meaningful about it. If you want to read more about sed or check out the slides of the presentation “Sed & Awk – The dynamic duo” by Joshua Thijssen.

Oh by the way, as i mentioned sed is a linux/unix tool, but also seems to be available for Windows. It’s probably included in Mac OS distributions as well.

Easy SASS compilation in WebStorm / PhpStorm

If you are a regular reader, you might have noticed i have started using SASS a while go. If you are not, and don’t know what sass is, you can read my previous post on sass here.

Recently Webstorm/PhpStorm introduced the support for sass syntax highlighting, which is really awesome, but the compilation of SASS files is not integrated in the IDE.
There is however a way to set up Webstorm/PhpStorm to use external tools, which is perfect to make sass compilation from within the IDE possible.

Just follow the steps below, and you can enjoy the comfort of SASS compilation from within your favourite IDE.

Open the Settings panel: File > Settings

Then go to “External Tools” and click “Add…”

The following screen shows up, fill in the values you see (but point the “program” field to your sass installation path)

Now, right click on your SASS (or scss) file, and the sass tool will be right there, as you can see in the screen below.

Some additional useful tips:

  • Alternatively, if you prefer the one time compilation, or other sass parameters, just change the “parameters” field, or create some duplicates of this external tool setup.
  • If you work with “deploy to FTP” on save, make sure to enable the “Upload external changes” option.

Sass – Stylesheet tool

Sass logoNow this tool you are going to read about is nothing new. In fact, it’s been around since 2007 according to Wikipedia, but i have to share it with you because it will make your life easier!

“Syntactically Awesome Stylesheets” is what Sass stands for and is a tool to make several things related to writing and deploying stylesheets easier. It is a command line tool written in Ruby, and is available as a ruby gem.

For writing stylesheets Sass has a couple of (language)features. For instance it supports variables, calculations, includes and this thing they call ‘mixins’; some sort of templates or functions.

Sass or actually, since version 3 they call them .scss, files need to be converted to normal a CSS file so you can use it like any other CSS file in your browser. This conversion is being done by the command line tool.

One of the most interesting features of this tool is that you can tell sass in what format it needs to output the css format. It can render normal (extended) css, but also in a compact or compressed way.
This is useful when you have deployment scripts for different environments.
Also, while developing, don’t worry about having to run the command every time while: with the –watch switch sass will automatically watch your scss file for changes and render a new css file each time it’s saved.

I really like tools that are easy to use, require no configuration and require no alteration of my workflow process and Sass is definitely one of them!
If you want to learn more about Sass or want to start using it right away, check out their website!

Using a PHP IDE: The start of a journey

So this week i’ve started the epic journey of setting up an environment to make full use of an integrated development environment for PHP.

Now using version control, develop locally, debugging, auto code-completion etc. is something i’ve heard a lot of people talk about lately.
Not because it’s a hot-topic, but because it’s mandatory for every (PHP) developer that wants to make full use of his or hers creative mind. Yes that’s right, what i considered first to be “Overhead” like version control seems to be mandatory for making your life as a developer easier.

As my day to day job requires me to work with several developers directly on a FTP server, i was never able to use a PHP IDE to it’s full extent. Things like debugging, auto code completion, version merging do not seem to be possible with *any* PHP IDE when you work directly onto a FTP server. So this has to change. And besides, this leads to a lot of problems which i probably don’t even have to explain.

Now that i am becoming more interested in Open Source development i have to do some research on how to set this all up.
Which is exactly what i am going to do this weekend.

There are a couple of problems i ran into before even starting to set things up. I still have to think of a solution to these:

  • Database version control
  • Automatic deployment
  • Merging feature branches to the testing/staging/live branches

Probably how to handle database version control concerns me the most, have to read up on that a bit more.

PS: Any idea’s, tips or tricks are welcome, as i am fairly new to all of this!