»Sunday, May 11, 2008

Facebook Profile

Choosing your profile picture (from PhD Comics - extras included)




Original comic here.


Labels: , ,



...
»Friday, May 09, 2008

Ruby on Rails and mysql connection problems

If you are losing connection to mysql every so often on OSX (I'm using 10.5 Leopard), it's probably because you do not have the native C ruby-mysql bindings. If your error looks like this:
Mysql::Error: Lost connection to MySQL server during query:


then try the following. Verify that the bindings are really not present. In a terminal window, open up the interactive ruby shell and type the following commands:
irb
>> require 'mysql.bundle'
=> true
>> exit


If you do not get 'true', then you need the bindings. Back to your terminal window and type the following:
$ sudo -s
$ ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/usr/local/mysql


Try require 'mysql.bundle' again and this time you should get back true.

Sources: 1 and 2.

Labels: , , , ,



...
»Saturday, May 03, 2008

Grounds for your garden

Did you know that you can get coffee grounds for free from any Starbucks? Just walk in and ask for 'Grounds for your Garden' and you will receive a huge bag of used coffee grounds that you can use to dress up your soil. If you live in Arizona, you probably need some acidity in your soil anyway, so try it out!


...
»Monday, April 14, 2008

Aim for Fame

From Banksy's guide to cutting stencils:

Any fame is a bi-product of making something that means something. You don't go to a restaurant and order a meal because you want to have a shit.


...
»Sunday, February 10, 2008

The economy is growing... so what?

I don't think there's any way to summarize this post, so just go ahead and read it. Bloody brilliant!


...

HOWTO: Carry on a multi-lingual conversation using Google Talk

I've always been a fan of Google's language tools, especially when I'm trying to find out how to say a phrase in Spanish. Now Google has built a bot out of the tool so that you can actually chat to it using Google Talk (or any jabber client) and receive the translation in real time.

Here's how to use it: Simply add en2es@bot.talk.google.com to your friend list and chat with the bot to automatically translate from english to spanish. Google has a list of currently supported language codes, but you can always try out a code to see if it has been implemented. (The current list is ar2en, de2en, de2fr, el2en, en2ar, en2de, en2el, en2es, en2fr, en2it, en2ja, en2ko, en2nl, en2ru, en2zh, es2en, fr2de, fr2en, it2en, ja2en, ko2en, nl2en, ru2en, zh2en)

Now, let's say that you are trying to talk to a Spanish speaking person over chat and neither of you are particularly good at the other language. You carry on a perfectly usable conversation by following these steps:

1. Add en2es@bot.talk.google.com to your friends list.
2. Add the reverse, i.e. es2en@bot.talk.google.com as a friend.
3. Invite both the bots to a group chat. Also, add your spanish speaking friend to the chat.

Now, everything that is said in English will be translated to spanish by the en2es bot. Also, everything that's said in Spanish will be translated automatically by es2en. (Don't worry, there will not be any infinite loops)

This is fully scalable - add all kinds of other language bots (and the reverse bots) to have a wickedly cool group chat!

Happy chatting!

Labels: , , ,



...
»Sunday, January 06, 2008

The catch-all "World Music" category

If you have ever tried to buy Indian music from one of the popular (and legitimate) online music stores in the US, then good luck finding the albums you want. Even though Indian music has enough genres and languages to have more categories than western music, it is always relegated to the catch-all 'World Music' category.

It's understandable the stores don't normally categorize international music since the market for that in the US is probably a fraction of the market for mainstream music, but for an online store like iTunes, creating proper sub-categories for international music does not increase their operational cost. Maybe we will get properly categorized music when iTunes hits more international markets.


...
»Thursday, December 20, 2007

Xmas for the child of an engineer

I got this in a forwarded email and I could not find out who created it (hence it's not attributed) but it's tough being born to a geek family.
Link (pdf)

Labels: ,



...
»Tuesday, November 20, 2007

HOWTO: Setup RoR, Mongrel and Apache on a production server

My experience with setting up production servers was zero before I tried to do this, and I had to go to a lot of sources to find a solution that worked for me. I finally got everyting working smoothly and here's the workflow that I used.

My setup:
-OS: Ubuntu 7.10 (Gutsy Gibbon) Server Edition
-Servers: Apache and Mongrel clusters
-Database: MySQL
-Deployment: Manual (It should be fairly easy to get Capistrano to work, but I am not using SVN and I haven't yet figured out how to integrate my setup with the SCM I currently use)
-RoR Application folder: /home/railsuser/rails/appname/

Step 1: Install Ubuntu Server and follow the instructions to install the LAMP stack (This will install Apache2 and MySQL for you.) It will be easy to reinstall or modify the Apache installation later if required.

Step 2: Install Ruby, Rails and Mongrel
Follow the instructions at http://mongrel.rubyforge.org/docs/debian-sarge.html to install Ruby, Rails, and Mongrel. The basic steps are as follows, but the linked blog provides help for systems that may have extra complications: As root:
  1. Update apt-get
    apt-get update
  2. Install Ruby:
    apt-get install ruby irb rdoc ri ruby1.8-dev libzlib-ruby libmysql-ruby libopenssl-ruby1.8
  3. Install Ruby Gems
    apt-get install rubygems
    (If you need to download rubygems first, use these instructions)
  4. Update your PATH
    In the user account you will use to run this, edit .bashrc (my preferred editor is nano)
    nano ~/.bashrc
    Add the following lines:
    PATH=$PATH:/var/lib/gems/1.8/bin
    export PATH
    Save and exit (^O and ^X should do that in Nano) and at the command prompt, reload your configuration:
    source ~/.bashrc
  5. Installing Mongrel will require some building, so make sure you have the components for that
    apt-get install build-essential
  6. Install Rails and Mongrel:
    gem install rails --include-dependencies
    gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies
    You will have to pick a version from the list provided. Pick the latest 'ruby' version. This step will take some time.
  7. Configure the Mongrel Cluster
    mongrel_rails cluster::configure -e production -p 8000 -N 2 -c /home/railsuser/rails/appname -a 127.0.0.1
    A note about this:
    -N 2 : Two instances of Mongrel will be started up as part of this cluster
    -p 8000: The Mongrel instances will listen at ports starting at 8000 (i.e. 8000 and 8001)
    /home/railsuser/rails/appname : Path to the folder where your Rails app resides
    -a 127.0.0.1 : This restricts access to localhost. If you are building a server where requests will come from domains other than localhost, do not include this option! I had a tough time figuring out why I could browse my site freely on the linux box, but not from any other machine until I tried removing this option.

    You should see a file mongrel_cluster.yml in the /config/ directory in your Rails application folder. If you need to make changes, use the cluster::configure command instead of directly editing this file.
  8. At this point, you should be able to cd to your Rails application directory (say /home/railsuser/rails/appname) and type in the following command to start up you rails cluster:
    mongrel_rails cluster::start
    You will see a confirmation of mongrel starting up on ports 8000 and 8001. To stop the cluster, just type mongrel_rails cluster::stop. I will update this later to add instructions on how to get mongrel to startup automatically, or you can just try these instructions yourself.
  9. Ensure that you can see your application work at http://yourhost:8000/ and http://yourhost:8001
Step 3: Install and configure Apache
  1. Installing Apache on Ubuntu is simple.
    apt-get install apache2
    However, if you were playing around with Apache and your installation is messed up, you can start afresh as follows:
    apt-get remove --purge apache2.2-common
    apt-get clean
    and then
    apt-get install apache2
  2. If the installation went fine, enable the modules that we need to make Apache work as a front end for the Mongrel cluster
    Instructive way:
    Browse to /etc/apache2/
    All the available modules are in mods-available, while the ones that are enabled are in mods-enabled (duh!) The conf files are the ones that we will look at later to configure apache. The obvious way to enable a module is to create a symbolic link from mods-enabled to mods-available. For example, to enable mod_rewrite, browse to mods-enabled and type (as root):
    ln -s ../mods-available/rewrite.load rewrite.load
    The non-obvious (and easier) way to do the same thing is to use the following commands (this is also a list of the modules we are interested in)
    a2enmod rewrite
    a2enmod proxy
    a2enmod proxy_balancer
    a2enmod proxy_http
  3. Now we need to configure Apache to use the balancer with the mongrel instances we started earlier. Edit /etc/apache2/sites-available/default
    If this is a fresh installation of apache, you don't have any pre-existing site configuration that you care about, so delete every line in this file (otherwise you will get errors about mixing * and *:80 ports) and type in the following (The colored lines are the ones we will have to edit):

    NameVirtualHost *:80

    #
    Add this if necessary
    ServerName myapp

    <Proxy *>
    Order allow,deny
    Allow from all
    </Proxy>

    #Proxy balancer section (Add as many BalancerMembers as you have
    #
    Mongrel servers running
    <Proxy balancer://myapp_cluster>
    BalancerMember http://myapp:8000
    BalancerMember http://myapp:8001
    </Proxy>

    #Virtual host section
    <Virtualhost *:80>
    ServerName myapp
    DocumentRoot
    /home/railsuser/rails/myapp/public/

    <Directory /home/railsuser/rails/myapp/public/ >
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>

    #log files
    ErrorLog /var/log/apache2/myapp_error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog /var/log/apache2/myapp_access.log combined

    #Rewrite stuff
    RewriteEngine On

    # Check for maintenance file and redirect all requests
    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /system/maintenance.html [L]

    # Rewrite index to check for static
    RewriteRule ^/$ /index.html [QSA]

    # Rewrite to check for Rails cached page
    RewriteRule ^([^.]+)$ $1.html [QSA]

    # Redirect all non-static requests to cluster
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://myapp_cluster%{REQUEST_URI} [P,QSA,L]
    </VirtualHost>


  4. Okay, lets's look at the elements we need to change in the above file:
    1. balancer://myapp_cluster:
      Replace myapp_cluster with whatever name you want, but keep it consistent across this file.
      The idea is that when RewriteRule finds a URL that matches the regular expression (say: ^/(.*)$), it will replace it with a value that is represented by balancer://myapp_cluster.
    2. BalancerMember:
      The value of balancer://myapp_cluster is determined by what you put in this section, where you have the paths to two of your mongrel servers. (If you had more than two mongrel servers in your mongrel configuration, you would need to put them in this section too). When a request for a page comes in, Apache will dynamically make a decision about which of your mongrel servers to forward it to.
      So replace BalancerMember http://myapp:8000 with your servername and port for each of the mongrel cluster members.
    3. DocumentRoot
      This is the path to your Rails App.
    4. <Directory /home/railsuser/rails/myapp/public>
      The /public is very important! This is the actual folder that your Rails server serves pages out of. If you forget to put this, expect to see 400 Bad Request messages from Apache.
  5. Restart apache as follows:
    /etc/init.d/apache2 force-reload
    (Later, you can replace force-reload with start/stop/restart, but for now we want to ensure that all the modules we added are loaded)
  6. Your site should be available at http://myhost/. While starting Apache, if you get a warning that the hostname could not be resolved, add the following line in the /etc/apache2/sites-available/default file right after NameVirtualHost *:80
    ServerName myhost
    where myhost is replaced by the actual domain name of your server.
Hopefully I haven't missed anything, but this worked for me, and I hope it does for you too.

Labels: , , , , , ,



...
»Tuesday, October 30, 2007

More about cellphones

One of the things I look forward to every day is reading the Wall Street Journal. To my mind, it brings back the days when the first thing I did every day was to read the newspaper. (The Times of India, before they morphed their print edition into a tabloid and also created one of the worst ad-infested websites I've seen) The downside is that if I find a great story, I can't send it to my friends since the online version is subscriber-only. Thankfully the Mossberg columns are available on his blog, so if you haven't seen or read his timely rant about the state of the cellphone service industry in the US, please do so now.

Apart from all the usual criticisms of the way cellphone services operate in the US, there's one that is strangely accepted - the fact that incoming text messages are charged! Leave aside the fact that text messaging is ridiculously expensive (when it is so cheap for the carrier to provide the service) - it is strange that folks are charged for incoming messages when there is no way to block text messages from appearing. At least you can refuse to answer an incoming call - there is no way to decline a text message, and if you have friends who love their unlimited text messaging plans (I know, I was one of them until recently), you can rack up charges for no fault of yours.

I can't wait for the rumored gPhone to shake up the way the cellphone industry works.

Labels: , , ,



...

What to do next

Also on this site

Latest Photos

  • www.flickr.com
  • » View Gallery

Stuff I read