Twitter updates. My Twitter user is bojicas. Follow me!

Silviu D. Bojica (bojicas)
Follow me!

Ctags and Vim for Ruby on Rails Development

Tagging is a feature that gives vim IDE-like code browsing powers.

:help tags

A tag is an identifier that appears in a “tags” file. It is a sort of label that can be jumped to. For example: In C programs each function name can be used as a tag. The “tags” file has to be generated by a program like ctags, before the tag commands can be used.

ctags -R *

is probably the most simple usage of ctags command from the command line, issued from the root of the Rails project. The result is a file named tags which indexed all objects, so it makes easy to jump, for example, to a Ruby method definition just by using CTRL-[ shortcut anywhere in the code where that method is used.

However, ctags can be told to exclude some of the files and directories and it makes sense to ignore the .git and log directories as they do not contain useful information:

ctags -R --exclude=.git --exclude=log *

But it would be more useful if we could have access to the Rails core method definitions and documentation, as well as for the included gems. Bellow, I have included the gem directory of my default ruby (ruby-head under rvm):

ctags -R --exclude=.git --exclude=log * ~/.rvm/gems/ruby-head/*

Navigation tips:

  • :ta belongs_to jumps to belongs_to method definition
  • CTRL-] if you see a call to a method and wonder what it does, position the cursor inside the method name and hit CTRL-]
  • CTRL-T to go back from the method definition

Two other useful shortcuts: CTRL-I and CTRL-O – think of them in and out the method definition.

Navigating through a list of methods with similar names

:ta /^validates_*

will look for all method definitions that starts with the given string. By default it will jump to the first definition found, but we can do more.

Following vim commands can be used to navigate through the method definitions:

  • :ts shows the list
  • :tn goes to the next tag in that list
  • :tp goes to the previous tag in that list
  • :tf goes to the first tag of the list
  • :tl goes to the last tag of the list

Resources:

Weekend in Al Ain

Last weekend was one of those magical ones, spent with my family and a handful of friend in Al Ain.

This post wishes to be a picture story of the above mentioned trip and the two places we visited there: Al Jimi oasis and the Al Ain Zoo.

First step Al Jimi Oasis.

Bellow a picture of my daughter, my wife and myself on the shade. Sorry guys and girls from back home, I know it’s winter there with tempratures far below zero:

1001_WeekendAlAin_006.jpg

The wonders of the desert, yes we are in the middle of the desert, but mind your steps…

1001_WeekendAlAin_009.jpg

and a close-up (my friends were busy visiting & making pictures of the nearby fortress), but I got myself knees dirty, attracted by these tiny flowers…

1001_WeekendAlAin_011.jpg

Hey, here we are, waive my girls…

1001_WeekendAlAin_013.jpg

If you follow me on twitter, you may know about that crazy project of mine dailyshoot / 2010 in 365 daily shots. Today’s assignment… Quirky things often catch your eye and make for interesting art. Make a photo of something that makes you go “Hmmm” today. So here comes my first candidate…

1001_WeekendAlAin_015.jpg

Let me see if you guess. What is this? Aliens?

1001_WeekendAlAin_024.jpg

Hmmm… a door profile:

1001_WeekendAlAin_027.jpg

Well, we were into an oasis, so this is how it looks like:

1001_WeekendAlAin_030.jpg

Let me introduce you now, one of my friends, without which the story will not be complete. His name is Octavian, passionate of photography himself. Here, he is aiming that flower bush…

1001_WeekendAlAin_035.jpg

or well, not exactly, hmm… as I hear him saying: A little to the left, no… no too much, to the right, just a bit. Perfect! And now say, cheese!

1001_WeekendAlAin_037.jpg

One more shot of his…

1001_WeekendAlAin_044.jpg

Time to move on, to the next place, Al Ain Zoo, but just before reaching there we enjoyed photographing our shadows (probably candidate #2 for the hmm moment):

1001_WeekendAlAin_045.jpg

Finaly, at zoo

1001_WeekendAlAin_046.jpg

It’s time to introduce Daniel, snacking his popcorn:

1001_WeekendAlAin_060.jpg

So why go to cinema? Popcorns, berry juice, and hey … we can see Alvin, live, right here …

1001_WeekendAlAin_062.jpg

My turn to feel attracted of flowers

1001_WeekendAlAin_069.jpg

… and flowers (love ya!) …

1001_WeekendAlAin_079.jpg

Wildlife… thinking at its supper

1001_WeekendAlAin_087.jpg

couple of fences apart…

1001_WeekendAlAin_096.jpg

Panorama

1001_WeekendAlAin_103.jpg

Final shots, to remember…

1001_WeekendAlAin_106.jpg

and

1001_WeekendAlAin_109.jpg

The winner of the quirky, hmmm moment is (laughing, laughing & laughing):

1001_WeekendAlAin_112.jpg

The zoo attraction, white lions:

1001_WeekendAlAin_124.jpg

But it’s late and my daughter is… getting tired.

Many more moments to come, I warn her.

Oh, man! says she, like Swiper the fox from Dora, one of her favourite cartoons.

1001_WeekendAlAin_126.jpg

From here, the last retreat in Heritage Village, then back to Sharjah.

I hope that you like it and I could bring the smile on your face showing you this photo-story.

The last, but not the least, I would like to hear from you, be sincere if you like it or not, and also I am awaiting other crazy ideas for one-weekend adventures. Comments are open …

What Is That?

A touching short film about parents and parenting.

Bellow is the link to the blog from where I have been originally referred to this movie: http://personalgrowthmap.com/blog/

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?

W2task – screencast

This is my first attempt to create a screencast, related to my w2task.com project. Comments are welcome.

For a higher resolution version, please check W2task screencast on screencast.com.

Update. I have posted a flash version, too. Enjoy.

Banks, peanuts and donuts

[EN] Banks, peanuts and donuts – are not always a good match in my opinion. In Sharjah, I’ve recently seen such an ad for a well known bank.

If in English, selling peanuts has a meaning of selling worthless things, in Romanian, selling donuts means selling overpriced things or worse – selling lies – oops.

Knowing this, let’s see the ad, in pictures …

Other banks offering you this?

 

Other banks offering you this?

Other banks offering you this?

The sweetest thing. No problem, we’re offering … donuts (ooopss) … 

 

The sweetest thing

The sweetest thing

Nice, isn’t it? We are leaving into a cosmopolitan country and we need to take care of the way others are seeing us. One size doesn’t fit all. Be aware marketers!

 

 

[RO] Bănci, alune și gogoși – în opinia mea nu fac întotdeauna echipă bună. în Sharjah, Emiratele Arabe Unite, am văzut de curând un astfel de panou publicitar stradal al unei cunoscute bănci locale.

Dacă în engleză, expresia a vinde alune e folosită cu înțelesul de a vinde mărunțișuri, în română, a vinde gogoși echivalează cu a vinde … hai să fim direcți – a vinde minciuni - ups.

Având în minte acestea, să vedem reclama, în imagini…

Alte bănci vă oferă asta? (alune – a se citi mărunțișuri)

Other banks offering you this?

Other banks offering you this?

Nici o problemă, noi vă vindem … gogoși (ups) … 

 

The sweetest thing

The sweetest thing

Frumos, nu-i așa? Locuiesc într-o țară cosmopolită și tocmai din acest motiv trebuie să avem grijă la aparențe. O mărime nu se potrivește tuturor. Celor din lumea marketing-ului, aveți grijă!