Markus Hedlund

Developer / Photographer

Contact / GitHub / Instagram

Ubuntu “compass: command not found”

The problem is that gem command executables aren't added to PATH. This is easily solved with this command.

echo "PATH=\$PATH:/var/lib/gems/1.8/bin:\$HOME/.gem/ruby/1.8/bin" >> /etc/profile.d/rubygems1.8.sh

Then re-login and it should be working.

It's necessary to escape the $ as done above. The /etc/profile.d/ directory contains app specific bootstrapping/environment variables, and is very suitable for this.

Source

Ubuntu: Compile ImageMagick

First become root.

su -

Then install build-essentials and dependencies.

aptitude install build-essential libpng12-dev libglib2.0-dev libfontconfig1-dev zlib1g-dev libtiff4-dev libexif-dev libfreetype6-dev

Now it's time to download and configure ImageMagick. I like to keep my downloaded sources in a ~/sources/ directory.

mkdir sources
cd sources/
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar xf ImageMagick.tar.gz
cd ImageMagick-6.7.7-4/
./configure --prefix=/usr

The "–prefix=/usr" part is for Ubuntu paths. After the configuration is done, it should tell you what features will be enabled. Let's compile it!

make

And then install it.

make install

Now test it to see if we did good.

convert -version

Test CSS media queries

We're working more and more with media queries at Snowfire, so we've created this tool that let's you test and explore different queries and viewport settings.

Check it out at http://snowfirelabs.com/css-media-query-tests/.

PHP escapeshellarg with unicode/utf-8 support

By default escapeshellarg will strip any unicode characters. You can in some cases solve this by setting the locale to a utf-8 variant, but that might not always work.

Another way to do this is to write a custom escapeshellarg function:

function mb_escapeshellarg($arg)
{
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        return '"' . str_replace(array('"', '%'), array('', ''), $arg) . '"';
    } else {
        return "'" . str_replace("'", "'\\''", $arg) . "'";
    }
}

The code above is translated from the C source of PHP.

Below is the C code for this function from the file ext/standard/exec.c, if you want to check. Copyright held by respective authors according to the license.

/* {{{ php_escape_shell_arg
 */
PHPAPI char *php_escape_shell_arg(char *str)
{
    int x, y = 0, l = strlen(str);
    char *cmd;
    size_t estimate = (4 * l) + 3;

    TSRMLS_FETCH();

    cmd = safe_emalloc(4, l, 3); /* worst case */

#ifdef PHP_WIN32
    cmd[y++] = '"';
#else
    cmd[y++] = '\'';
#endif

    for (x = 0; x < l; x++) {
        int mb_len = php_mblen(str + x, (l - x));

        /* skip non-valid multibyte characters */
        if (mb_len < 0) {
            continue;
        } else if (mb_len > 1) {
            memcpy(cmd + y, str + x, mb_len);
            y += mb_len;
            x += mb_len - 1;
            continue;
        }

        switch (str[x]) {
#ifdef PHP_WIN32
        case '"':
        case '%':
            cmd[y++] = ' ';
            break;
#else
        case '\'':
            cmd[y++] = '\'';
            cmd[y++] = '\\';
            cmd[y++] = '\'';
#endif
            /* fall-through */
        default:
            cmd[y++] = str[x];
        }
    }
#ifdef PHP_WIN32
    cmd[y++] = '"';
#else
    cmd[y++] = '\'';
#endif
    cmd[y] = '\0';

    if ((estimate - y) > 4096) {
        /* realloc if the estimate was way overill
         * Arbitrary cutoff point of 4096 */
        cmd = erealloc(cmd, y + 1);
    }
    return cmd;
}
/* }}} */

Install a locale on Ubuntu 11.10

To see what locales are installed, run

locale -a

To see what locales are available for installation, run

less /usr/share/i18n/SUPPORTED

To install the en_GB locale, run

locale-gen en_GB

Tip: Leave out the charset and every charset will be installed for that locale.