Hello, I’m a web craftsman with a passion for the modern web. I build web applications and play with social services and communities.

March 30, 2010 at 9:07 pm

While developing scalable web applications you will come across memcached at some point. Memcached is a free & open source, high-performance, distributed memory object caching system.

XAMPP is great for development in a local environment but does not come with a php memcached extension preinstalled. Since there are 2 good memcached php extensions in the PECL repository (memcached and memcache) it could be as easy as installing them through XAMPPs PECL installer. Unfortunately XAMPP for Mac (1.7.3) is still compiled for 32bit and the PECL installer would create a 64bit snow leopard extension. So let’s do it manually by setting some 32bit flags…

Install memcache PHP extension (2.2.5) for XAMPP (1.7.3) under Mac OS X 10.6 Snow Leopard (10.6.2)

  1. make sure Apple Developer Tools (Xcode) are installed
  2. make sure XAMPP Developer Package is installed
  3. $ cd /tmp
  4. $ pecl download memcache
  5. $ tar xzf memcache-2.2.5.tgz
  6. $ cd memcache-2.2.5
  7. $ /Applications/XAMPP/xamppfiles/bin/phpize-5.3.1
  8. This line looks just a bit complicated because it tries to deal with architecture problems between XAMPP (compiled for 32bit) and Snow Leopard (compiles everything by default to 64bit)
    $ MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1
  9. $ make
  10. $ sudo make install
  11. change XAMPPs php.ini to load the extension: (in [Dynamic Extensions])
    extension=memcache.so

Those steps enable you to use memcached in your PHP Code. But to actually test the application and caching in your local development environment you have to start the memcached daemon. Fortunately memcached got already installed by the Mac OS X Developer Tools (Xcode).

Just go ahead and start the memcached daemon:

$ memcached -m 8 -l 127.0.0.1 -p 11211 -d

-m 8 limits memcached to use a maximum of 8MB RAM to operate

-l 127.0.0.1 -p 11211 is the ip and port to listen on

-d tells it to start as a daemon

(instead of -l and -p you can also use -s to use an unix domain socket)


March 29, 2010 at 11:22 pm

In Windows 7 (and maybe even older Windows versions) you have 3 ways of opening an image… Just double click it and it will open with the default application. right-click -> Open with… and choose an application yourself or right-click -> edit to open it in an default image editor. In Windows 7 the default applications for those menus are Image/Print Preview for opening and Paint for image editing. Now I wanted to stick with Preview for opening an image (because it’s quick) while changing the behaviour of the edit context menu to open up the file in Photoshop. There seems to be noway to do so in the usually so overloaded Windows GUI. But regedit comes in handy:

  1. Open up the registry editor: Start -> “regedit”
  2. HKEY_CLASSES_ROOT -> SystemFileAssociations -> image -> shell -> edit -> command
  3. On right hand side double click on Default and change path to “C:\Program Files\Adobe\Adobe Photoshop CS4\Photoshop.exe” “%1”

February 5, 2010 at 1:22 pm

This post is intended to be a memo for myself on the basics of the linux tool screen, which allows to have several terminal screens opened simultaneously. This comes in very handy when working on a remove server over ssh.

Starts a new screen session with session_name:

screen -S session_name

Detach the current screen session (while being in it):

Cmd + a -> d

List all screen sockets:

screen -ls

Bring a screen session back:

screen -r session_name


January 26, 2010 at 7:30 pm

iPhone Recovery ModeToday an App crashed my iPhone pretty badly. This has never happened before and was rather awkward. I was using the App normally and after I ended it and went back to the home screen, the screen went black after half a second and the phone restarted. Or better said: It tried to restart. It couldn’t get past the Apple logo and was totally stuck there. I tried restarting it several times but nothing helped. So I had no choice but restoring the phone from an backup.

Here are the steps to put your phone into Recovery Mode: (using an iPhone 3GS and iTunes 9)

  1. Plug your iPhone via the USB cable to your computer and start iTunes
  2. Press and hold the Screen-lock button and Home button simultaneously until the phone turns off and release the buttons then (in case your phone is not totally stuck like mine you can just shut it down normally by holding the screen-lock button until the red slider appears)
  3. Now press and hold the Home button immediately and wait until the phone starts and goes to Recovery Mode. While on the cable the phone does start automatically after shutting it down. So be quick to release the buttons from step 2 and move over to hold the Home Button

Now you should have the option to restore your iPhone to factory settings. After that you can choose to set the device up as a new one or restore all your personal data from an backup. Once this is done the iPhone will sync all your iTunes media back to the device.

The whole process was quite straight forward but left me without a phone for about 2 hours.


December 11, 2009 at 2:04 am

I spend the last couple of hours trying to get Ruby on Rails (2.3.5) to work with MySQL on Mac OS X 10.6 Snow Leopard. So far I have been using SQLite for Rails Development but a current project requires some MySQL specific functions. I didn’t expect things to be so rough but now everything works and I am quite happy. So happy that I decided to write it down and share it with the world.

First: What was the problem?

Since I’m coming from PHP/MySQL development I had XAMPP already installed on my system and I was hoping to use the same XAMPP-bundled MySQL Server I have been using for all my PHP projects for rails projects too. Forget it! Don’t waste your time here. You may get it to work somehow but you will run into trouble at some point since XAMPP’s MySQL is compiled in 32bit and Ruby on Snow Leopard in 64bit. So basically as soon as you have a Mac with a Core 2 Duo (or any other 64bit processor) and running 10.6 Snow Leopard you have to install a 64bit version of MySQL.

So the problem you will run into (or already ran in and that’s why you are here right now) while trying to install the mysql gem with sudo install mysql looks like this:

Building native extensions.  This could take a while…
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lmygcc… no
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

and some more I won’t bore you with.

So here comes the solution:

1. Download MySQL 5.4 beta for Mac OS X 10.5 as x86_64 version from the official MySQL website

2. Open up the downloaded .dmg and run the mysql-5.4.x-…x86_64.pkg installer, followed by the MySQLStartupItem.pkg Installer. After that you install the MySQL.prefPane which allows you to start and stop the MySQL Server comfortably from the System Preferences (for some reason the prefPane is still in 32bit but that won’t bother us now).

3. Go into terminal and install the mysqlplus gem:

sudo gem install mysqlplus

4. That’s it!

It seems a bit crazy that I spend hours figuring that out but basically the key to success is mysqlplus here. I tried all kinds of combinations with the official MySQL 5.1/5.4, XAMPP’s MySQL, MacPorts MySQL and the standart mysql gem but none worked. Sometimes I got the mysql gem to compile and install but then rails still couldn’t connect to the database… However, now it works and I’m glad things can go on!


« Newer PostsOlder Posts »