Blog

Autospace Bootstrap columns on small screens

A little trick I have been using in pretty much every design I worked on that was based on Bootstrap is to automatically add a margin between grid columns when they break/collapse, i.e. are displayed vertically instead of horizontally.

Read on

Spiegel Fotostrecken Awesomizer - Verleih den Spiegel.de Fotostrecken die nötige Portion "Awesome"!

Update (September 2016): Die Extension wurde für das neue Spiegel.de-Design angepasst!

Manchmal besucht man eine Webseite fast tagtäglich und bemerkt irgendwann, nach Jahren, dass sie sich einfach nicht weiterentwickelt oder benutzerfreundlicher wird. So habe ich letzte Woche gemerkt, dass die Fotostrecken auf Spiegel.de von der Usability her immer noch im letzten Jahrtausend feststecken - für jedes Bild wird die komplette Seite (mit allen Trackern und Werbebannern) neu geladen, die Pfeile zum Vor- und Zurückblättern sind winzig (12px breit und hoch!), es gibt keine Übersicht der gesamten Fotostrecke in der Form von Thumbnails, und das Weiterblättern mit den → und ← Tasten oder dem "Swipen" auf dem Trackpad ist auch nicht möglich. Alles Features, die man von Bildergalerien eigentlich seit Jahren gewöhnt ist!

Zufällig bin ich kurz danach über das Plugin Fotorama gestolpert, mit dem man sehr einfach aus ein paar Fotos eine hübsche Bildergalerie erstellen kann. Anstatt Fotorama auf meine Liste von interessanten Projekten zu setzen, in der Hoffnung, dass ich es dann auch wiederfinde, wenn ich es mal wirklich brauche, habe ich mir ein paar Stunden Zeit genommen und es in einer Chrome Extension verpackt, die die Spiegel.de Fotostrecken damit anzeigt.

Read on

How to run Ruby scripts on AWS Lambda using Ansible

AWS Lambda is definitely one of the most fascinating services I have come across in the last years. As a web developer, the prospect of not having to deal with servers and scaling at all anymore, not even in the abstract sense of Heroku's dynos, is exhilarating.

And I'm not even that averse to doing ops stuff like many other developers. For example, I picked up Ansible about two years ago and have been using it to manage my own (DigitalOcean) servers ever since and even replaced Capistrano with a custom Ansible playbook to deploy my Rails apps.

Lambda really reminds me of how Elon Musk talks about reasoning from first principles rather than by analogy. AWS already offered a "traditional" cloud hosting service with EC2, and a managed one with Elastic Beanstalk, but with Lambda they really sat down and said "OK, let's start from scratch. A developers writes some code and wants to run it. We at AWS have all these regions, servers, databases and whatnot. What would be the easiest way we could let developers run their code without caring about any of it?" And the result is Lambda - upload your code in small chunks (functions) and run it, without thinking about servers or scaling at all.

Read on

Testing async ActionMailer jobs with ActiveJob in Minitest

One of the fantastic new libraries that came with Rails 4.2 is ActiveJob - a standard interface to background queues like Sidekiq, Resque or Delayed Job. It lets you write your jobs using the ActiveJob syntax and decide on a background queue later. And if - a year from now - you are not happy with your choice of background queue anymore, you can switch it out without having to rewrite any of the worker code.

But the real power of ActiveJob is that it abstracts the implementation details of the different queuing backends and lets you develop additional tools and libraries around that central API. Any gem can now safely enqueue background jobs for example, without having to know what queue backend the application uses.

An important aspect of background jobs is the ability to test them of course. You want to make sure that a certain piece of code really enqueues a job, and that its the right job with the right parameters!

Read on

Ruby's built-in databases - meet PStore and YAML::Store

Ruby keeps amazing me! Did you know it has not one, but two databases built right into its standard library? Okay, the two are basically the same under the hood, but still!

When you write a Ruby script, it's not unusual that you come to the point where you want to persist some data, so that when you run the script the next time, it can access that data from the previous run. Examples are the result of an API call you don't need to execute every single time the script runs, configuration values that rarely change, or a timestamp of the last time a certain action was performed.

Read on

How to use Basic Authentication with the Ruby Rest-Client gem

I hope this will save someone the hour that it just took me to google, try out several StackOverflow answers and finally finding the solution in the source code (note to self: move "check the source code" to the top of the list of things to try next time).

Read on

How to validate the uniqueness of an attribute across multiple models in Rails

I recently ran into the situation where I had multiple models that each had a identifier field, and each object of each model had to have a unique value for this field.

Now, in my specific situation, I could have used UUIDs, because I was using Postgres and the identifier didn't have any other requirements apart from being unique, but there is a nice generic way to implement uniqueness checks across models in Rails, which is what I chose to use.

Read on

How to configure Nginx to return an error for requests without a matching host

When you host multiple apps on the same server using Nginx, you probably define multiple virtual servers like this:

server {
  server_name my-awesome-app.com;
  ...
}

server {
  server_name another-brilliant-app.com;
  ...
}

server {
  server_name such-a-fantastic-app.com;
  ...
}

Then you set up a monitoring servive like Pingdom for each app to make sure you are notified if anything bad should happen and one of the apps would go down. The next day a coworker decides such-a-fantastic-app.com is no longer needed and removes that server blog from the Nginx config. But hey, since you set up monitoring, you will get a notification immediately, right?

Well, you guessed it, WRONG!

Read on

Recalculate counter cache columns in Rails

Rails has this great feature called counter_cache. When you have a has_many/belongs_to relationship between two models, it basically lets you say that you want to save the number of associated objects on the has_many side. So if you have Post has many Comments, you can do post#size and no SQL query is executed, Rails simply just looks at the comments_count field of the post.

And - as with so many things in Rails - the beauty is that it just works out of the box, the way you would expect it to work. When you create or delete Comments, Rails keeps the comments_count fields of all associated Posts up to date. Well, most of the time. I have had the situation a couple of times where I ended up with a negative value which obviously doesn't make sense.

Read on

How to get free SSL for your SquareSpace website with CloudFlare

I noticed that many people struggle with setting up CloudFlare and SSL for their SquareSpace site, so here's our offer - let us do the setup for you for a flat fee of just $49!

Click here and fill out the form and we'll get in touch with you soon after!

I recently set up SSL for one of my websites which runs on SquareSpace and was amazed by how fast and straightforward it was using CloudFlare - not to mention that it's completely free! Since the only information I could find on this topic is an entry on the SquareSpace help site with some outdated information, I thought I'd document the necessary steps here.

Buckle up!

Read on