Monday, October 12, 2009

"We Have to Improve Communication" - Part I

Have you ever heard that phrase, upon a team review, a company review, a post-mortem meeting, etc...? I bet you have; When looking at the root cause of a problem or series of problems, (ok areas of opportunity or deltas if you prefer) this phrase features inevitably.

And then a question automatically pops out of my mind. Ok, so "We Have to Improve Communication". But HOW?

I don't have an idea of how. Why? Because I learned to communicate by intuition, by day-to-day social interaction. So for me this is so obvious I did never mind looking deeper at what communication means, nor that it has a structure, and that rules have to be established and shared in order to make it work. I didn't realize that words or letters by themselves mean nothing, that COMMUNICATION = ACTION; the way I communicate is the way things will be executed.

It has a direct effect on the results. Yes, I'm talking about verbal communication.

Even when they say verbal communication weights as little as 7% on delivering a message, the "what we say", knowing how to structure it, becomes the most important part of the "how we say it", the other 93% that goes along with the body language, voice tone, rhythm, tonality, etc...

Bear in mind nowadays in business, technology had made us more practical, more impersonal, and most of our communication occurs first through e-mail or documentation, then by phone, and at last by personal contact.

I didn't realize either that knowing HOW TO COMMUNICATE is the most powerful weapon I have to make things happen, and it provides added value to any team I work along with.

Effective communication is the cornerstone of any task, any project, any human interaction. It is the main driver to success, and to make my way along to get what I want.

I have to thank Softtek for helping me realize it, particularly Emilio Rojas, may he rest in peace, for his valuable two days course "Communication for Action". This is a course in which I learned so much, and it was just so simple.

And also have to thank Infosys for providing me the Business Writing Skills course.

I feel that knowing how to communicate is a MUST for any leader, manager, director to be efficient, yet I don't see many of them applying this knowledge. Why? Because learning how to communicate seems to be a waste of time, and even an offense: I already know how to ask for things, how to praise, how to reprehend, how to inaugurate, how to close, how to feedback, how to express my thoughts...

Give it a second thought. Let me give you a sample of how I realized I didn't know how to communicate effectively. The first thing I learned on Emilio's course was the most important, ask yourself:

Do I take ownership of my thoughts? Do I take responsibility of what I say?

At the course there was this little, inflatable plastic smiley called "One". You may also call it "We" sometimes. Emilio established the rules of the course and said: "I introduce you to One, an inert being made out of plastic and air".

Ok, yeah, so?

Let me ask you my reader your opinion about anything, let's say: Have you ever been so stressed out you treat people so badly that you later regret? Why did you do it?

Think of an answer before continuing, as if I was in front of you.

...

Ready?

Ok now think: How many times did you use the "One" or "We" pronouns? Like in: "Well, you know sometimes One is just so filled up with such pressure One lets it go inadvertently." or "Well, I mean we may be under so much stress sometimes and don't think about what we do, but people understand we are just under stress".

Well, if you said "One", let me introduce you to him: it is an inert being made out of plastic and air. And I don't think One has an opinion, do you?

If you said "We", let me ask you, what do you mean by "We"? Because if you ask me, I may disagree. And maybe someone in Asia won't either. Or any other reader of this post.

It was so annoying to be constantly interrupted by Emilio during the course whenever I said "One", or "We" or "Them". But it made me realize how badly I was used to not taking ownership nor responsibility on my thoughts.

Using "One" as a pronoun may seem not a big deal, but try it. It was so hard for me. If this was not a big deal, why was it so hard for me to avoid being indirect when expressing my thoughts an opinions?

This is deep, this is profound. I see it coming from a rooted thought or assumption that the world as I see it, is the world everyone else sees. That what I think must be what everyone else thinks.

This is automatically blocking my disposition to LISTEN, and puts me as a Proposer, never a Listener.

How can I achieve understanding, or get to an agreement, if I can't even take ownership of my thoughts, hence I am predisposed to reject a different opinion? I'm closed to diversity!

I will be posting about communication, about what I've learned. Next post will be about how to ask for things.

On the meantime, try avoiding "One", see how it works for you.

Tuesday, September 15, 2009

Credo Mexicano (Mexican Creed)

by Ricardo López Mendez

This poem from 1940 still reflects the essence and feelings of our Mexican culture and feeling. It's too deep and I share it with you. I'll try to translate on a later time, for now, let's enjoy the holidays. =) ¡QUE VIVA MÉXICO, CABRONEEES!

México, creo en ti,
como en el vértice de un juramento.
Tú hueles a tragedia, tierra mía,
y sin embargo ríes demasiado,
acaso porque sabes que la risa
es la envoltura de un dolor callado.

México, creo en ti,
sin que te represente en una forma
porque te llevo dentro, sin que sepa
lo que tú eres en mí; pero presiento
que mucho te pareces a mi alma,
que sé que existe, pero no la veo.

México, creo en ti,
en el vuelo sutil de tus canciones
que nacen porque sí, en la plegaria
que yo aprendí para llamarte Patria:
algo que es mío en mí como tu sombra,
que se tiende con vida sobre el mapa.

México, creo en ti,
en forma tal que tienes de mi amada
la promesa y el beso que son míos,
sin que sepa por qué se me entregaron:
no sé si por ser bueno o por ser malo
o porque del perdón nazca el milagro.

México, creo en ti
sin preocuparme el oro de tu entraña:
es bastante la vida de tu barro
que refresca lo claro de las aguas
en el jarro que llora por los poros
la opresión de la carne de tu raza.

México, creo en ti,
porque creyendo te me vuelves ansia
y castidad y celo y esperanza.
Si yo conozco el cielo, es por tu cielo,
si conozco el dolor, es por tus lágrimas
que están en mí aprendiendo a ser lloradas.

México, creo en ti,
en tus cosechas de milagrerías
que sólo son deseo en las palabras.
Te consagras de auroras que te cantan
¡y todo el bosque se te vuelve carne!,
¡y todo el hombre se te vuelve selva!

México, creo en ti,
porque nací de ti, como la flama
es compendio del fuego y de la brasa;
porque me puse a meditar que existes
en el sueño y materia que me forman
y en el delirio de escalar montañas.

México, creo en ti,
porque escribes tu nombre con la equis,
que algo tiene de cruz y de calvario;
porque el águila brava de tu escudo
se divierte jugando a los volados
con la vida y, a veces, con la muerte.

México, creo en ti,
como creo en los clavos que te sangran,
en las espinas que hay en tu corona,
y en el mar que te aprieta la cintura
para que tomes en la forma humana
hechura de sirena en las espumas.

México, creo en ti,
porque si no creyera que eres mío
el propio corazón me lo gritara
y te arrebataría con mis brazos
a todo intento de volverte ajeno
sintiendo que a mí mismo me salvava.

México, creo en ti,
porque eres el alto de mi marcha
y el punto de partida de mi impulso.
¡Mi creo, Patria, tiene que ser tuyo,
como la voz que salva y como el ancla...!

Monday, April 13, 2009

Making File Uploads Work in IE6 and 7

So, I'm developing a web application at home with Linux OS and Firefox web browser. Then I deploy it on a Windows OS and a IE Web Browser.

...

Yeah I know how dumb and risky it sounds, problem is I can't afford a new computer right now, so I use Ubuntu 8.10 for developing, and the target server for my developed web app is Windows.

You know cross-browser compatibility is always a headache, and this it's all true for File Uploads.

I use PHP, and for some reason, the file upload feature wouldn't work in IE Browser. WHYYYY!!

I spent almost 3 hours on forums and finally found the reason: ENCTYPE. All file upload features warn you: You have to change your form enctype attribute to "multipart/form-data" in order that the file input contents can travel through the request.

Well... I DO! SO WHAT'S WROONG?!!

As I use an admin page with header, left navigation pane and content areas, I use the same form for several different features. And I have a feature which uploads files.

Hence, I dynamically change the ENCTYPE attribute through javascript. And after hours of trying to explain myself "why in the world is this not working if I'm doing everything right", and just before I start blaming the elves or believing I was coursed, I found this page: http://www.talkphp.com/javascript-ajax-e4x/1176-form-enctype-internet-explorer.html

It turns to be that for Internet Explorer, the W3C STANDARD enctype attribute is NOT ENOUGH. I have to set this particular ENCODING attribute as well, so my code ended up like this:

form.enctype = "multipart/form-data";
form.encoding = "multipart/form-data";
form.submit();

Yeah, I addded the form.encoding=... line and it worked perfectly.

Thanks Wildhoney @ talkphp forum!

Now I am compelled to spread the words of wisdom to all you programmers that have lost hope. No, you're not cursed, you just didn't know.

PS. Yes, my writing style today is a little bit crazy, that's what's left of an stressed mind after 3 hours of trying to find a logical reason to an error that shouldn't be there in the first time. Now I'll take some rest and no more coffee for me.

GREETINGS!

Saturday, April 4, 2009

Overcoming AJaX UTF-8 Encoding Limitation (in PHP)

I've been learning a lot about PHP, MySQL programming through a project I've been working on for 2 months.

I didn't know AJaX, actually. And when I find any challenge that takes time and a lot of headaches to overcome, I share the solution for the sake of saving people some time and bad moments.

My web application is in Spanish (latin american characters), and I use AJaX to show search results paginated, in order to make it simpler and faster to go through the results, sort them, etc...

And the results include words in Spanish, containing characters not supported in UTF-8, AJaX won't show those characters correctly.

And no, there's no way, so far I've researched, to change the UTF-8 character set for the XMLHttpRequest object; setRequestHeader("Content-Type", "...; charset=ISO...") won't work.

Some pages say you may encode the URI you are sending, and decode the responseText and you're all set. I assume encoding the URI applies when using GET method, or when using non-UTF-8 characters in the parameter values, but not to make the responseText UTF-8 compliant. I can't decode a responseText that was never encoded. And I wasn't able to decode the responseText when assigning it to the containing element.

So I finally found the solution on a web page, much simpler than what I would imagine: encode the string representing the HTML string at the server-side to UTF-8 before returning it.

In PHP, it's like this:

$html = "... all my html response text here ...";
echo(utf8_encode($html));

or whatever way you decide to do it, the fact is, encode the response text with ut8_encode() before printing it or returning it.

Also, very important, make sure the HTML page receiving the responseText has the appropriate character encoding.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I assume it'll work pretty much the same way on other programming languages; simply encode the response text server side before responding, and make sure the receiving page character set is utf-8.

Hope it is helpful for anyone.

Greetings!

Tuesday, February 17, 2009

Correct Installation Steps for XAMPP 1.7 on Ubuntu Linux

So, for my freelance projects, I have to learn PHP, and use MySQL as database.

I have an Ubuntu 8.10 Linux distribution, and the best tool available for developing web apps with PHP and MySQL is XAMPP (formerly LAMPP: Linux, Apache web server, MySQL database engine, PHP programming language, PERL scripting language)

XAMPP is basically a set of tools well-packed to run altogether. It is called now XAMPP and not LAMPP because it is available to all operating systems, not only Linux.

Usually the best way to install a software in Linux is to get the debian package installation, (.deb file, this is because Ubuntu is built over Debian distribution) but for XAMPP there's nota debian package; there's a self-contained .tar.gz file (like a .zip file for windows users) with a folder called lampp that includes all tools embedded.

There's a comprehensive installation manual on the XAMPP pages for installing and setting it up, however, it doesn't include some minor changes that are required in order for some included XAMPP tools (such as MySQL) to work well.

After installing XAMPP do the following:

1.- For XAMPP web page to run: give proper read/write permissions to 'others' on the lang.tmp file at /opt/lampp/htdocs/xampp folder; go to the folder and execute the following command as root user:

#chmod 666 lang.tmp

2.- For MySQL correct execution: provide read/write/execute permissions over the var folder and all its contents. As I hadn't identified the right user, I assigned it to everyone. Go to the /opt/lampp/ folder and type:

#chmod -R 777 var

I've spent HOURS figuring out in error logs and forums for the right answers. I don't even want to list all of the errors I've faced. This should solve any of your installation problems on Ubuntu 8.10 and basically any Linux distribution.

Greetings!

Tuesday, January 13, 2009

Basic Java Thread Exercises

Was this helpful for you? Please take a little time to comment on the exercises and solutions after you've used them, I'd like feedback from you. Thanks! =)

UPDATE 12/03/20011: Fixed broken download links


Thread Race
Thread Relay Race

Assassin Thread Slayer

BASIC JAVA THREAD EXERCISES

This brief, simple tutorial assumes you already know the basic use of OOP in Java language.

Basic Theory Background - What is a thread?

I like to take the approach form the Operating Systems perspective, where a thread defines a single execution unit in a process, being a process an instance of a program in a multitasking environment.

Meaning, for example, when I run my internet browser, it is a process, and each separate browsing window tab inside that browser is a thread.

Threads, ideally, are independent execution units; they don't depend on others to execute, and a process can go on separately from the thread.

However, this would work fine in a multi-processing environment, like in a server with several CPU's. Most operating systems are multi-tasking, meaning they emulate this multi-processing by reserving time slots and resources alternately for each process, and as the CPU clock speed is high, it is transparent for the user.

Think about your computer now: you probably have this browser window open and also maybe your personal messenger, and maybe playing some music. Well they are executing alternately in the background, but for you as a user it's seamless.

And even in a multi-processing environment, threads may be having access to a resource another thread may be using, and this can cause what is called a deadlock; when neither thread can have access to a resource.

Imagine for example me and my brother want to wash our cars, and there's only one bucket and one sponge. Let's say I got the sponge and my brother the bucket: I won't be able to start washing my car because I'm waiting for the bucket, but my brother won't give it away because he's waiting for the sponge, so we're both just standing there looking at each other to see who releases his item first, but no one does, and I'm late for my date =(

If we were an harmonious family, we'd agree to share both alternately; he'll be using the bucket and sponge while I'm removing the soap from the part of the car I've washed and dry it, and then ask him for the bucket and sponge when done and he'll dry his part of the car and then ask me for the bucket when done and so on... and I'll be on time for my date with a shining car =D

What I mean is that when we program threads, we must consider these possibilities and provide our classes with a mechanism to manage shared resources. Java itself includes several synchronization methods for that purpose.

EXERCISES SECTION

The purpose of this post is to provide exercises that will help practice a basic implementation of threads. Here we'll present the problem and guide through the solution from a design approach, the implementation is up to you, and that's what these exercises are about: use what you've learned about threads implementation in Java for coding the solution. Good luck with your self-assessment exams! :-)

Exercise 1 - Thread Subclassing Vs Runnable Implementation - The Thread Race.

I wanted to make an interesting experiment: is it true that threads run independently, and that in multi-tasking environments each execution unit is given a time slot based on certain algorithms? What will happen if I made a thread race, let's say 10 threads... will the first one being run will finish first, or are they completely asynchronous and independent?

Let's make a thread race program, where a ThreadRace class will create an instance of 10 ThreadRaceCompetitor's. Then it'll run them all. There will be a results class called ThreadRaceContext, which will keep the scorecard of who finished in which place.

When a ThreadCompetitor finishes the race, it will have to inform the ThreadRaceContext his race number, and that it's done, so the ThreadRaceContext will inform about its arrival. Who'll arrive first? Make your bets!


Design challenges: The ThreadRaceContext object is a common resource for all ThreadCompetitor's. How can I make sure it keeps an accurate record of each of their positions at the race?

How should I implement the solution of I extended from Thread rather than implementing the Runnable() interface? What will the difference be? How would the ThreadRace class control each of the threads execution?

Reference for solving this exercise.

Exercise 2 - Synchronizing the Threads Through the join() Method - The ThreadRelayRace

Now let's make the Thread Race even more interesting: let's make it a ThreadRelayRace, in which the competition will occur between 10 ThreadRelayRaceTeam's, each of them composed of 4 ThreadCompetitor's.

Now the ThreadCompetitors will have a thread number and a team number, and the ThreadRaceContext will inform when a ThreadRaceCompetitor from a team finished, and then the whole team finishes, informing the results of the team's positions.



Design challenges: Did you make the previous classes reusable? How would I redesign the ThreadRaceCompetitor and the ThreadRaceContext to comply with these changes?

Now the ThreadRace will start running the ThreadRelayRaceTeam, and the ThreadRelayRaceTeam will start running its ThreadRaceCompetitor #1. How can I ensure the ThreadRaceCompetitor #1 starts and then follows #2 using the join() method?

Reference for solving this exercise.

Exercise 3 - Reserving a Shared Resource Using the interrupt() Method - The Assassin Threads Slayer.

So I decided to make an experiment in which I want to see that will happen if I place 10 AssasinThread's in a ThreadSlayerRoom, where there's only one ThreadKillerGun? Who'll take the gun first and kill all others?

The AssasinThreadSlayer class will make sure the AssasinThreads are placed on the ThreadSlayerRoom where the fun will start when their run() method is invoked. They'll all try to get the ThreadKillerGun first, and if it's already taken, they'll say it: "Assassin 1: Oh No! Gun's Taken!"

You should be informed who takes the gun and how all AssasinThread's are being killed one by one.



Design Challenges: Who will call the interrupt for the AssasinThread's when one takes the gun? It has to be the gun.

Reference for solving this exercise.

A Reference Code Example.

A useful code example implementing all the methods included in this exercise.

Was this helpful for you? Please take a little time to comment on the exercises and solutions after you've used them, I'd like feedback from you. Thanks! =)

Regards!