Thursday, November 30, 2006

Thai Ordering and Development Mode vs Production Mode for Rails Apps

A while back, I wrote a little rails app for Thai food ordering at my work. My colleagues place orders using the system and then bring money to the nominated orderer of the week. Once all orders are in and paid for (this is also tracked in the app), the orderer rings up our favourite Thai restaurant (Laddas) and places the order.

I have the app running from fairly cheap shared hosting. At peak times during the ordering, I guess that they'd be 15 or so people simultaneously using the app. We've used it many times without problems. Thus, I was quite surprised and displeased (as were my colleagues), when my hosting account was suspended and we couldn't see what had been ordered this morning. A hasty email to my hosting provider revealed that my account had been suspended due to high load and "ruby flooding". They were kind enough to un-suspend my account and we completed the ordering process.

I remembered seeing something about production mode in 'environment.rb'. Some googling confirmed my hunch - in development mode, rails apps are much more resource intensive. Caching is not used, and every single file needs to be reloaded every time it is required. After changing my app to production mode, it seemed to run noticeably faster. Michael and I ran 'top' and it looked like each request used less CPU.

So, should you be in a similar situation, this is how to change your app to production mode on fast-cgi Apache shared hosting:
  1. Confirm that 'database.yml' in your app's 'config' directory has a section for production mode, and that it has up to date database connection details.
  2. Edit 'environment.rb' in your app's 'config' directory.
  3. Add this line:
         ENV['RAILS_ENV'] ||= 'production'
  4. Run 'ps -u [your_user_name]' to find if you have any 'dispatch.fgi' processes running.
  5. If so, kill all of them (they'll restart and use your new config settings).
  6. Browse to your app, it should now run faster.

Monday, November 27, 2006

Neuro Linguistic Programming - Part 2

This is the second part of my post on NLP. Part 1 is available here.

Building Rapport
To build rapport, the book recommends that you pay careful attention to the person you are speaking with and match their physical posture, expressions, breathing, movements, voice and language patterns. Whole body listening is important - this means you are curious and focused on the person you are speaking with and your language is 'you' focused, rather than 'I/me' centered.

Perceptual Positions
Perceptual positions are a way of appreciating situations from different standpoints and gaining different perspectives. 1st position is when you are in your own body - this position is good for concentrating on what you want and being assertive. 2nd position is when you imagine yourself in somebody else's shoes - good for trying to understand their perspective/actions. 3rd position is when you imagine yourself as a fly on the wall looking at the scene - good for detaching yourself emotionally and considering things logically.

Setting Anchors
Anchors are particular stimuli (eg, a touch, smell or taste) that automatically trigger a linked memory or emotion. Everyone has unconscious anchors - eg, smell of food makes you feel hungry and think of eating. However, you can set anchors for yourself which you can then call up at will to change your emotional state:
  1. Choose a state/feeling that you have experienced in your life that you want to be able to access whenever you choose.
  2. Choose an anchor - eg, touching index finger to thumb on your left hand.
  3. Recall the time when the feeling was it its strongest for you. Make sure you are seeing the memory out of your own eyes (1st position). Think about the time - what colours do you see, what do you hear, what do you feel etc.
  4. Just before your emotions peak, set the anchor and then remove it at the peak of your emotions.
  5. Shake yourself to break state, and then repeat the process several times.
  6. Test the anchor - think of something else and trigger the anchor. You should feel the emotions/state you associated with the anchor.
I had a little bit of a play with anchoring emotions. The technique seems to work at least to some extent for me. I intend to play around with it a bit more.

Friday, November 24, 2006

Neuro Linguistic Programming - Part 1

I recently finished reading "NLP at Work" by Sue Night. It was quite a nice introduction to the topic. Here's some of the more interesting bits through the filter of my interpretation.

Styles of Thought
Visual/Auditory/Feelings - from the way people speak (eg, "that sounds good"), you can guess what style of thought they prefer.

Eye Movements
The way you move your eyes is meant to reflect your thought patterns:
  • Looking up (or straight ahead defocussed) => remembering/constructing images
  • Looking sideways => remembering/constructing sounds
  • Looking down => feelings/internal dialogue

As an aside, if you're talking and somebody looks away, they are probably thinking, and you should wait till they meet your eyes again before continuing.

Empowerment thought Word Choice and Questions
Empowerment means you take responsiblity for your own experience. Resolve ambiguity and abdication of responsiblity though challenging your thoughts with questions.
  • Deletions: "They overlooked me in the recent promotions" - who are they?
  • Vague actions: "We are going to develop Joe's ability to learn" - how are we going to do that, and when?
  • Baseless comparisons: "The company is doing well" - compared to what?
  • Abstraction: "It was a difficult conversation" - who was involved, and what made it difficult?
  • Hidden opinion: "This is the right way to do it" - according to who? The speaker?
  • Generalisations: "She never listens to me" - how do you know that? Has there ever been a time when she listened to you?
  • Blame: "the company demotivates me" - how does the company demotivate you?
  • Drivers: "I want to see my friend" vs "I should see my friend". The former (driven by you) empowers and motivates, the latter (forced on you) triggers opposite feelings.
  • Assumptions: "he is fiddling with his pen => he is bored" - how does fiddling with his mean mean that he is bored? Maybe it is just his habit.
With this approach, you can untangle your beliefs. Eg,
"These presentations never go well" - Never? Has there ever been a time when one did go well? How do you determine if it went well?
"Giving these talks makes me feel stressed" - How exactly does giving the talks cause you to feel stressed? How do you want to feel?

The power of imagination
If you imagine something sufficiently strongly and sensually (when, where, sight, smell, touch, taste, sound, etc), your feelings will be similar to what they would be if it was really happening. Ie, your feeling do not differentiate between what is really happening, and what you imagine.

Hence, if you want to know how you would feel if you did X, simply imagine it in great detail and you'll find out. Similarly, if you want to achieve something, imagine what it would be like in detail and it will be as though you have already achieved it. Believe it is true, and you will act as though it is true, and then it will be easier for it to become true!

No negatives
The unconscious mind does not understand negatives. Hence, if you say "Don't worry" to yourself, you are in effect triggering the "worry" emotion.

Rewriting Memories / Modifying Perception
Bring up a memory in detail, and bring in as many senses as you can. Try changing the lighting, the background sound, the relative size of objects etc and see how you feel. If you do this enough, you can change how you feel in the memory, and how you will feel when something similar arises.

I think that this could be done mentally in real time in real situations as well by changing your perception. Eg, somebody is screaming at you. If mentally imagine yourself to be larger, and the screamer to be smaller and imagine a glass between you, you could avoid feeling overwhelmed or getting angry yourself. You could then respond in a better manner.

Beliefs of Excellence
What you believe will influence how you act. Hence, if you take on positive beliefs, you can become more friendly, productive and motivated. Similarly, negative beliefs (eg, "I can't do it") are often self-fulfilling. According to the book, the important beliefs for excellence are:
  • Each person is unique
  • Everyone makes the best choice available to them at the time
  • There is no failure, only feedback
  • Behind every behaviour is a positive intention
  • The meaning of the communication is its effect
  • There is a solution to every problem
  • The person with the most flexibility in thinking and behaviour has the best chance of succeeding
  • Mind and body are part of the same system
  • Knowledge, thought, memory and imagination are the result of sequences and combinations of ways of filtering and storing information
Presuppose that these beliefs are true for you - try them out :-)
Or go back into memory and imagine how you would have behaved differently had you had these beliefs.
Practice should make the belief become more fixed in you, and change your automatic behaviour.

Outcomes and Goals
What do I really want to achieve in 3 months/6m/1yr/3yrs, beyond..
List, prioritise and choose top 3. For each goal,
  • Imagine it with all senses - how does it feel/look/sound
  • When, where and with whom?
  • What have you got now you'd need to give up?
  • Is it worth the risk/pain? If not, chose another goal and start again.
  • If not self-maintained, chunk up ("recession to ease", ask "what's important about that?") to find the higher level need (eg, "security")
  • Ensure the outcome fits with who you are and who you want to be
  • What alternative ways are there to satisfy this need that will allow you to move towards the outcome?
  • How does having the outcome fit with the other people who are important in your life?
  • Act by dividing what you need to do into many small steps that you can work through in a real way every day or every week, potentially with time frames.
This topic is continued in Part 2.

Saturday, November 18, 2006

Wing Chun Grading

This morning I went for a grading to move from grade 3 to grade 4. I did better than I could have hoped - both passed and got a good score! New and exciting Grade 4 techniques shall be revealed to me next training :-)