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
end
def display
@statement = params[:statement]
end
end

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

Leadership

Management

People

Things

Empower

Control

Effectiveness

Efficiency

Principles

Techniques

Purpose

Method

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

(People-Oriented)

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 2.10.0.2). 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.

Slayer