The Secret’s Secret

Disclaimer: This post is not unbiased. It strongly reflects my beliefs, biases and the way I think.

To put it succinctly The Secret is a new-age-pseudo-scientific-pseudo-philosophical-delusional-self-help crap delivered to you in the form of DVD, book, audiotape and God knows what else.

More detailed version? Okay.

The Secret by Rhonda Byrne has been among the bestsellers for last three years. And what is it? Lets get it straight from the blurb:

It has been passed down through the ages, highly coveted, hidden, lost stolen and bought for vast sums of money. This centuries-old Secret has been understood by some of the most prominent people in history: Plato, Galileo, Beethoven, Edison, Carnegie, Einstein - along with other inventors, theologians, scientists, and great thinkers. Now The Secret is being revealed to the world.
"As you learn The Secret, you will come to know how you can have, be, or do anything you want. You will come to know who you really are, You will come to know the true magnificence that awaits you in life."

According to The Secret, there exists a wonderful law called The Law of Attraction that says attracts like, so when you think a thought, you are also attracting like thoughts to you. Now there is nothing wrong with this law and in fact a lot of research has shown the positive thinking does have a positive effect on the outcomes. So how do you reap benefits from the law of attraction? Byrne claims that the universe is like a Jeanie and all you need to do is think positive thoughts and they will be transformed into reality by the Jeanie. Here are the steps:

Step 1: ASK

The first step is to ask. Make a command to the Universe. Let the
Universe know what you want. The Universe responds to your
thoughts

Step 2: BELIEVE

Step two is believe. Believe that it’s already yours. Have what
I love to call unwavering faith. Believing in the unseen.

Step 3: RECIEVE

Step three, and the final step in the process, is to receive.
Begin to feel wonderful about it. Feel the way you Will feel
once it arrives. Feel it now.

From Chapter 3, How to Use The Secret

So these are the three steps. Apparently you don’t need to take any action to receive what you ask for. It will come to you, the universe will conspire; remember the Jeanie. Interestingly enough the above three steps are called The Creative Process with no creation step anywhere.

Another big claim is that great thinkers and inventors like Galileo, Einstein, etc. used this Law of Attraction to achieve what they achieved. I had a hard time imagining Galileo sitting in his lab waiting for the universe to conspire and arrange the lenses to form a telescope or Einstein staring at blank papers on his desk waiting for them to reveal the General Theory of Relativity.  Probably I’ll create a few theories this weekend as I have a ream of white papers on my table. I just never asked them to reveal something world-changing. Silly me.

Byrne quotes a lot of famous people out of context in support of the law of attraction. Out of context, I might also find something from pope that could be quoted on the cover of Playboy.

Now lets get down with the claims that it is scientific theory with roots in quantum mechanics(hint: NO). A scientific theory is by definition falsifiable. If you cannot prove test a theory for falsifiability, then it is not scientific. So how do you  test The Law of Attraction. You try to prove it false? Sorry, you can’t do that because if you succeed than it was by virtue of The Law of Attraction that you proved it false. After all that was what you asked in first place and the Jeanie obliged to your commands. I wonder why Gödel didn’t thought of something like this when he was working of his Incompleteness Theorem.

By the way Emily Yoffe of Slate tried to live by method described in The Secret and see what were the results.

Finally, what about the stories of thousands of people who succeeded with the help of The Secret. First I don’t think they are true and even if they are there comes the question of Survivorship bias. What is survivorship bias?  Some people sailing in the pacific they come to know that there is a hole in the ship and they all are going to die. Short of any other option after sending SOS, they prayed to God, to save them. Some people died, some survived. When asked how they survived, they answered, We prayed to God. So what about the people who died, didn’t they prayed too. But none of them was alive to tell their stories. This is survivorship bias in action.

So the conclusion, don’t read the book, don’t watch the DVD, don’t waste your commute time listening to the audio version and don’t signup on their website.

If you want something, don’t desire for it, deserve it. And how do you do that? By doing things. Surely positive thinking helps but if thinking was all that was required, Mungerilals would have been ruling the world.

And if you think I’m not open minded watch the following video and decide for yourself.

Minifying Javascript/css without changing file references in your source

Rule 10 of Steve Souders High Performance Web Sites: Minify Javascript

The most common problem faced while implemnting this is how you handle the full and minified version and how to change there reference in referencing documents. One of the easier ways to do this is to make it part of the deployment process.

Here are the relevent steps involved.

I’m using YUI Compressor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
 
#Execute this script after checking out the latest source from repository.
 
#Minify all javascript files
cd /path/to/javascript
for x in `ls *.js`
do
        java -jar /path/to/compressor/yuicompressor-2.4.2.jar -o ${x%%.*}-min.js --preserve-semi  $x
done
 
#Minfiy all css files
cd /path/to/css
for x in `ls *.css`
do
        java -jar /path/to/compressor/yuicompressor-2.4.2.jar -o ${x%%.*}-min.css  $x
done

Now you don’t want to replace all references to x.css or x.js in your development code with references to x-min.css and x-min.js respectively. So what you can do is rewrite all those filenames at the web server level.

For apache the following rewrite rules work fine:

1
2
3
4
#enable rewriting
RewriteEngine on
RewriteRule /(.*)\.js /$1-min.js
RewriteRule /(.*)\.css /$1-min.css

Caution: Remember to delete existing minified css/js file before running the minifying script or you will end up with file names like x-min-min-min.js and so on. One way to do this is to clear the js/css folder before checking out files from your source repository.

Humanizing the time difference ( in django )

django.contrib.humanize is a set of Django template filters that adds human touch to data. It provides naturalday filter that formats date to ‘yesterday’, ‘today’ or ‘tomorrow’ when applicable.

A similar requirement which the humanize pacakge does not address is to display time difference with this human touch. so here is a snippet that does so.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django import template
 
register = template.Library()
 
MOMENT = 120    # duration in seconds within which the time difference 
                # will be rendered as 'a moment ago'
 
@register.filter
def naturalTimeDifference(value):
    """
    Finds the difference between the datetime value given and now()
    and returns appropriate humanize form
    """
 
    from datetime import datetime
 
    if isinstance(value, datetime):
        delta = datetime.now() - value
        if delta.days > 6:
            return value.strftime("%b %d")                    # May 15
        if delta.days > 1:
            return value.strftime("%A")                       # Wednesday
        elif delta.days == 1:
            return 'yesterday'                                # yesterday
        elif delta.seconds > 3600:
            return str(delta.seconds / 3600 ) + ' hours ago'  # 3 hours ago
        elif delta.seconds >  MOMENT:
            return str(delta.seconds/60) + ' minutes ago'     # 29 minutes ago
        else:
            return 'a moment ago'                             # a moment ago
        return defaultfilters.date(value)
    else:
        return str(value)

Running Glassfish as a service on CentOS

Here is how you run glassfish as a service on CentOS:

  1. Create a user glassfish (you can call it anything you want) under which Glassfish will run.
    #useradd glassfish
  2. Install glassfish in /home/glassfish.
  3. Create the startup script /etc/init.d/glassifsh for glassfish.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    
    #!/bin/bash
    #
    # glassfish:          Startup script for Glassfish Application Server.
    #
    # chkconfig: 3 80 05
    # description:      Startup script for domain1 of Glassfish Application Server.
     
    GLASSFISH_HOME=/home/glassfish/glassfish;
    export GLASSFISH_HOME
     
    GLASSFISH_OWNER=glassfish;
    export GLASSFISH_OWNER
     
    start() {
            echo -n "Starting Glassfish: "
            echo "Starting Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            su $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            sleep 2
            echo "done"
    }
     
    stop() {
            echo -n "Stopping Glassfish: "
            echo "Stopping Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            su $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            echo "done"
    }
     
    # See how we were called.
    case "$1" in
            start)
                    start
                    ;;
            stop)
                    stop
                    ;;
            restart)
                    stop
                    start
                    ;;
            *)
                    echo $"Usage: glassfish {start|stop|restart}"
                    exit
    esac
  4. Install the service
    #chmod +x /etc/init.d/glassfish
    #chkconfig -add glassfish
    #chkconfig --level 3 glassfish on
  5. Start glassfish.
    #/etc/init.d/glassfish start

Embedding flash object in Facebook Apps (FBML)

Yesterday I was trying to include a flash object in a facebook app using FBML fb:swf tag. The flash object needed to change the url of the page it was running on on a particular event. But since facebook prevents direct script access from flash, this could not be done.

Here is a simple workaround:

1. Create a simple html page containing only the flash object that you want to include.

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   </head>
   <body>
   	<object type="application/x-shockwave-flash" data="foo.swf" width="300" height="300">
   		<param name="movie" value="foo.swf">
         	<param name="quality" value="high">
         	<param name="scale" value="noscale">
         	<param name="salign" value="LT">
         	<param name="menu" value="false">
    	</object>
    </body>
</html>

2. Embed this html on the facebook page using the fb:iframe tag.

<fb:iframe src="http://anandnalya.com/foo.html" width="300" height="300" frameborder="0" scrolling="no"></fb:iframe>

Now you can make all the Actionscript calls you want to. Only caveat to this approach is that you will no longer be able to make Facebook API calls directly from flash.

Anand Nalya’s Blog