There is trouble brewing, or: Openssl issues on Ruby with Homebrew

This post is to describe an issue I’ve run into using < 2.3 versions of Ruby on OSX with rvm and brew.

Don’t even get me started on working with older versions of Ruby — we have some maintenance projects running in ruby-1.8.3! Even modern Rubies may give you a hard time, however, and this is one of the times. Actually, I am writing this post as a reminder for me because I ran into the same problem twice now, and what is worse, the second time it took me nearly the same amount of fruitless googling to solve it as it took the first. And the solution was the same! So, let us proceed with order.

Continue reading “There is trouble brewing, or: Openssl issues on Ruby with Homebrew”

More space, more productivity, more fun

Whoever uses a laptop finds out that there are situations where they want more available space on their desktop. For this reason, working with an external monitor can make you much more productive. When you are at home or at your office, you probably have a secondary display for your laptop but not when you are outside.

As many developers, I have a 13 inches MacBook and sometimes I need to have extra space to better handle multi-tasking and to increase my productivity. Now, there is a solution for those who want to have the advantages of an extra monitor even outside the office: DuetDisplay. Continue reading “More space, more productivity, more fun”

asdf the “easy to write and hard to read” version manager

As a Rubyist one of the first thing you end up doing is to manage many different Ruby versions on the same machine. As a matter of fact, one of the first steps in setting up a new workstation is to install some kind of version manager like RVM or rbenv.

Unfortunately it doesn’t end up simply like this…

Continue reading “asdf the “easy to write and hard to read” version manager”

Donkey Kong and the secrets of the brain

I don’t know about you, but for me there are few topics as complex and as fascinating as the human brain. How it evolved in us as a species, how it develops differently in each individual. How this small, low-power biological device can store memories for years, carry out complex tasks, explore large decision trees in a matter of seconds or compose the 9th Symphony in D Minor. How it enables the existence of the individually unique bundle of thoughts, feelings and self-awareness that is consciousness.

Continue reading “Donkey Kong and the secrets of the brain”

How requirements shaped my code, AKA Rails 5 and ActiveRecord before_destroy callbacks

I recently started a new project with Rails 5, and at some point I found out the code was not behaving as expected.
The initial scenario was quite simple, Admins can have many Phones, as this code suggests:

Continue reading “How requirements shaped my code, AKA Rails 5 and ActiveRecord before_destroy callbacks”

Wrap and iterate with the power of yield

Iterating over a collection isn’t rocket science. Obviously if you need to iterate over a really big collection you may need to adjust your strategy but it is something that in the vast majority of programming languages you get quite for free.

In Ruby for example you can just send the each message to your collection together with a block of code. The block will be executed for each element of the collection itself.

But what if you need “something more” from the objects you’re iterating on? If, for example, each element of your initial collection is an array and you want to abstract away how you access each of its elements? What options do you have?

Continue reading “Wrap and iterate with the power of yield”

Swift: How to send SOAP requests with AlamoFire 4.0

We do love our JSON APIs, but sometimes we need to work and talk with the Dark Side and perform SOAP requests exchanging XML responses with a server far far away.

In our Objective-C projects we grew fond of AFNetworking, but having switched to Swift (and Swift 3 nonetheless) we had to rely on the new Alamofire 4.0.

Why new if it is a 4.0 version?

Alamofire 4.0 brings a big rewrite and some breaking changes, needed to address the new Swift 3 syntax and to ease some things up. The breaking changes involve how to make a request and how to encode our parameters, key aspects if you want to talk with a SOAP server. The changes have been introduced only recently and it seems few people had the same problem of having POST requests on a legacy SOAP server, so the literature on the web is quite scarse and this post wants to fill this gap.

As with everything, the solution when found, is quite simple.

At line #6 we set the headers up, the SOAPAction one is quite important, since without it nothing worked. As always, YMMV, but you should find the correct value inside your WSDL of reference.

At line #16 we setup the request, the encoding parameter is the key of this post: to encode the request we write an extension to String:

In this extension we specify the format for a correct header as requested by our SOAP server and serve it during every request.

And we are ready to go.

Then, if you need to parse the XML response (otherwise why talk with the server to begin with?), we suggest you to use the XMLHash library of SwiftyJSON inspiration.

We hope this little bit of information will save you some research time.