Mario Behrendt

Sinatra caching with Rack::Cache, Dalli and Memcachier

If you want to use Rack::Cache to cache data within your Sinatra application using Memcached, it’s pretty straight forward. Put something like this into your config.ru:

1
2
3
4
5
6
if memcache_server = ENV['MEMCACHE_SERVER']
  use Rack::Cache,
    verbose: true,
    metastore: "memcached://#{memcache_server}",
    entitystore: "memcached://#{memcache_server}"
end

But I’m using the Memcachier addon for Heroku, which requires credentials to access the Memcached instance. In order to get this running you need to use the Dalli gem to set the mandatory options, like so:

1
2
3
4
5
6
7
if memcachier_servers = ENV['MEMCACHIER_SERVERS']
  cache = Dalli::Client.new memcachier_servers.split(','), {
    username: ENV['MEMCACHIER_USERNAME'],
    password: ENV['MEMCACHIER_PASSWORD']
  }
  use Rack::Cache, verbose: true, metastore: cache, entitystore: cache
end

Push it to Heroku and you’re done!

Note: Rack::Cache uses Dalli behind the scenes by default, even for the first example - so make sure to include it into your Gemfile.

Tips for the actual problems in web development

If you’re a developer you probably read quite a lot of blog posts, Stack Overflow questions, articles, books and so on - just to keep yourself informed and up to date. If not, you should start with it. Once you’re reading through the material you quickly realize most of the things you read about try to improve certain, very small parts of your development process. Like shaving 5 seconds from a deployment or creating another 5 Vim key bindings which save you another 2 seconds each day.

But there are so many developers and businesses out there who struggle with the most rudimentary tasks, because nobody tries to find a better solution or is able to find something on the web. So here we go, my tips for unsucking your development. If any of those things is untrue for yourself/your business, change it immediately! Seriously! There’s no excuse, it will save you time and thus, money.

Read more →

Heroku versus EC2

During the last few weeks I rewrote an existing PHP application with rails 4. Since basically everything changed (including DB schema and even DB type) a new hosting provider was also interesting.

After some research Heroku and Amazon EC2 seemed to be the best fit. During development the app was hosted on Heroku using it’s free tier for one dyno. As always, setup was very easy and all external services, like the database, memcached, Blitz.io and Papertrail were connected in no time.

But there are two “problems” with heroku:

  1. I don’t have complete control over the server(s). This is a questionable point since Heroku provides a platform rather than just an infrastructure, so one might argue that not caring about the server(s) is actually a good thing. But I rather have full control over everything.

  2. The price. Heroku’s free dyno is awesome, especially for development to get the app up and running very quickly. But once you actually need to scale, it becomes really expensive really fast.

Read more →

Alphabetical vendor list in Shopify

While migrating an existing a Magento shop to Shopify, my client faced me with a task: Implement a list of all vendors, grouped by their first character.

Since Shopify doesn’t give you as much flexibility as Magento or other non-hosted systems do, I had to try around a bit to come up with some working code. It contains several things that Liquid provides, so it might be a good starting point for other problems as well. Here’s what I came up with in a compressed and simplified version:

Read more →

How to use Trello to tackle your goals

We all want to tackle our goals. Regardless if it’s a new year’s resolution or just the summer sixpack. But most of our goals aren’t met. There are several reasons for that, but more often than not, it’s because we don’t define our goals. Tracking goals and their progress has also a huge impact.

One way to do this is Trello. Trello is mostly a project management tool, which I use in a number of client projects. But since it’s so easy to set up a new board with an individual layout, it can be used for all sorts of things. Tracking goals is one of them. Here’s a standard layout I use to define my goals and keep track of my progress:

Read more →

Makefile ?= syntax

Quick tip: Lately I worked with a bunch of developers who didn’t know about the ?= syntax in Makefiles. Let’s say you have a make deploy target which, by default, deploys to staging. In order to deploy to production you could add another target like make deploy-production or you use the mentioned syntax:

1
2
3
4
5
6
# Makefile

ENV ?= staging

deploy:
    my_deploy_script $(ENV)

So the deployment can be done like this:

1
2
$ make deploy # Deploys to staging since it's the default value
$ ENV=production make deploy # Deploys to production

This is useful in a variety of cases, like tests, generating docs and so on. Maybe you can find a use case for it in your workflow. It’s not a big deal, but can be nifty quite often.

Meetings

I’m trying to keep this one short but I had to write it down, cause it’s bugging me since a long time:

Meetings are usually the worst thing you can do with your time! And I don’t mean 3 developers sitting around one screen to debug something. I mean those kinds of meetings which are scheduled by project managers and CEOs.

Employees getting pissed and sitting around a table for x hours doesn’t help anyone. The only definitive result is a headache. Meetings can be productive and useful but almost every time there are too many people invited, there’s no clear agenda (or there is and nobody cares), no clear time frame and so on. Watch Jason Fried’s talk on TED and you’ll know what I mean. He’s completely right. But especially project managers and CEOs either don’t know they’re wasting time and money or they don’t care because they think the meeting is “important”. Usually it’s not.

Read more →

Using a WYSIWYG editor in a Magento widget

The other day a client of mine faced me with an interesting request: A widget with a WYSIWYG editor. Since we all know those tinyMCE editors from the Magento backend (for instance when changing cms pages) it sounded pretty easy to accomplish. As it turns out, it wasn’t. But here’s how to do it.

Read more →

The myth of ‘No time’

Lately I heard “I just don’t have the time” quite often. And it pisses me off. Why? Because most of those people actually have the time but use “no time” as an excuse for not getting things done. You see, if you have the time to watch 2 hours TV every evening, you have the time. If you’re sitting in a bar three times a week, you have the time. If you listening to music while checking Facebook for 30 minutes a day, you have the time. You got the idea.

Take 30 minutes of Facebook from Monday to Friday. That’s 2,5 hours a week or 10 hours a month. 10 hours. More than a whole work day one could spent on Open Source, own projects, family time, learning a language, teaching something, working out and a thousand other things that actually have a value. The value of checking your Facebook timeline 5 times a day: Right…

Read more →

Starting a company in Germany

So I started my own company during the last two months and I wanted to share my experience with you. Besides that I want to compare the founding process in Germany with the one in the US (at least a bit).

If you think about starting a business in Germany, here are the steps for an UG (GmbH is basically the same) to get it done:

Read more →