Welcome to Delicate template
Header
Just another WordPress site
Header

For the Dutch version, visit my Dutch blog

Small update on the TimeMachine & Network Drive setup. Since I have a new MacPro, I wanted to enable TimeMachine on it. Note that this install is a fresh Snow Leopard installation, and that my MacBook is a Leopard.

I took the steps as I discribed them myself, but it seemed that TM was still trying to create a new sparsebundle instead of using the newly created on.

If you are using Snow Leopard, keep these things in mind:

  • The naming of the sparsebundle file needs to be a tad diffrent. No more use of the MAC address in the filename. You can just use <computername>.sparsebundle
  • One important step to follow is the fact that TimeMachine is now looking for a file called com.apple.TimeMachine.MachineID.plist
    . This file needs to reside inside the sparsebundle directory.
  • So fire up terminal and go to /Volumes/<volumename>/<computername>.sparsebundle
  • open up vi (name the file com.apple.TimeMachine.MachineID.plist and add the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.backupd.HostUUID</key>
    <string>YOURUUIDHERE</string>
</dict>
</plist>

NOTE: Replace COMPUTER UID with the UUID of your MAC. You can find it under the System Profiles on the Hardware tab. Now fire up TimeMachine and everything should be running smooth again.

One of the main reasons I switched to Mac was the fact that the user interface is polished and I still maintain the power and freedom I find Linux. But one downside in Mac Terminal is that there is no standard syntax highlighting.

So here is some info how I got to enable some basic syntax highlighting in Terminal and VIM. Note that these settings are user specific and not system wide.

Fire up Terminal and create a .vimrc file in your home directory.

cd
vim .vimrc

Edit/create /usr/share/vim/vimrc for system wide settings.

Press the ‘i‘ key to switch vim to Insertion Mode, then enter these lines
set ai                  " auto indenting
set history=100         " keep 100 lines of history
set ruler               " show the cursor position
syntax on               " syntax highlighting
set hlsearch            " highlight the last searched term
filetype plugin on      " use the file type plugins

" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif |
\ endif

Press the Escape key to take vim out of Insertion Mode, then press ‘:‘ (colon) followed by ‘x‘ to save the file and exit. Now when you list a directory or edit a file through vi(m) you’ll see that all syntaxes are highlighted.

Long live VI(M)!!

Installing MySQL on Snow Leopard

December 6th, 2009 | Posted by Michaël in ICT | Mac | Web Development - (3 Comments)

Just got my new MacPro this weekend. After installing my common applications, I had to install my develoment tools as well. These are the instructions to install MySQL 64-bit version on OS X Snow Leopard.

First of all, note that we are going to install MySQL compiling from source. So make sure you have installed Xcode tools and you know your way around Terminal ;)

Now lets set up our personal profile where we declare our path variable. Fire up Terminal and create/edit your profile file:

vi ~/.profile

Set your path variable like this:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

Close and save the file. Now load the the path variable to your current shell:

source ~/.profile

Now verify your updated path:

echo $PATH

You should see /usr/local/bin at the beginning of the line returned by the system.

Now lets download the MySQL source and start compiling like crazy :

curl -0 http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41.tar.gz/from/http://mysql.easynet.be/
 
tar xzvf mysql-5.1.41.tar.gz
cd mysql-5.1.41
CC=gcc CFLAGS="-arch x86_64 -O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-arch x86_64 -O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=myisam,innobase --with-zlib-dir=bundled --with-big-tables --with-readline
 
make
sudo make install
 
cd /usr/local/mysql
sudo ./bin/mysql_install_db --user=mysql
sudo chown -R mysql ./var

Ok, everything should be compiled and installed without problems. Now lets create the launch daemon with the following content

sudo vi /Library/LaunchDaemons/com.mysql.mysqld.plits
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
 &lt;key&gt;KeepAlive&lt;/key&gt;
 &lt;true/&gt;
 &lt;key&gt;Label&lt;/key&gt;
 &lt;string&gt;com.mysql.mysqld&lt;/string&gt;
 &lt;key&gt;Program&lt;/key&gt;
 &lt;string&gt;/usr/local/mysql/bin/mysqld_safe&lt;/string&gt;
 &lt;key&gt;RunAtLoad&lt;/key&gt;
 &lt;true/&gt;
 &lt;key&gt;UserName&lt;/key&gt;
 &lt;string&gt;mysql&lt;/string&gt;
 &lt;key&gt;WorkingDirectory&lt;/key&gt;
 &lt;string&gt;/usr/local/mysql&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;

Change the user to root.

sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist

Now, to start / stop MySQL, run the these commands:

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
 
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

Now the last thing todo is to set the root password:

mysqladmin -u root password "mypassword"

Now MySQL should be running smoothly and without problems on Snow Leopard.

NOTE: For the RoR mysql gem, use the following command:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

For love of the game

July 3rd, 2009 | Posted by Michaël in Blog | ICT - (0 Comments)

Some people tell me I’m crazy for working most of the time. Running my own small company and working a full time job. Sometimes, I have to admit they are right. When I sit in front of my computer I totally lose sense of time. I just get wrapped up in problems that need to be solved and trying to absorb more knowledge. For some, that might be geeky, for me its fulfilling and a way to earn more respect amongst my pears.

But lately I’ve been struggling with some ideas. It’s almost 4 years since I started my own business during college and I’m still operating on the same level. Business is growing but not in a noticeable way. I’m still a strong believer that you don’t have to start a business by just quitting your daytime job  and giving yourself a tight deadline to make you project work.

You can still succeed by working on your project at the beginning or the end of the day. Instead of getting up at 8, get up at 7. Instead of sleeping in during the weekends ’till noon, wake up at 9. Instead of hanging in front of the tv during the evening, get some work done. And instead of going to sleep at 10, go to bed at 11. I know it might sound crazy, but getting those few extra hours really give you the chance to accomplish more in one day then you might think. So why am I unable to accomplish my own goals?

Having a day time job also comes with responsibilities. The more you get involved to more responsibility you have to take, the more responsibility you have to take, the heavier your workload.
But thats not all. Before you can accomplish your goal you need one thing: ideas. Not that don’t have any ideas, on the contrary. At this point, I started working on 4 projects, witch isn’t really healthy. As a result of working on 4 different projects at the same time, work goes slower then it would when you would work on 1 project.(I even put one project in the fridge and considering starting it all over again with a whole new concept).

Working on one project at a time gives you the possibility to finish your project quicker and get it launched on a first draft. People would get to know you project and give feedback. In the meantime when you are waiting for feedback, you can just start working on the second one, and so on.

Guess I need to take a few steps back and just reflect a bit more on what I want to achieve. I have to admit, I’ve been working like crazy the past year, but I just can’t help it. Trying to accomplish great things often comes with sacrifices  (to some degree of course)  and you can only accomplish them when you feel really passionate about what you do.

So the next step will be thinking about a new strategy to get back on top of things!

Time Machine & Network Drive.

June 22nd, 2009 | Posted by Michaël in Mac - (34 Comments)

For the Dutch version, visit my Dutch blog

NOTE: SMALL UPDATE FOR SNOW LEOPARD USERS. KEEP THIS UPDATE NEXT TO THIS POST

Just bought a network disk last week to backup some stuff on from my dads computer. But instead of buying a normal external USB drive, I decided to buy a network drive so I could use it myself.

After some research I choose for the Lacie Network Drive. It has a simple web interface for configuration purposes and it’s accessible through AFP, SMB and FTP.

For Windows/Linux users, SMB would be enough, but since I work on a Mac, I needed the AFP protocol.
Leopard is a great OS and it has many great features. One of it is Time Machine. Time machine takes hourly snapshots of your disk and lets you browse through your backup history to recover lost files.

By default, Time Machine only backups to external drives connected trough USB. But I found out it’s pritty easy to let it automatically backup to a network drive.

First, enable unsupported volumes in Time Machine. This can be done by opening Terminal and enter the following command:

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Now when you want to select a disk, your network drive should show up in the list. But that’s not all. For some reason, Time Machine is unable to create the initial sparcebundle. Well, it actualy starts creating it, but during the process, it just fails. So, we just create it ourselfs.
Go to Disk Utilities and click on “New Image” with the following settings:

  1. Save As ComputerName_MACAddress (some say you can choose the name yourself, but I didn’t want to take any chanses.
  2. Change partition to “No Partition Map”
  3. Change Image Format to “Sparce Bundle Disk Image”
  4. Custom Volume size. Set the maximum you want to use on your remote location. Don’t worry if you don’t have the room on your Mac. Sparce Bundle Disk Images grow in size dynamically.
  5. Create it and move this file to your network drive.

Now, go to the Time Machine interface again and tell it to start backing up. Now Time Machine should start backup your stuff to your network drive. It should even do so every hour automatically. When you are on location, and Time Machine can’t access you drive, you won’t get any errors. It will just retry every hour.

You might find posts where people say that backing up on unsupported drives is a stupid idea and it is unreliable, but untill today, I haven’t found any problems. I even recovered a few files for testing and it worked perfectly. But even so, don’t shoot me if something goes wrong.

I just had one small problem when my router assigned a new IP to the network drive. Time Machine didn’t seem to find the drive anymore even when it was showing up in Finder. So I just fixed the problem by assigning the IP myself (not through DHCP anymore) and problem solved.

bash: /bin/rm: Argument list too long

December 28th, 2008 | Posted by Michaël in ICT - (0 Comments)

Today, I needed to empty a folder on my Linux server that containted a lot of files. The files where maybe 2kb, but all the files together contained over 400Mb.

So I used rm * to remove them, but it threw me a nice error: bash: /bin/rm: Argument list too long . Looks like rm has its limits :)

Use ‘find’ to pipe all the matching files to ‘rm’, one at a time:

find . -name '*' | xargs rm

And I’m a happy camper again.

Finally, I found a nice solution for the RoR 2.2 MySQL problem. The initial problem was that the MySQL library isn’t bundled with RoR anymore, and you need to install it as a gem. No big deal at first, but we Leopard users are “plagued” with the fact that Apple has somewhat of an exotic installation method of web programming.

The stock MySQL and Apache are both 64bit, but the Ruby interpreter is 32 bit. That’s why you can’t use the 32 or 64 bit MySQL library gem. I found a lot of “idea’s” on the net, but none of them helped out, or I didn’t think they where good enough.

One of them was to run a second MySQL instance on 32bit. A lot of users solved  that way but I found it just stupid running 2 MySQL instances. So then it struck me, why not recompiling the stock MySQL as a universal build that supports both 32 and 64 bit?

So I did. I downloaded the source from the MySQL website and compiled it like this:

MACOSX_DEPLOYMENT_TARGET=10.5 \
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 \
'--disable-dependency-tracking' \
'--prefix=/usr/local/mysql' \
'--localstatedir=/usr/local/mysql/data' \
'--libexecdir=/usr/local/mysql/bin' \
'--with-comment=MySQL Community Server (GPL)' \
'--enable-thread-safe-client' \
'--enable-local-infile' \
'--enable-shared' \
'--with-zlib-dir=bundled' \
'--with-big-tables' \
--with-readline \
'--without-docs' \
'--with-plugins=myisam,innobase'

And my problem was solved. I had one MySQL instance running, and I finally could use RoR 2.2.

Now the only problem remaining is getting PHP to run properly.

Mac, though love

December 19th, 2008 | Posted by Michaël in ICT | Mac | Ruby On Rails | Web Development - (0 Comments)

I recently made the switch to mac. I just love working with it. But I’m experiencing some downsides to it. This is probably due to lack of knowledge about Mac.

Like most of you know, I’m in the web development business. So I need PHP and Ruby on Rails.

I was happy to notice that PHP en RoR where installed by default on Leopard. But then I needed MySQL PDO. Hmm, the default PHP installation doesn’t support MySQL PDO. So I need to recompile. So I downloaded the PHP source and tried to recompile it with almost the same parameters I found of my previous installation. But still no go. I just gave up at the moment.

Then next thing happend. RoR 2.2 came out. So I wanted to upgrade. I upgrade an old experimental app and tried to run it. Oops, looks like RoR doesn’t ship anymore with mysql library. After a quick google, I noticed I had to install the mysql 2.7 gem.

Ok, that’s easy. Tried to install it, but ran into errors. So after some more googling I saw that other mac users ran into the same problem and various solutions where found. But, none of them worked for me. Well, I didn’t tried them all. Some of the solutions mentioned installing both 64 and 32 bit version of MySQL. Well, I just like to run a clean system and not messing with diffrent installations.

I googled a lot lately but still didn’t found a solution for both of my problems. So if any of you readers might have found a solution to help me out, please do share.

I got some nice emails conserning my restful search and the Object-oriented approach to ActiveRecord posts.

But a few of those mails had another thing in common. Some users find all the finder classes in the helper folder overwhelming, and they don’t like having them in the same folder as their view helpers.

Well, the thing you can do, is put all the finder classes in a subfolder. Lets call the subfolder “finders”, just for the fun of it :p.

Now Rails won’t load those finders anymore, since it won’t recognize your newly created subfolder. So open your environment.rb file and paste in the following code:

  Dir.glob("#{RAILS_ROOT}/app/helpers/*[^(.rb|.ignore)]").each{|dir| config.load_paths << dir }

This will tell Rails to load all files and folders in the helpers folder, that don't contain .rb or .ignore in its name.

So all the view helpers won't get loaded again, and if you have a subfolder that you don't need to be loaded anymore in your helpers folder, but still want the code, you can just rename the folder.

So I hope this might help you guys keeping your application clean. Offcoure you can also use this on other subfolders you might want to create ;)

RESTful search

July 31st, 2008 | Posted by Michaël in ICT | Ruby On Rails | Web Development - (1 Comments)

During the development of my new project, I read a lot on the REST subject. In my opinion, it is a nice way of keeping your application clean and maintainable. But I stumbled upon a small problem when I had to implement a search for my resources.

In all the examples you find on the net, you will see how to create your basic CRUD actions in REST. So create, update and delete isn’t a problem at all. But when it came to implement a search system, you find nothing. Well, nothing is a big word, you do find posts, but all of them work diffrent.

The first thing I needed to do was to deside how I would handle the search. The first possibility is to create a new controller so it would fit in the REST filosophy. Just see the search as a resource. I didn’t realy feel right to see a search as a separate resource. I just see the search as a filter on an existing resource, so why defining the search as a resource of its own??

The next logical step was just adding a new action in my resource controller called search. But again, a new action just to search? Not a real good idea I think. Like I said before, a search is just a filter on your list, so I should be part of the index action.

So there we go. We just send our search parameters to the index action and filter our list there where it should happen.

If it was just as simple as that. You can’t just use a normal POST method form, becouse Rails will see that as create. And if I would use the GET method, all the search parameters would apear in the address bar. I know thats not a big of a deal, but I personaly think that isn’t realy clean.

But then it came to me. We live in an age where you can’t find an application without Ajax. So why not implement our search with Ajax? This way, we can send a GET request with our search parameters to the controller and rebuild our list without having to reload the hole page.

Some readers might think, building your search in the index action will make your index action look ugly. Well, for those readers, check out my previous post on building your query string dynamically in an object-oriented way with ActiveRecord.

As far as I know, this is the cleanest way to implement a search the RESTful way. But ofcourse, this is just my vision on the subject, and other developers will say you HAVE to create a separate controller. But if you think like me, and can’t comprehend why a search is a separate resource, my filosophy will be a nice way to follow.

If you have some input or improvements, please do share them :)