Archive for the 'Science & Technology' Category

Getting back sqlite3 to Mac OS X

For some reason, I lost my SQLite version from my Mac OS X 10.5 Leopard. I hardly suspect MonoFramework for the “damage” caused, as /usr/bin/sqlite3 has been replaced with a link to a non-existent file from MonoFramework Library.

A quick and dirty fix is to bring back the sqlite3 source and install it in the *nix fashion (configure, make, make install). For future reference, I am listing the full sequence of commands I’ve typed in Terminal:

curl http://www.sqlite.org/sqlite-3.6.14.tar.gz | tar zx
cd sqlite-3.6.14
autoconf
./configure --prefix=/usr/local
make
sudo make install
# check if SQLite is installed properly
sqlite3 --version
# 3.6.14
which sqlite3
# /usr/local/bin/sqlite3

Note the new path: prefix=/usr/local, so the CLI (command line interface) sqlite3 will be accessible via /usr/local/bin/sqlite3. As sqlite is part of the core Mac, I believe it is wise not to interfere with any of the original libraries (not only CLI).

Do you know a “cleaner”, Mac OS X like (.dmg) way to restore SQLite? Please comment.

Setting up Plone to show Dubai time

As a short introduction, Plone is an excellent content and document management system. I would not insist on its features and installation as it installs as a normal Mac OS X application. For this, you may find more visiting Plone.org website.

In exchange, I will present the issue I had with the timezone for Dubai and the workaround…

For some reason, the default Plone installation doesn’t pick the right time for Asia/Dubai.

So I googled back and forward but couldn’t find the correct answer.

In fact, those tips will work for something like Europe/Berlin (eg setting up TZ variable to Europe/Berlin), but setting up TZ environment variable to Asia/Dubai will give me something like GMT+10? Obviously wrong.

So, the workaround is to set up the TZ environment variable to something more general, like Etc/GMT+4. We don’t care about daylight saving issues, so it should work all year round.

Enough words, let me know show you some code. Let’s suppose that you downloaded version 3.2.2 from http://plone.org/products/plone for Mac OS X and used the Stand Alone installation, then, edit /Applications/Plone/zinstance/buildout.cfg file and locate the following lines under [instance] section:

# You may also control the environment variables for the instance.
environment-vars =
    PYTHON_EGG_CACHE ${buildout:directory}/var/.python-eggs

Now add the TZ environment variable to point to Etc/GMT+4:

# You may also control the environment variables for the instance.
environment-vars =
    PYTHON_EGG_CACHE ${buildout:directory}/var/.python-eggs
    TZ Etc/GMT+4

Save the file, then run from your Terminal:

cd /Applications/Plone/zinstance/
./bin/plonectl stop
./bin/buildout
./bin/plonectl start

Now, back in your favourite browser and launch http://localhost:8080/Plone.

You would see now, that Plone will report the correct time.

Bellow, let me show you a snapshot of the same blog post, edited in Plone:

Keeping session data across subdomains in Rails 2.3.2

Upgrading to Rails 2.3.2 I came across with the error of not keeping the session data between subdomains. That meant I had to authenticate each time I would change the subdomain.

The fix is simple.

Prior to version 2.3.2, I have had something like this in environments/development.rb file:

ActionController::Base.session_options[:session_domain] = '.w2task.local'

In Rails 2.3.2, I had to change this line into:

config.action_controller.session = {
  :domain => ".w2task.local"
}

Of course, same principle applies to development.rb, where:

config.action_controller.session = {
  :domain => ".w2task.com"
}

I’ve lost some hours in researching this solution, so I hope this will help others in need. too. As usual, I will be more than happy to hear comments from you.

Happy coding!


Ruby on Rails application could not be started

This is the error message, on my local machine after I upgraded to rails 2.3.2. Well, it was not an instant error, but it appeared after a while, to be more exact after I rebooted my computer.

The error:

no such file to load -- application.rb (MissingSourceFile)

As the new rails renamed application.rb to application_controller.rb, I have immediately sensed the root of the problem, so I’ve tried to

./script/server

and it worked. That means it has something to do with the Phusion Passenger.

But what? I’ve updated all the gems, and passenger was updated too.

Well, yes, but not the apache module, and not the configuration…

This is to remember: Every time, after getting a new version of Phusion Passenger via sudo gem update, I have to:

sudo passenger-install-apache2-module

and go through the setup, than edit the httpd.conf file (in my case: /private/etc/apache2/httpd.conf) and replace the old passenger configuration lines with these new ones:

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.1.3
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Last step is, of course, to restart the apache server:

sudo apachectl restart

Now we are set to go.

I have post this article as a reminder to myself in case something similar would happen in future, and as well I hope to be useful to the readers of my blog whom might struggle with the same type of issues.

For any other tips and comments, it would be a pleasure to see you replying to this post.

Coding is fun!

The Gimp-Reflection Plugin Screencast

The gimp-reflection plugin extends the lower section of an image as a reflection of the original image with a single click, similar effects to what you see on Apple’s website, iWeb, etc.

This screencast shows you how to download, install and use the gimp-reflection plugin. Enjoy!

Example:

The original image:
photo-19

The result, after the one-click reflection filter is applied:
photo-19-gr

Easy, isn’t it?

Ruby on Rails – Tools I Use

Going with the hype, I am coding in Ruby on Rails and exclusively on a Mac.

As a text editor I am using TextMate. It was love at first sight (although shared) – I know, we are talking about community here. But as many of us, I would like to see more often updates and at once that pending version 2. It is something there which says that a version increment will make us much more happy. I have a feeling it is loosing slowly its vibe. For instance: Peepcode is releasing a screencast episode about Emacs, and I am also seeing more and more blogs talking about switching to either Emacs (Carbon or Aqua) or to MacVim.

CSSEdit 2 is filling my coding gear and it helps a lot in cleaning my templates. I am a dirty hand coder in the way I am using quite often something like <div style=” …. “> directly into my code, pushing only at the end for what I need to a style sheet.

I discovered git once with Rails and since it became my right hand in versioning. I never believed it can be so easy, doesn’t matter if you are online or offline, you are alone or working along with a team. More, I agree it is more productive to have that infinite hexa number instead of 1, 2, etc as your file/project version number, because you just code, don’t tend to compare. And because I love luxury, I am using a micro account with github. Yes, I have my own secrets there, too ;)

Ticketing and organizing my staff – I am into a personal level with the lighthouse. And the Lighthouse Keeper is giving me enough support whilst offline.

What about you?

Coding Aloud – Restricting your users to edit other’s profile

restful_authentication plugin made its way to my projects as the “de-facto” authentication system in my Ruby on Rails projects like w2task or gistate.com. I would not insist on how to install it, as it is well explained on its home page at github.

What I want to show is that in particular instances we may not like that one user can access and modify other user’s profile. For example if I try to edit my profile, the URL will end in something like users/2/edit and if I would change it to users/1/edit then I am able to modify this user – most often an undesirable fact.

Here is my workaround:

app/controllers/users_controller.rb
  # ...
  def edit
    if params[:id].to_i == self.current_user.id
      @user = User.find(params[:id])
    else
      flash[:error] = "Not allowed!"
      redirect_back_or_default('/')
    end
  end
  # ...

That’s pretty much everything I need to change.

What is your preferred solution? Are you doing these tests into a – perhaps – before_filter?

w2task Challenge

I would like to introduce my latest project w2task - a web application written in Rails.

w2task challenge

It is a task and time management web based software. At this point, a registered user can create its own business (company) and define a series of projects. Then, the user can record its own efforts and attach them to a particular project. The sidebar (Efforts Bar) gives a quick statistic regarding the number of efforts and total timing. Also, by clicking on a particular project you may get the timesheet of the particular month.

You may well give it a try, here is the link: http://w2task.com. Don’t hesitate to tell me your opinion about it, right here as a reply to this post. You may me as harsh as you want, it is constructive and ultimately this blog is moderated :) .

Be warned, this web app is still in its early, early development stages.

To better understand the philosophy behind this application, the strength and the weaknesses of the application, allow me to tell you in few points a bit of my history with Rails:

  • January 2008 – I’ve bought my first Rails book Agile Web Development with Rails, but I didn’t have enough time to practice it that Rails, turned 2.0 and broke the compatibility with 1.x versions. I remember the headaches regarding the scaffolding, so I abandoned my Rails path.
  • May 2008 – I’ve make up my mind and bought the third edition of the above book and start again with Rails at a low pace.
  • October 2008 – my friend Hossein asked me to join in a web project with a real estate portal. I thought it is the moment to put my knowledge into practice and this his how gistate.com got wind. Ok, the real estate market is down now (dec 2008 – jan 2009), but gistate.com shines ;) .
  • November 2008 - Dubai Hacking Night – where I meet again my heroes: the SpinBits guys which encouraged me to learn Rails. I have shown to Rida a sketch of w2task (a scaffold and some CSS files) – a Ruby on Rails practicing project and he asked me to promise that I will present it on DemoCamp 4, which should be in mid January 2009.
  • December 2008 - I have closely followed 37signals blog and read their book - Getting Real. Truly inspiring, and I am thinking to copy their business model.
  • 2009 – here we are.

Wow, getting long with this post. However, for the future, I have a lot to say and I hope it will be of interest for my blog readers, as I will fly along the Rails.

DemoCamp Dubai (third edition)

The third edition of DemoCamp Dubai is now over. It was a beautiful evening, with four different presentations:

  1. Jawaker - online card games
  2. Twffaha - women recruitment portal
  3. Untiny - expand tiny urls
  4. industrials Directory - self explanatory title
For more details, I will refer to DemoCamp Dubai website.
And because we all like criticizing, please allow me adding the following comment. Rules, rules, rules … Rule #2 of DemoCamp: No powerpoints allowed. Why no .ppt ? Well, do you have working software or don’t you? But first three presentations used quite heavily the power of slides.
However, all in one… great people, great projects.

Title: Nokia E90 – How To Find its MAC Address?

Dial:

*#MAC WLAN#

or

*#62209526#