5minutenPause

iOS and Mac OS X programmer from Berlin. coffee-geek. tea lover. on rails.

Careful Where You Get Your Gems From

I use this gem “acts-as-taggable-on”. It’s for tagging (articles for example). The default configuration is case-insensitive to tag names. If you take a look at the gems github.com repository you can find a setting ActsAsTaggableOn.strict_case_match = true. If you actually set this setting you get the dreaded (NoMethodError):

1
.../config/initializers/acts_as_taggable.rb:2:in `<top (required)>': undefined method `strict_case_match=' for ActsAsTaggableOn:Module (NoMethodError)

I took a look at the ActsAsTaggable Module inside rails console and couldn’t find the setting/class variable anywhere. Turns out, it isn’t included in the rubygems.org version (yet). You need to specifically declare to use the github.com version:

1
gem 'acts-as-taggable-on', git: 'git://github.com/mbleigh/acts-as-taggable-on.git'

Then you can set your configuration options and everything works. Just be careful where you get your gems from.

Watch a Folder for New Files and Convert Them With Bash Script

For a recent web app project I needed a solution to automatically convert uploaded files with ffmpeg. This post describes my solution so I’ll still know what I did 4 weeks from now.

The client uploads folders, subfolders and files to a specific folder via FTP. Let’s say this folder sits at /data/upload/. Every *.mp4 file inside these folders and subfolders needs to be encoded with ffmpeg. This will result in three different files per uploaded file, each with a different bit rate. This should happen automatically and only for new uploaded files.

Watch a folder for uploaded files

I watch a folder with the app iwatch. Install iwatch via sudo apt-get install iwatch. During install it may ask you to specify your configuration for Postfix. This is outside the scope of this post. You can run iwatch as a daemon and specify a configuration file:

1
 iwatch -d -f /etc/iwatch/iwatch_encoder.xml

The xml file looks like this:

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" ?>
<!DOCTYPE config SYSTEM "/etc/iwatch/iwatch.dtd" >

<config>
  <guard email="root@localhost" name="IWatch"/>
  <watchlist>
    <title>Neue Video-Daten erhalten. Encoding starten.</title>
    <contactpoint email="foo@bar.baz" name="Administrator"/>
    <path type="recursive" alert="off" exec="find %f -iname '*.mp4' -execdir /data/upload/encode_files.sh {} \;" events="close_write">/data/upload</path>
  </watchlist>
</config>

Line 9 is the crucial part.

Let’s dissect it:

  • type="recursive" - This makes sure to watch the folder recursively. So you don’t miss files inside subfolders.
  • alert="off" - You can get emails every time something happens in /data/uploads. I chose not to.
  • exec="find %f -iname '*.mp4' -execdir /data/upload/encode_files.sh {} \;" - The part inside the quotation marks is the command I want to execute once a file is uploaded. It will be executed for every file uploaded.
  • events="close_write" - I watch only this event. It means to fire the command once a file is closed after write. This is essential for large (video) files. Otherwise the command triggers while the file is still uploaded.
  • <path>/data/upload</path> - This is simply the path you want to watch.

Trigger a command for uploaded files

  • find %f -iname '*.mp4' -execdir /data/upload/encode_files.sh {} \; This is bash magic happening. Took me quite some time to find out.
  • %f is the full path of the filename that gets an event. (via iwatch documentation).

What the command does:
Find every mp4-file (*.mp4) inside directory %f and execute a certain command with this file.

  • execdir - run the command inside the directory where you found the mp4-file.
  • /data/upload/encode_files.sh {} \; - run the bash script encode_files.sh and pass the mp4-file as first parameter so I can access the filename inside the script.

The encoding script

1
2
3
4
5
6
7
8
9
10
11
f=$(basename "$1")
if ! [ -f "/data/streamfiles/$f" ]; then
  ffmpeg -i "$1" -vcodec libx264 -b:v 1000k -ab 96k -ar 48k -f mp4 -strict experimental "/data/streamfiles/$f"
fi

if ! [ -f "/data/streamfiles/128_$f" ]; then
  ffmpeg -i "$1" -vcodec libx264 -b:v 250k -ab 96k -ar 48k -f mp4 -strict experimental "/data/streamfiles/128_$f"
fi
if ! [ -f "/data/streamfiles/250_$f" ]; then
  ffmpeg -i "$1" -vcodec libx264 -b:v 500k -ab 96k -ar 48k -f mp4 -strict experimental "/data/streamfiles/250_$f"
fi
  • f=$(basename "$1") - Take the first parameter and strip it of its path. This gets you the bare filename (my_uploaded_file.mp4 instead of /data/uploaded/subfolder/my_uploaded_file.mp4)
  • if ! [ -f "/data/streamfiles/$f" ]; then - If the file doesn’t exist at the target destination run the following command
  • ffmpeg -i "$1" -vcodec libx264 -b:v 1000k -ab 96k -ar 48k -f mp4 -strict experimental "/data/streamfiles/$f" - This is a bunch of ffmpeg gibberish, also outside of the scope of this post. Ffmpeg seems overwhelming at first but is quite well documented.

And we’re done. Whoohoo!

welt.de Has a Great Way to Look for Developers

The German news website welt.de has a clever way to engage developers. Once you look at their site’s source code, you can see this nice HTML comment:

It’s German. Here’s a translation:

If you read this, we have interesting tasks for you: Work on www.welt.de and other digital products (iOs-apps, Android-apps)

Curious? Say hello at:

https://www.twitter.com/macomber
https://www.facebook.com/christoph.maier
https://www.xing.com/profile/christoph_maier

I think it’s great.

Have a Look at Your Shell History

Over the weekend I was at eurucamp. One of the many things I took with me was this fun little script/shell command made by bamb00zle:

It’s interesting seeing the commands you run most often. And seeing all these aliases I guesss I am doing it right. :D

Bubble Like It’s 1999

Andrew writes the madness and the bubble we have with mobile start-ups right now. you get funding, you burn money, you launch your app, then nothing really happens, and then you’re broke and disappear again. That’s what happened to a lot of start-ups during the dotcom boom. And it’s repeating. He doesn’t offer a solution, and neither do I, but it’s an interesting topic nevertheless.

Overpaying Makes Sense

Today I read a blog post by Allen Tucker which I thought is really worth sharing with you. It summarized many aspects I consider true and important in life. Here’s a quote to get you started:

When you overpay, you are first in line. Your stuff gets made first, and the other guy’s stuff gets done when there’s time. It gets rushed. Many of the intangible pieces that make up the quality of a product or service go out the door when we’re getting a deal. They’re doing a favor and sometimes when we bargain, people resent us.[…]

I always get great service. The staff who isn’t even waiting on me comes over to say hi. They know what I’m going to order, and if I forget something, they know it.

It’s about overpaying for things. That means you pay more for stuff you could get for less. And you deliberately pay more because you know it’s worth it in the end.

I don’t want to quote the whole article, so this is the last one. After that, go over there and read it. It’s really worth it.

Top pay attracts the best people. Although freedom and recognition generally trump pure dollars for employee happiness, those that consistently pay their employees less, end up losing their best people.

Employees don’t ask for raises. On the infrequent occasion that they do, they’re not really asking for a raise, their telling you about the new job some place else that they found, which comes with a raise. It’s your job to make sure they never have a reason to look for that job.

Often companies that can’t afford to hire the best people end up this way because they don’t hire the best people (who will generate more money). If your business is struggling, look at your payroll. Do your employees resent you? Are they making a sacrifice to work for you? It is your job to find a way to keep them thrilled to work with you, and monthly pizza parties aren’t going to do it.

As always, you are only as good as the people around you. I couldn’t find the link that brought me to this article anymore. Turned out it was André Wendt’s retweet on Twitter. Thanks again for sharing, André.

Jeff Beck

Jeff Beck is a great musician. I just stumbled upon his last album “Emotion & Commotion”. What can I say? I am loving it. He’s featuring great talent like Joss Stone. Have a listen. It’s really awesome.

Seperate RSS Feeds

In the coming weeks I will supply two extra RSS feeds. Right now you only have one feed to subscribe to. This is the main feed with every article I am writing.