Marcos Placona Blog

Programming, technology and the taming of the web.

Picasso – Same URL but different content

Reading time: 3 – 5 minutes

I love using Square’s Picasso library whenever I need to load images into my Android applications. It lets me load images from the internet into ImageViews with a single line of code.

Doing the same thing without the library is a whole different story, and Picasso even takes care of caching and transformations for me.

Until I hit a snag

Today I was working on a demo with a RecyclerView that loads random images from the internet to display as icons for each one of the items. The naive implementation on my View Adapter looked like this:

I’ve highlighted the code above to get you to think about what is going to happen with the result on the RecyclerView. Make sure you open the ICON_URL on a new tab and refresh a few times to help you out.


If your guess was that all the images would be loaded the same for every single item on the RecyclerView, then you’ve either come across this problem or are pretty good at guessing.

Enabling logs show distinct requests being created from Picasso to the URL, which should in theory result in different images right?

As it turns out, it seems like the default behaviour for when you try to load the same URL with Picasso is that it only ever queues your request once. A deeper look into the log showed me only one of the requests was enqueued and executed. And this was not the easiest thing to realise in all honesty.

Theoretically loading up the same page over and over again should always result on the same content and if you remember well, in the beginning of this post I mentioned Picasso takes care of caching for me, and I presume in this case the URL will be the key.

Let’s make a small change to the code and check whether we can force Picasso to think that it needs to enqueue and execute every single one of our URLs regardless.

Doing pretty much the same thing as before, but notice I now have a number that gets appended to each URL. This should make my URLs look like this:{number}.

I'm ugly and I'm proud

Now let’s look at the logs:

Each one of my URLs now started a request that was created, enqueued and executed. And sure enough, now each one of the items on my RecyclerView has a different image for its icon.

But there is a better way. Right?

I found a few threads like this one indicating that a combination of the invalidate() method,  MemoryPolicy and NetworkPolicy should get this to work. So something like this should do the trick right?

Nope! Doing so presented the same behaviour as before, where only one item is ever enqueued.

So for the time being, I will stick to the solution where I add a query parameter to each one of the images to make sure I always get random results on the same URL.

Know the solution?

I would love to hear from you what the correct/less hacky solution you found to this problem. Drop a comment bellow if you know how to make this work without having to fiddle with the URL.

How to secure Apache with Let’s Encrypt and CloudFlare on Centos

Reading time: 4 – 7 minutes

I took it upon myself to converting a couple of my domains to use Let’s Encrypt in order to offer a secure connection to them. If you haven’t heard about Let’s Encrypt by now you’ have probably been living under a rock. If that’s the case though, have a read at this page and you’ll get up to speed with it.

Their getting started page describes the entire process of installation, but that didn’t really resonate with me. Upon some googling I found a great Digital Ocean article which made a lot more sense to me. That is an absolutely fine tutorial if you’re not using CloudFlare. If you came to this article from a Google search though, chances are you’re also using CloudFlare and are having issues like some of the following:

  • Failed authorization procedure
  • The following ‘urn:acme:error:unauthorized’ errors were reported by the server
  • urn:acme:error:unauthorized :: The client lacks sufficient authorization ::

Hopefully this article will show you how to get that nice green padlock showing on your website. Props to the article on Cloudflare’s support page that took me halfway the process.

Install the dependencies

I usually SSH to my server to get these things done, but this step may vary if you access your server differently.

On your terminal start by installing EPEL (Extra Packages for Enterprise Linux) repository:

Then install GIT. We will use it to get the latest version of the Let’s Encrypt Client.

Download and install Let’s Encrypt Client

Start off by cloning the repository and then saving it to /opt/letsencrypt. Feel free to save it elsewhere but /opt is a good location for third party packages.

Generate a new SSL certificate

This is where we go differently from the Digital Ocean article as we will generate our SSL certificate using the webroot option.

We’ve used the following flags for this setup.

  • –webroot-path is the directory on your server where your site is located. This is not your webserver’s root directory but your website’s
  • –renew-by-default selects renewal by default when domains are a superset of a previously attained cert
  • –email is the email used for registration and recovery contact.
  • –text displays text output
  • –agree-tos agrees to Let’s Encrypt’s Subscriber Agreement
  • -d specifies hostnames to add to the SAN. You can specify as many domains and subdomains as you need here as shown above

After you run that you should get a message saying your certificate chain has been saved.


Apparently I also need to read about upgrading Python on Centos without breaking everything

Setting up the SSL certificate with Apache

With your certificate created it’s time to tell Apache that you want it to use that. On terminal run:

And you should get a screen that looks like this:


Apache still doesn’t know about this new certificate but we’re about to change that by selecting option 1 and on the subsequent screen choosing whether we want to make HTTP required or optional. I chose Secure here as I want all of my requests to be redirected to HTTPS.

You should then end up with a confirmation screen that tells you to check that your certificates are correctly installed. This procedure will have modified your httpd.conf file to add redirects so all requests that are non HTTPS are now redirected to be HTTPS.


Go ahead and hit those URL’s and you should see that they both get a grade A pass.


Updating Cloudflare

We need to tell CloudFlare that we now have an SSL certificate and want the communication to our website to use it. On CloudFlare’s dashboard for your chosen website choose Crypto and under SSL choose Full (Strict). You will probably want to use Flexible here if during the previous step you chose HTTPS to be optional.


At this point you should be done and your website should be showing a nice green padlock on the URL bar.


You’re using WordPress. In this case you will also want to update it so the URL is always HTTPS. You can do that by going into WordPress Admin, and then navigating to Settings > General.


And that will make sure every image and every URL on your WordPress site is served via HTTPS.

Multi-Line C# Strings

Reading time: 2 – 3 minutes

I’ve seen this question being asked on StackOverflow so many times I event thought about writing a bot to automatically reply to it.

The answers vary slightly according to the experience of each developer but the question is always the same. How do you create multi-line C# strings?

Assigning multi-line strings to a variable

Say you’re trying to assign an XML string to a variable and want your code to still look presentable. The correct way to do that would be as follows:

Notice all I had to do was add an @ before the speechmarks, and this gives multi-line capabilities to my string.

But what if I wanted to have dynamic values inside my string? Say values coming from variables for example.

Assigning dynamic multi-line strings to a variable

What most people will do here is make the assumption you can use concatenation to inject variables in by doing something like this.

That is a horrible way of doing this though. Every time you add a new variable, you need to use an @ again to tell the compiler you’re starting a new multi-line string.

To assign dynamic values to a multi-line string you can use interpolation by adding the variables with curly braces within the string and then using string.Format() to tell it to replace those with the values I provide.

So much more elegant right? My string remains the same but I can now replace values in it in compile time and just keep increasing the number within the curly braces.

Let’s kick it up a notch and say your string has attributes. We’d now be looking at adding speechmarks in each of them as such:

Unfortunately it would also mean your code is now broken and you will start getting something like CS1002: ; expected. To go around that just make sure you double the speechmarks wherever you need them within your string.

And that will make your code work again and best of all – look really neat!

I’m joining Twilio

Reading time: 2 – 2 minutes

So the time has come for me to move on and accept a new challenge. As of the October 20th,  I’ll be joining Twilio as a Developer Evangelist.

Twilio has been no stranger to me for quite a while now,  and when I saw an open position in their devangelism team,  I wasted no time and applied for it.

The whole process took a bit of time, but both Twilio and I were quite keen to make sure we would be a good fit for each other.

I had a number of telephone interviews,  and then flew over to Twilio HQ 3.0 for the final round of interviews. The process was quite thrilling,  and I got so excited about it, this was the only company I actually applied for. Halfway the interview process, and after having met and spoken to some of the most clever people I have ever spoken with, I knew I wanted nothing but to work  with them.

I am supper excited with the prospect of not only writing  lot of code and working with some amazingly clever people, but also helping other developers writing some kick a$$ code in conferences, meetups, hackatons, stackoverflow…. or the pub.

Also, I will loudly and proudly wear my Twilio jacket to make sure people know they can approach me to have a chat about any Twilio integration, development in general, or life if they fancy it.

Here’s an example of what I will be doing.

So keep tuned, and get in touch!

Dart Pub packages stats

Reading time: 2 – 2 minutes

So modulecounts came to my attention, and I thought the idea was pretty neat.

I then contacted Erik (the author), and asked if he would mind also adding Dart.

He replied saying he wouldn’t mind, but quite rightly pointed out there seemed to be no way on Dart’s package manager to actually find out how many packages were live.

I asked some community members on G+, and while they seemed to have some solutions that kinda worked, there didn’t seem to be anything accurate or likely to work every time.

My solution was to then quickly knock-up a scraper up that would navigate through all pages on the website, grab some information and counts, aggregate and then generate a JSON output that could then be used by anyone trying to get some package information.

The JSON package is generated once a day as to not overload the website.

I then created a very simple app-engine client application that consumes the JSON packet, and shows information about it.

Check it out here:

Source code can also be seen in my GitHub account:

I have also exposed another endpoint for anyone wanting to use the JSON packet on their applications.

The packet is also cached daily, to make sure my app-engine account doesn’t get abused 🙂

You can see the JSON endpoint here:

Collaboration and pull requests welcome!

« Older posts