Nexus one for existing customers

January 9th, 2010 mahesh No comments

If you are an existing t-mobile customer and are planning to get a nexus one, you probably know by now that you have to pay $279 and not $179 (which is for new customers only). I just can not understand the reasoning behind this. Anyway, since my contract has expired, I thought I can just get on a new plan with a new account if required and get the phone for $179. Guess what, you can’t even do that. After researching on various forums and piecing together, I got my nexus one for just 20 bucks more instead of shelling out 100 bucks!

So, what I did was, I called  tmobile and told them I want to cancel the account and go to another network for 3 months and come back as a new customer. That way I save 100 bucks. I was ok waiting for 3 months to get my hands on that phone. I am excited about that phone but not THAT desperate. It is after all just a phone. But guess what, tmobile was like, it anyway costs 35 bucks or so to activate when I come back as a new customer, so they agreed to give me $45 credit. So, I really put in only 20 bucks more and got the phone! Isn’t that cool? :) Let’s see when google will ship it to me.

If you are an existing customer, try that and see if it works for you as well or if there is any other workaround, I will be curious to know! Well, not really, I already got mine ;)

Cheers,
Mahesh Murthy!

Categories: Uncategorized Tags:

Beyond my understanding!

October 30th, 2009 mahesh No comments

I had a bug in my application where the calculation was a little off from expected. After putting debug statements, I narrowed it down to an interesting behaviour in ruby. Fire up irb and try it out yourself!

irb(main):001:0> (6.725*60*24).to_i
=> 9684
irb(main):002:0> (6.725*24*60).to_i
=> 9683

wtf?

Categories: Uncategorized Tags:

Annoying rails date validation

September 13th, 2009 mahesh No comments

I spent a good amount of time breaking my head over why a date field wasn’t getting set in one of the model after retrieving it’s value from a form. It turns out that if you pass a random string and not an actual date, rails will silently assign a nil to that field without complaining.

For example, I have a class Fact with date fields called from and to. Notice what is happening.

Loading development environment (Rails 2.3.3)
>> fact = Fact.new
=> #<Fact id: nil, from: nil, to: nil, timeToCount: nil, val: nil, remarks: nil, cp_detail_id: nil, created_at: nil, updated_at: nil>
>> fact.from = "foo"
=> "foo"
>> fact
=> #<Fact id: nil, from: nil, to: nil, timeToCount: nil, val: nil, remarks: nil, cp_detail_id: nil, created_at: nil, updated_at: nil>
>> fact.from = DateTime.now
=> Sun, 13 Sep 2009 09:53:29 -0600
>> fact
=> #<Fact id: nil, from: "2009-09-13 09:53:29", to: nil, timeToCount: nil, val: nil, remarks: nil, cp_detail_id: nil, created_at: nil, updated_at: nil>

script/console

Loading development environment (Rails 2.3.3)

>> fact = Fact.new

=> #<Fact id: nil, from: nil, to: nil, timeToCount: nil, val: nil, remarks: nil, cp_detail_id: nil, created_at: nil, updated_at: nil>

>> fact.from = "foo"

=> "foo"

>> fact

=> #<Fact id: nil, from: nil, to: nil, timeToCount: nil, val: nil, remarks: nil, cp_detail_id: nil, created_at: nil, updated_at: nil>

>> fact.from = DateTime.now

=> Sun, 13 Sep 2009 09:53:29 -0600

>> fact

=> #<Fact id: nil, from: "2009-09-13 09:53:29", to: nil, timeToCount: nil, val: nil, remarks: nil, cp_detail_id: nil, created_at: nil, updated_at: nil>

When I assign a value foo, it doesn’t complain but just assigns a nil.  Only if it had complained, I could have saved so much of my brain cells and time. Sigh …

Now, you might ask why am I assigning a foo instead of date. Well, I am still developing and was just putting random values to get the form to work  :P

Anyway, I hope it will help some nOOb like me someday.

Have a good week,
Mahesh Murthy

Categories: Uncategorized Tags:

Upgrade your wordpress plugin

July 8th, 2009 mahesh No comments

If you use wordpress plugin for your website, make sure you are using the latest version of it. If you are lazy like me, chances are that sooner or later your site will be hacked. Yeah, mine was hacked because I had not upgraded in ages. Thankfully my database was intact, so I didn’t lose anything. Here is a good read: http://ocaoimh.ie/did-your-wordpress-site-get-hacked/

have a good day,
Mahesh Murthy

Categories: Uncategorized Tags:

:cache => true

April 27th, 2009 mahesh No comments

That is all it took to take my site from F grade to B and make my site faster by 1 second almost! So, if you have a rails app, go ahead and add :cache => true to your stylesheet_link_tag and javascript_include_tag in your view files. This is all I added into my application.html.erb

<%= stylesheet_link_tag "home", :media => "all", :cache => true %>
<%= javascript_include_tag :all, :cache => true %>

All rails does is collapses all your javascript (and stylesheet) files into single file. I have 11 javascript files and 3 css files. With this, I reduced the number of calls by 12 and that gave a good one second improvement! Not bad ha? Also, that one second was pretty consistent with/without firefox caching.

After this, I tried using asset_packager plugin to see if I get any more improvement. But, I didn’t really see any. Basically, that minifies your files by combining everything into one file and removing new line character and stuff.

The video tutorial had a few more suggestions like using CDN which clearly is not something I would like to explore at this point because it costs money.

That’s all for now. Stay tuned for more improvements as I go through next tutorials.

Cheers,
Mahesh Murthy

Categories: Uncategorized Tags:

How fast is your website?

April 15th, 2009 mahesh No comments

I was searching for rails caching tutorials and ran into this really nice set of video tutorials about scaling rails applications on newrelic. I just watched the first video which has some neat tricks on how to improve the page load time. I ran some tests on thecollegestuff.com and here are the stats.

1. According to firebug, the site load time is 3.5 seconds and the breakdown is as follows

firebug

2. Then the tutorial mentioned about yslow and how to use it to collect some stats. Here is the output from yslow.

yslow

Ugh .. my site has a rating F!

Over the next few days, I will try to implement all the things suggested in the tutorials. Let’s see how much improvement I will get out of it.

Have a nice day!
Mahesh Murthy

Categories: Uncategorized Tags:

Note on page caching

April 12th, 2009 mahesh No comments

It turns out I can’t use page caching like the way I did in the previous post. The way page caching works is that rails just saves the rendered html in the public directory and next time when the request comes in, if the page exists, it just fetches it. The problem is, if a user is logged in, his name shows up on the top right corner of the page. Now let’s say on the first hit for user foo, rails caches the page. When someone else accesses the same url, rails happily fetches the cached page (with user name foo) to user bar. yikes! User bar is all confused now. Not good.

Moral of the story: Page caching should be used for pages which don’t have any customized information.

What I really need is action caching. Back to the drawing board! I will blog about it when I am done.

See you later,
Mahesh Murthy

Categories: Uncategorized Tags:

Go rails caching!

March 31st, 2009 mahesh No comments

I had no idea caching is SO simple in rails. I added some caching to thecollegestuff.com. Two places where caching was clearly needed were the college page listing all its professors and the professor page with all the ratings. Majority of the people who land on these pages are only viewing these pages. They are not really adding content. So, it makes sense to fetch the page quickly (from the cache).

For now the way my cache expires is when someone rates a professor in which case I expire that professor page. Similarly, I expire the college page when a new professor is added. Below is a code snippet which does the caching.


class ProfessorsController < ApplicationController

caches_page :show

cache_sweeper :professor_sweeper,
:o nly => [ :create ]

caches_page is self explanatory. I have cached the show transaction.

cache_sweeper is used to expire the cache when a create method is called on the professor. Below is the sweeper code.


class ProfessorSweeper < ActionController::Caching::Sweeper

observe Professor

def after_create(professor)
expire_college_page(profesor.college_id)
end

private

def expire_college_page(collegeId)
expire_page :controller => “colleges”, :action => “show”, :id => collegeId
end

end

That is all it takes to do a page caching! I am sure I can find more places in my code which can be cached. I will have to see if I can use some action caching or fragment caching somewhere. The home page has the top professor and college list which are database queries. I have to find a nice way to cache that part of the page. I will play around next weekend. Have a good week!

Cheers,
Mahesh

Categories: Uncategorized Tags:

What are your 3 must read blogs everyday?

March 17th, 2009 mahesh 3 comments

I just noticed that there are a few blogs which I really look forward to reading everyday. Do you have any in your feed reader like that? If so, can you share it with me?

Here are the 3 I read everyday without fail

0. Seth’s

1. Fred’s

2. Jeff’s

Feel free to add yours in the comments section.

Cheers,
Mahesh

Categories: Uncategorized Tags:

End of week 1 – thecollegestuff goes nowhere

March 8th, 2009 mahesh 3 comments

It’s been a week since I put thecollegestuff.com up. There has been one registered user apart from me (ouch!). I think there are many reasons for it. I am just brainstorming here for myself. Feel free to add anything I have left out.

  • the site is just ordinary. No killer features, nothing
  • Look and feel is very average
  • There is no much content there
  • I haven’t done a good job of marketing the site
  • Let’s see what I can do to fix each of them

    Point 1: I will work on adding the features in my todo list.
    Point 2: Anyone out there who can clean up the interface a little bit? Leave a comment if you are interested!
    Point 3: This is a chicken and egg problem. Users will be motivated if there is content. But they are the ones who will have to add content. So, I don’t know what to do here.
    Point 4: I will start bugging my friends to use the site and spread the word and will look up online for some marketing techniques ;)

    That is the 3 point formula to win! I am sure I will laugh at myself looking back at this post sometime in the future. heh .. who cares. This is fun for now! The feelinig of starting a website is amazing even if it is crappy!

    That is all for now. Have a good week ahead!

    Cheers,
    Mahesh

    Categories: Uncategorized Tags: