Saturday, March 31, 2007

RJS Templates for Rails

Ruby on Rails has excellent support for Ajax baked right into the framework. Remote JavaScript (RJS) templates build upon the Ajax support offered by Rails, allow to easily update multiple page elements.
This is a quick start to work with RJS.
$ rails RJS_Example

Create your controller:

RJS_Example> ruby script/generate controller Examples
exists app/controllers/
exists app/helpers/
create app/views/examples
create test/functional/
create app/controllers/examples_controller.rb
create test/functional/examples_controller_test.rb
create app/helpers/examples_helper.rb

Let's modify the default controllers now:
class ExamplesController < ApplicationController 
def index
def display
@statement = params[:statement]

Now, we should go to create our views.
Create in the $RJS_Example/app/views/examples create your index.rhtml
In the header include this tag
    <%= javascript_include_tag :defaults %>

The :defaults helps to add all the Scriptaculous visual effects and controls.

In the body, add this code.
    <%= form_remote_tag :url => { :action => 'display' },
:html => { :id => 'display-form' } %>
<%= text_field_tag 'statement', nil, :size => 40 %>
<%= submit_tag 'submit statement' %>
<%= end_form_tag %>

We use the form_remote_tag() helper instead of the form_tag().
:html option helps to reset the form after completion.
:url option specifies the controller action that receives the form data.
Finally the empty "div id=statement",The id provides a way to reference the element from the RJS template.

Create partial template app/views/examples/_example.rhtml
<%=h example %>

Create the RJS template: app/views/examples/display.rjs
page.insert_html :bottom, 'statements', :partial => 'example'
page.visual_effect :highlight, 'statements'
page.form.reset 'display-form'

The page object is an instance of the Rails JavaScriptGenerator.
the partial template app/views/examples/_example.rhtml is rendered, and the resulting content is inserted into the bottom of the statements div.

Friday, March 30, 2007

Leadership User Guide

Leadership has becoming more and more important due to the globalization and its effect on the effective workforce in market.

Who is a leader?

A leader is someone who makes things happen by:

* Knowing the objectives and having a plan to achieve them.
* Building a team committed to achieving the objectives.
* Helping each member to give his best effort.

A leader must demonstrate two active traits: expertise and empathy. Also he takes active roles in remaking the environment in productive ways.

What is Leadership?

Leadership involves cooperation and collaboration activities that can occur only in a conductive context. It is the art of influencing a body of people to follow a certain course of action; the art of controlling them, directing them and getting the best out of them. A major part of leadership is man-management.
Leadership is the capacity to translate vision into reality.

There is a different between Management and Leadership.

Leadership Vs Management













Doing the right things

Do things right

Is the ladder against the right wall??

Climbing the ladder fast.

Leadership styles.

Creation of resonance can be done in six ways, leading to Six Leadership Styles. Typically, the most effective leaders can act according to and they can even skillfully switch between the various styles, depending on the situation.(According to Daniel Goleman).

Visionary Leadership

(Transformational Leadership)

Coaching Style

Affiliative Leadership


Democratic Leadership

Pacesetting Leadership

(task oriented)

Commanding Leadership

How style builds resonance

He moves people towards shared dreams.

Connects what a person wants; with the organization's goals.

Creates harmony by connecting people to each other.

Appreciates people's input and gets commitment through participation.

Realizes challenging and exciting goals.

He decreases fear by giving clear direction in an emergency.

The impact of the style on the (business) climate

+ + +

+ +



Often ― ― when used too exclusively or poorly

Often ― ―

When style is appropriate

When changes require a new vision. Or when a clear direction is needed. Radical change.

To help competent, motivated employees to improve performance by building long-term capabilities.

To heal rifts in a team. To motivate during stressful times. Or to strengthen connections.

To build support or consensus. Or to get valuable input from employees.

To get high-quality results from a motivated and competent team. Sales.

In a grave crisis. Or with problem employees. To start an urgent organizational turnaround. Traditional military.

(to be continued....)

Globalize on Ruby-On-Rails

The Globalize is an internationalization and localization plugin for Rails application.
  • Translates both db content and view text.
  • Supports automatic selection of an alternate, localized template for each view.
  • Built-in localization and translation of strftime, numbers, and currency formats.
  • Supports pluralization.
  • All based on three automatically migrated database tables.
It is the best solution to support multi-languages for your rails application.
The globalization wiki is not yet complete. But I think the "Get Started" part is fair enough to help you out making your globalized application, it provides very helpful external links.
  1. Sven’s Globalize Writeup – has many times been refered to as “the best documentation available for Globalize” .
  2. Example Application – takes you step by step through the process of creating a Globalized example application.
  3. Unit-tested Example – a walkthrough using a test-driven approach by Josh Harvey.

Monday, March 26, 2007

New Versions of Ruby, Rails and Instant Rails

I'm happy that new versions of our cool development tools have been released. This includes Ruby, Rails and my favorite tool, Instant Rails.

Ruby 1.8.6 is a steady and reasonable enhancement of the 1.8 series including many bug and security fixes, standard library updates, feature enhancements and performance improvements keeping high backward compatibility with the previous release (1.8.5).

Rails 1.2.3 was released mainly to support Ruby 1.8.6.
Besides the 1.8.6 compatibility, we’ve included few minor fixes. Nothing major. This should be a drop-in replacement for Rails 1.2.2.” David said.
What makes that even better is Instant Rails 1.7 that upgrades to the latest versions of Ruby, Rails and even phpMyAdmin (version Another cool feature of the new Instant Rails is automatic RadRails configuration.

Now, just download Instant Rails 1.7 and enjoy the latest Ruby with the latest Rails.

Saturday, March 24, 2007

Assumptions On The Way

When I read this post of the idea when to cache...I thought, it's not just a caching problem. the cache is just a component. Hence, I think that the valid question is "'What 'to do or not to do'?".
I believe that the key to answer this question is the assumptions.
The caching is very relevant in distributed systems in general. It has many modes and many techniques.
As mentioned in the post, I agree that a cache implementation cannot increase the mail server performance. It's obvious that the relation is 1:1 between the client and his mailbox. Thus, the data is just required by only one client.
To let the wonder aside, and make a simple rule to follow on the implementation, each project should start by setting the "ASSUMPTIONS".
So, let say that from the beginning I made an assumption that each client on my system is hyperactive. My clients don't cease pressing the refresh button on their browser. This will push the designer to find a way to decrease the time response to each client (by implementing a cache layer)which can be considered as a "Selfish caching".
Another one would assume that the client are normal users, they access their mail smoothly without any problem. This system doesn't need a cache.

I will give a practical example for assumptions. When I read about GFS (Google File System) I felt something wrong, the problem was that I predicted some technical problems and I expected that GFS design is putting an assassination plan to it. But I figured out that I was completely wrong.
When i got back to the assumptions I found that the system is fair to provide a complete solution based on these assumptions. The moral is that the system's design and implementation are always relevant to the assumptions and not to a vague problem statement.
To be more specific, most of distributed Systems researches are based on a very important assumption which is, concurrent reading is always more frequent than concurrent writing.
(Once written, files are seldom modified again)

The GFS Assumptions:
  1. The system is built from many inexpensive commodity components that often fail. It must constantly monitor itself and detect, tolerate, and recover promptly from
    component failures on a routine basis.
  2. The system stores a modest number of large files. We expect a few million files, each typically 100 MB or larger in size. Multi-GB files are the common case and should be managed efficiently. Small files must be supported, but we need not optimize for them.
  3. The workloads primarily consist of two kinds of reads: large streaming reads and small random reads. In large streaming reads, individual operations typically read hundreds of KBs, more commonly 1 MB or more. Successive operations from the same client often read
    through a contiguous region of a file. A small random read typically reads a few KBs at some arbitrary offset. Performance-conscious applications often batch and sort their small reads to advance steadily through the file rather than go back and forth.
  4. The workloads also have many large, sequential writes that append data to files. Typical operation sizes are similar to those for reads. Once written, files are seldom modified again. Small writes at arbitrary positions in a file are supported but do not have to be efficient.
  5. The system must efficiently implement well-defined semantics for multiple clients that concurrently append to the same file. Our files are often used as producer-consumer queues or for many-way merging. Hundreds of producers, running one per machine, will concurrently append to a file. Atomicity with minimal synchronization overhead is essential. The file may be read later, or a consumer may be reading through the file simultaneously.
  6. High sustained bandwidth is more important than low latency. Most of our target applications place a premium on processing data in bulk at a high rate, while few have stringent response time requirements for an individual read or write.

Thursday, March 22, 2007

From Consultance to Danger

From time to time, I try to remain connected to postgraduates classes. I find pleasure to meet people there and to refresh my head with academic tones.
Among the classes, I prefer the "Advanced Web Programming" the most. Sometimes I contribute as an audit!!! It may look strange, specially that I am a new born in the web technologies world.
The course is under supervision of two professors. One of them was going to chase me out, he thought that I represent a danger to the students. "Students knowing me well can rely on me as a friendly consultant and as a knowledge resource, they are going to be lazy" he thought so.
On the contrary, the other Professor thinks that I am a good guy, giving help to my colleagues, through my business oriented experience.
the third party is the students, they want me to come every Saturday to attend the lectures with them! some of them felt guilty while I was accused by the Professor.

I really like to help as much as I can, I can't stop this. in the same time I don't like lazy people.
I have a theory about this...The students I deal with are not lazy, all wt I do is providing them the help through our conversations. When I figure out that who I am dealing with is not doing his best I start to to minimize my contribution with him.
I believe that we need to focus more on the keeping connection between different generations. Undergraduates should benefit from graduates experiences. Currently what happens is totally different; Only TAs are the ones involved with undergraduates.
Maybe I am wrong, maybe I am right. but I am convinced in what I am doing.

Wednesday, March 21, 2007

To cache or not to cache

I was sitting with a couple of friends of mine, and we were discussing scalable system performance issues, we were specifically discussing mail system performance issues, when all of a sudden, one of us said "it would be better to eliminate all system caching, then we will have better performance", Wow.. where did this come form?

Eliminating cache to boost performance? we all know that there are several system caches and buffers that stores last fetched items so that whenever someone asks for them again, the system doesn't need to go there again to fetch them, its like an intermediate faster and smaller storage with most recent viewed blocks..

Many algorithms, theories govern the best way to cache I/Os, what to cache and how much to cache, locality and other cache issues, and they all work for the well fair of decreasing the time to read data, so how come removing our friends here might enhance performance.
In our case its a mail system, with about 3 million users, meaning 3 million mail boxes.. and the read/write activities specially the I/O activities are all on the mail boxes, in matter of fact what is cached here is the user's mail box.. so how often could two users ask for the same mailbox? so the cache is almost not usable, cause everytime a user asks for his mailbox, its fetched from the HD and cached, and then another one does the same, until the cache is full and we need to remove blocks(users mailboxes) to free space, and if we are talking about thousands of visits then the possibility that a user revisits his mailbox and finds it in the cache is very low, Those copies in turn imposes the CPU and memory cost of moving the data from cache to userspace destination buffer for reads, and the other way around for writes.

At this moment i started to think of a more radical idea, why not tweak the H.D. cache too, I mean the hardware cache on the hard disk itself, or use cheapo Hard Disks with no internal caches, lets make it a cacheless system, with direct access to data without any unnecessary overheads, no need to use an intermediate zone for any reason, its a cache free world!
But then, what will be the impact of this? how could we use caching in such systems? what are the best practices, what if all of this is just wrong speculations, and that cache do make a difference even in such systems. I think we need to make some tests and benchmarks to validate what we are saying here. maybe i will work on this one day.


Monday, March 19, 2007

Erlang Review

After I got a quick look to Erlang, I started to feel a little more curios to this language, and I decided to give it a portion of my readings.
The resources of this language are limited, it is very clear that it is still in the "Early Adopter" phase. I already believe that this language can realize a very good hype very soon. Furthermore, I see it has as many advantages as the Ruby.
I won't talk about the ordinary features which anybody can figure out by himself. What I see the most important point is "Concurrent Programming" in Erlang.
Now, I think of this blog entry as a checkpoint of my digging results in the Erlang World, and not an Erlang Quick Start. this is just an entry to point to the "Erlang Status".

Erlang is a programming language designed for building highly parallel, distributed, fault-tolerant systems. It has been used commercially for many years to build massive fault-tolerant systems which run for years with minimal failures. Erlang combines ideas from the world of functional programming with techniques for building fault-tolerant systems to make a powerful language for building the massively parallel networked applications of the future.
This means that your Erlang program should run X times faster on a X core processor than on a single core processor, without changing a single line in your code. I really appreciate this flexibility. You can use this feature in a very effective way in your application.
I didn't test the Erlang by myself and test its performance, but actually I am very optimistic towards the results, given that the Erlang is heavily used on embedded systems. so, I expect that it has a good performance comparing with other technologies such as Java, Ruby..etc
frankly speaking, I didn't test the Ruby on my PDA. But I expected that the performance won't be pleasant at all. so I decided to save my time for something else. About Java, yes well, I tested it and I am not ready to do it again.
I wondered if anybody used Erlang in web applications!!! The good news I found is that there is a plan to produce a web platform for Erlang. well, there is already a web platform for Erlang but it is not open source and information about it is very limited because it was developed outside of Ericsson.
I think the Erlang consulting and Training Ltd has used an Erlang web platform. which I think a quite impressive start for the Erlang. When I think about Erlang Platform, I think of powerful concurrency handling of heavy loads (It is the Erlang nature, nothing to do with it), and I certainly remember the fault-tolerance embedded with Erlang (built-in ability to upgrade software during runtime without restarting or failure time) which is something missed in most of frameworks dominating the marketplace nowadays. This paper talks in some more details about the status of the Erlang Platform.

I hope you enjoy your Erlang programming.

Saturday, March 17, 2007

Quick look to Erlang

I started to be interested to the Erlang language. I read a little about it, and I think I may dedicate some time to it.
There is a short movie giving a quick introduction about ERLANG features.
Erlang has reached a high level of maturity in the telecoms market!!!!

Friday, March 16, 2007

Corporate Blogging

It's not about the way you spend your leisure time. Blogging or as we can call it here "Corporate Bloggings" is one of the technologies that have great potential impact on the marketplace.
The corporate-blogging is the use of online journals by employees to further company goals.

It started with nontechnology entries, but the lack of interest was a big factor of disappointments.
2005 was the peak of hype for corporate blogging. Currently it is sliding into the trough replaced by the (Social Network Analysis, Folksonomies, Speech Recognition for Mobile Devices, RSS Enterprise...)
The corporate-blog can be considered as a tool for projecting the marketing messages in a medium that has large reach and low cost. Furthermore, it creates a good opportunity to make some kind of dialogues with the market(collect feedback from the market).
Expectations are tricky in the blogging world. Although no initial efforts nor technical skills are needed for blogging, it is not easy to effectively achieve it because it requires long-term commitment and consistency.
Behind the scenes, you can expect the intelligent competition, and recruiting processes ;)

Tuesday, March 13, 2007

Web Usability

Usability is not exclusive to the web. It refers to the relationship between tools and their users, so it is applicable to practically any field. Usability is usually defined as the measure of the ease with which particular people can employ a particular tool.

Within the web development process, usability is the set of techniques used during the design of the web site in order to improve the ease of use to everybody, including those with disabilities. Web usability is based on two main principles:
  • Visitors only see what they need: Internet users don’t read in detail, they skim the web trying to find what they are really interested in. If they can’t find what they are looking for, they will leave your site.
  • Visitors are impatient: They want to access the relevant information as soon as possible. If they can’t find what they are looking for quickly, they will leave your site.
Accessibility vs Usability

Web accessibility and usability both improve satisfaction, effectiveness, and efficiency of users. But while accessibility is aimed at making the web site open to a wider user population, usability is aimed at making the target population of the web site happier, more efficient, more effective.
Accessibility covers technical issues; usability is experiential. It is about the user’s experience when accessing a web site. Usability is very much like quality: you typically notice it only when it is missing.

Usability Factors

Web usability is about making your web site in such a way that your site users can find what they're looking for quickly and efficiently. A usable web site can reap huge benefits on to your website and your business:
"A web usability redesign can increase the sales/conversion rate by 100%" (source: Jakob Nielson2)
Web usability is not just about making sure everything on the site works, but also how quickly and easily visitors are able to make use of the site. Web usability covers download time, page layout, graphics, animation, navigation, information architecture, search, etc... it can only be measured by the end user’s experience and satisfaction. Here are some examples:
  • The web site should be easy to find by search engines.
  • The web site should be quick to download.
  • The user should easily find the information he/she is looking for.
  • The services offered should be easy to access and understand.
  • The web page layout and design should be consistent throughout the site.
  • The site should has a logical structure and efficient navigation.
  • Explanations should be provided on how the site is organized.
  • The user should be able to interact with the site and provide feedback.
  • The site should offer some search features.

Thursday, March 1, 2007

Dependencies hurts..

I had an experience recently that I like to share with you..

It started a week ago, the last days of my honeymoon vacation, when i decided to check my email.. i found an email from my mother saying that she has a problem in her college..

my mother - motivated by me - has joined a PhD program.. she's a doctor.. currently making her PhD at the Institute of Public Health. She and my father are staying in KSA currently where she teaches in a girls college.

Her problem was that the PhD exam will take place on 24th of June 2007 in Alexandria. Her vacation at her workplace in KSA starts 27th of June 2007. she needed a paper that states the exam date to pass it to the people there so she can take her vacation earlier.. so we needed someone to go get that paper and send it.. i used to handle this kind of tasks.

it was supposed to be a 30-60 minutes thing, two hours max including the journey. so i thought of checking it right away, i have the car it would be easier for me to do. my brother would have done it. but he was at his work that day.. it was thursday.

i went, didn't find a lot of people due to the funeral of a professor there. the employee at Student Affairs told me there is no one to sign or seal it.. i can pass by on sunday, write a request, and get my paper directly.. i said OK and delegated it to my brother.

Sunday, my brother called, said he made the request and we can take the paper the next day morning. so i told it is ok, i can pass by early before work and take it.

Monday, it rained heavily.. all streets was jammed... the journey overhead would have been a disaster so i decided to postpone it..

Tuesday, i went there to find the paper ready. except that it did not specify the date of the exam explicitly.. i adjusted it in the request.. and it passed the person responsible on typing it on the computer again.. as an early person can expect, the person was there, the PC was off, and "el Dada betnaddaf"... i like that clean place!!!
i knew it had to be signed from the dean after that, sealed and so... so i told the employee that i'll go to my work.. and pass by later in the day to take it.. i was smart enough to take his mobile number so i can check that it was done before i make the journey again. time is valuable as u know!!

Tuesday Afternoon, i called the guy around 1pm. His phone what out of service. i decided to take my chances and go since i know they finish at 2 pm. His mobile was off till i reached there. the request was still in the computer personnel queue.. she was overwhelmed to add a "Date" to the paper..!!! i asked the guy there to push her.. and get done with all the singing and so.. and decided to take first thing next day..

Wednesday, i called the guy early morning before i go... it was typed but not signed yet.. the dean doesn't come at 9 am of course so i went directly to work.... in the middle of the day i tried calling but his mobile was off again... i miss the old land line!!!
he answered at 1:40 pm saying that it was done.. he took off... he won't be there tomorrow.. and that he left it with a colleague there.. and saying that i can go take it now... I have learned the lesson, i knew that i won't find the colleague by the time i reach there... interrupting work is a high overhead..

Thursday, i went before work... Luckily the colleague had arrived.. but she was not on her desk.. she appeared after 10 minutes... she gave my the paper, and asked me to have it sealed from the office next floor, then copied, the to bring her a copy... sealing went fine.. at the copying stage, as usual, the copying machine was not working, the guy there was trying with it.. adjusting the paper carrier, restarting it... another 10-15 minutes... then it was done..

the task consumed the time of about one and half working day (because i had experience and some communication).. was done after a week...
it is really amazing how a 2 hours estimated task can actually consume.

i had a lot of free time to think while I'm working on this... Analogies... i tried putting my self in their lazy shoes..
what if Larry was in my place and got affected and delayed because i chosed to work first on a bug that is less critical than a bug he really needs..
why do tasks tend to take so longer than they deserve?!!!
in my case... people involved didn't take it seriously enough.. they lack management.. they lack communication....

applying the same analogies... Outch!!!

the Morale of this story:
- Do not apply for PhD
- Do not motivate people to apply for PhD