Poetry of Programming

Its about Ruby on Rails – Kiran Soumya

By

The “remembered” three fishes story…

Instead of using the word “unforgettable story”, I should say this story is always remembered in every act of my life.

The story is a lesson of my telugu detailed text book in my school days and it is … as follows:

Once upon a time, there lived three fishes in a lake. Their names are “Bhuddimathi”, “Kalamathi” and “Mandamathi”. I hope you got the story by names… But still let me continue… They used to live together and lead a happy undisturbed life in the lake. But one day suddenly… villains appeared… two fishermen… they were standing next to the lake and talking about fishing this place soon. They have decided to come with nets and other things the next week. The three fishes who heard this got scared… Bhuddimathi has decided to start to the next lake near by before those fishermen come. The next day early morning itself, it alerted the other two fishes and reached the other lake safely. The other two fishes thought there was lots of time left to them so they took it easy. Finally, the two fishermen approached the lake one day before they planned… Kalamathi as it is smart… acted dead once its caught. And thinking that fish was really dead .. the fisherman threwed it back to the lake. And it safely started its journey to other lake. But the third fish “Mandamathi” finally who could neither be like Bhuddimathi acting before nor like Kalamathi acting smart was fated to death due to its negligence.

So from then… in every work I do… my mom alerts me saying… be like Bhuddimathi study before itself or complete your work before itself… Even now… in anything… if I have to get fruits or if I have to get milk for curd or if I have to book my tickets to vizag or in anything.. this Kalamathi, Mandamathi and Bhuddimathi characters appear… Always I prove her to be Kalamathi but never Bhuddimathi…

But nowadays seriously… I improved from Kalamathi to Bhuddimathi… Believe me Mom!

By

Dilemma of a Developer under TL

I have a group of friends in big MNC software fields… who complain a lot about their Tls … almost every day… And I cant complain in return because I dont have one !!! Infact.. I am the Tl/owner of my own Task..

But when a developer works under someone or managed by someone… that someone becomes a Guru for the developer. As an Indian Slogan…”Guru Devo Bhava !” [which means “Guru is equal to God”].

But if there are too many Gurus…??? Simple… Too many Gods… :)
Taken Project on Hand… Incremental Developments or Releases are possible only when…

1> The manager knows… whos eligible for what… On a situation to give freedom to developers.. tasks decided within the group need to be known to everyone.

2> When you let the developer complete implementing his whole idea whatever he understands… after a ONE-TIME compulsory discussion/Goal achievement Plan — and thats perfect ! Because Guru is God !

3> Without completion of this one-time plan by the developer… never add new stuff/discussions that confuses the developer neither to complete his past work nor do the newly added stuff.

4> Any debates on the idea to be taken place only with the right person or the creator who knows everything.
5> The bottomline should surely be shared with the developer who ultimately needs to complete the goal.

6> Thereby the easy developer feels easy to release whatever on hand and every week meetings includes the happy releases whether it is accepted/rejected. This surely makes the track of the work and the developer.

7> Arguments/debates are allowed weekly once to change the plan or update it to make this another solid release.

8> A plan that changes daily is never said or called it as a “Plan”. If planning is perfect… then releases are perfect…

Hey Tls…! If you set the plan … then the developer is just a perfect mirror of your plans/ideas… or else leave everything to the developer… sometimes he knew better than you…!!!

Never blame the Developer rather believe… Because He gives Life for it as he is the one who builds it !!!

By

Pin Drop Sound please…

Code code code… hurray…
But whos that? calling me there…

Discussion Discussion Discussion…
Confusion Confusion Confusion…

Too many cooks… threw me in a hot pan…
Although… I have set my plan.

The whole concept… lost its fuse.
And who is this now … dumping things in dose.

What the heck the themes/dress change do
Please… Please give me a clue…

When not even the model/doll exists…
Help ! I need to complete this…

Ok say yes to one… say no to other…
Now see the fireworks around. do you bother?

Follow the right and make the domineer sad…
How to make all happy… without doing… all bad?

Wah! Finally… What a silence…
Now… I am leaving into the world of coding sense…

Me and my laptop…
On a rocket plane… to the success hill top !

By

So howzz Rails2.0? Its Awesome !

Added the “rake routes” task, which will list all the named routes created by routes.rb.

All resource-based controllers will be plural by default. This allows a single resource to be mapped in multiple contexts and still refer to the same controller. Example:
  # /avatars/45 => AvatarsController#show
  map.resources :avatars

  # /people/5/avatar => AvatarsController#show
  map.resources :people, :has_one => :avatar

Rendering a HTML page in Iphone using Rails 2.0 Multi View

Speaking of the iPhone, we’ve made it easier to declare “fake” types that are only used for internal routing. Like when you want a special HTML interface just for an iPhone. All it takes is something like this:
  # should go in config/initializers/mime_types.rb
  Mime.register_alias “text/html”, :iphone

  class ApplicationController < ActionController::Base
    before_filter :adjust_format_for_iphone

    private
      def adjust_format_for_iphone
        if request.env[“HTTP_USER_AGENT”] && request.env[“HTTP_USER_AGENT”][/(iPhone|iPod)/]
          request.format = :iphone
        end
      end
  end

  class PostsController < ApplicationController
    def index
      respond_to do |format|
        format.html   # renders index.html.erb
        format.iphone # renders index.iphone.erb
      end
    end
  end
You’re encouraged to declare your own mime-type aliases in the config/initializers/mime_types.rb file. This file is included by default in all new applications.

No more overhead of Requesting a bazillion of Javscript/Stylesheet files

In Rails2.0, Using javascript_include_tag(:all, :cache => true) will turn public/javascripts/.js into a single public/javascripts/all.js file in production, while still keeping the files separate in development, so you can work iteratively without clearing the cache.

Speed your application !

In Rails2.0, If you set ActionController::Base.asset_host = “assets%d.example.com”, we’ll automatically distribute your asset calls (like image_tag) to asset1 through asset4. That allows the browser to open many more connections at a time and increases the perceived speed of your application.

Identify your Record url just by object !

Added a number of conventions for turning model classes into resource routes on the fly. Examples:
  # person is a Person object, which by convention will
  # be mapped to person_url for lookup
  redirect_to(person)
  link_to(person.name, person)
  form_for(person)

API authentication over SSL

It’s terribly simple to use. Here’s an example (there are more in ActionController::HttpAuthentication):
  class PostsController < ApplicationController
    USER_NAME, PASSWORD = “dhh”, “secret”

    before_filter :authenticate, :except => [ :index ]

    def index
      render :text => “Everyone can see me!”
    end

    def edit
      render :text => “I’m only accessible if you know the password”
    end

    private
      def authenticate
        authenticate_or_request_with_http_basic do |user_name, password|
          user_name == USER_NAME && password == PASSWORD
        end
      end
  end

Security

A built-in mechanism for dealing with CRSF attacks. By including a special token in all forms and Ajax requests, you can guard from having requests made from outside of your application. All this is turned on by default in new Rails 2.0 applications and you can very easily turn it on in your existing applications using ActionController::Base.protect_from_forgery (see ActionController::RequestForgeryProtection for more).

Also made it easier to deal with XSS attacks while still allowing users to embed HTML in your pages. The old TextHelper#sanitize method has gone from a black list (very hard to keep secure) approach to a white list approach. If you’re already using sanitize, you’ll automatically be granted better protection. You can tweak the tags that are allowed by default with sanitize as well. See TextHelper#sanitize for details.

Finally, added support for HTTP only cookies. They are not yet supported by all browsers, but you can use them where they are.

Exception handling

Lots of common exceptions would do better to be rescued at a shared level rather than per action. This has always been possible by overwriting rescue_action_in_public, but then you had to roll out your own case statement and call super. Bah. So now we have a class level macro called rescue_from, which you can use to declaratively point certain exceptions to a given action. Example:

  class PostsController < ApplicationController
    rescue_from User::NotAuthorized, :with => :deny_access

    protected
      def deny_access
        …
      end
  end

Cookie store sessions

The default session store in Rails 2.0 is now a cookie-based one. That means sessions are no longer stored on the file system or in the database, but kept by the client in a hashed form that can’t be forged. This makes it not only a lot faster than traditional session stores, but also makes it zero maintenance. There’s no cron job needed to clear out the sessions and your server won’t crash because you forgot and suddenly had 500K files in tmp/session.

This setup works great if you follow best practices and keep session usage to a minimum, such as the common case of just storing a user_id and a the flash. If, however, you are planning on storing the nuclear launch codes in the session, the default cookie store is a bad deal. While they can’t be forged (so is_admin = true is fine), their content can be seen. If that’s a problem for your application, you can always just switch back to one of the traditional session stores (but first investigate that requirement as a code smell).

New request profiler

The new request profiler that can follow an entire usage script and report on the aggregate findings. You use it like this:

  $ cat login_session.rb
  get_with_redirect ‘/’
  say “GET / => #{path}”
  post_with_redirect ‘/sessions’, :username => ‘john’, :password => ‘doe’
  say “POST /sessions => #{path}”
  $ ./script/performance/request -n 10 login_session.rb
And you get a thorough breakdown in HTML and text on where time was spent and you’ll have a good idea on where to look for speeding up the application.

AtomFeedHelper

Makes it even simpler to create Atom feeds using an enhanced Builder syntax. Simple example:

  # index.atom.builder:
  atom_feed do |feed|
    feed.title(“My great blog!”)
    feed.updated((@posts.first.created_at))

    for post in @posts
      feed.entry(post) do |entry|
        entry.title(post.title)
        entry.content(post.body, :type => ‘html’)

        entry.author do |author|
          author.name(“DHH”)
        end
      end
    end
  end

Faster Performance

Active Record has seen a gazillion fixes and small tweaks, but it’s somewhat light on big new features. Something new that we have added, though, is a very simple Query Cache, which will recognize similar SQL calls from within the same request and return the cached result. This is especially nice for N+1 situations that might be hard to handle with :include or other mechanisms. Also drastically improved the performance of fixtures, which makes most test suites based on normal fixture use be 50-100% faster.

More efficient Migrations

create_table :people do |t|
  t.column, “account_id”,  :integer
  t.column, “first_name”,  :string, :null => false
  t.column, “last_name”,   :string, :null => false
  t.column, “description”, :text
  t.column, “created_at”,  :datetime
  t.column, “updated_at”,  :datetime
endNow you can write:

create_table :people do |t|
  t.integer :account_id
  t.string  :first_name, :last_name, :null => false
  t.text    :description
  t.timestamps
end

Clean up your environment

Before Rails 2.0, config/environment.rb files every where would be clogged with all sorts of one-off configuration details. Now you can gather those elements in self-contained files and put them under config/initializers and they’ll automatically be loaded. New Rails 2.0 applications ship with two examples in form of inflections.rb (for your own pluralization rules) and mime_types.rb (for your own mime types). This should ensure that you need to keep nothing but the default in config/environment.rb.

Easier plugin order

This can require that you load, say, acts_as_list before your own acts_as_extra_cool_list plugin in order for the latter to extend the former.

Before, this required that you named all your plugins in config.plugins. Major hassle when all you wanted to say was “I only care about acts_as_list being loaded before everything else”. Now you can do exactly that with config.plugins = [ :acts_as_list, :all ].

By

Notes on using fb:swf in FaceBook

In facebook groups or discussions… I saw plently of developers struggling to embed fb:swf using FBML.

An example for them to make their life easier :)

<fb:swf swfsrc=”SRC_URL” allowscriptaccess=”all”
bgcolor=”#ECECEC” id=”some_id” wmode=”transparent” SWLIVECONNECT=”true”
flashvars=”serverPath=http://dynamic_url?fbid=<%=uid%>&some_params=blahblah” height=”200″ width=”382″
imgsrc=”img_url_at_beginning” />

The other Common Wiki Notes for this to be noted:

  • Currently, Facebook requires Flash version 9.0.0 for all <fb:swf> tags.
  • Make sure that the flashvars parameter is all lowercase. Some sources of embedded links capitalize the V, which does not work on Facebook.
  • Currently, Facebook wraps the resultant Flash object in a <div> tag, so despite the fact that the embed/object tag is not block-level, consecutive <fb:swf> tags will appear one above the other instead of side-by-side.
  • To verify that your Flash object was loaded from a Facebook page, do the following. For security, this technique does not embed your secret key in your Flash app:
  1. Get all the parameters whose names start with fb_sig_. (Do not include the fb_sig parameter itself.) In Flex use Application.application.parameters to do this.
  2. Strip the fb_sig_ prefix from each, and make sure the keys are lowercase.
  3. Create a string of the form param1=value1param2=value2param3=value3, etc., sorted by the names (not the values) of the parameters. Note: Do not use ampersands between the parameters.
  4. Pass this string to your server, where your secret key is stored.
  5. On your server, append your application secret key to the string that was passed in. The following is returned: param1=value1param2=value2param3=value3myappsecret
  6. On your server, create an MD5 hash of this string.
  7. Return the MD5 hash from your server to your Flash object.
  8. In your Flash object, compare the returned hash with the fb_sig parameter that was passed in. If they are equal, then your Flash object was loaded by Facebook. (Or by someone who stole your secret key.)

While the above technique doesn’t embed your secret in the Flash object, what you’re doing is making a public Web service to sign parameter strings with your secret and then embedding its address in your Flash object. This is just as bad as publishing your secret key (except you do the MD5 computation for any malicious clients). What you want to do is send all the parameters to the Web server (including fb_sig) and have it verify the signature internally and respond with either OK or NOT_OK.

By

Embedding Flash in Google Gadget !

A static flash play can be easily embedded using _IG_EmbedFlash() function in the gadget but since we need to load the xml according to the User Login preferences. I need to do some more modifications.

The issue I faced here is :

For security reasons, a Macromedia Flash playing in a web browser is not allowed to access data that resides outside the exact web domain from which the SWF originated.

Since google loads modules from 97.gmodules.com domain, extracting data from marketsimplified domain becomes external.

Cross-domain policy file has to be created to make it work.

(Ref: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14213&sliceId=2)

But still I didnt get it to work… unless on top of this, I have to do some workaround as described in this url…
http://www.scriptplayground.com/tutorials/as/Loading-remote-XML-in-Flash-8/

However finally… its up and running…

By

Import Tool – ScRUBYt

At first I tried String Wrapper tool using open-uri

Then I understood Tree wrappers tools that the HTML document can look very good in a browser, yet still be seriously malformed (unclosed/misused tags). It is a non-trivial problem to parse such a document into a structured format like XML, since XML parsers can work with well-formed documents only

But HTree and REXML is capable to transform the input into the nicest possible XML from our point of view: a REXML Document. ( REXML is Ruby’s standard XML/XPath processing library).

After preprocessing the page content with HTree, we have to unleash the full power of XPath, which is a very powerful XML document querying language, highly suitable for web extraction.

The powerful web scrapping tools in Ruby are mainly Mechanize and Hpricot. Hpricot is “a Faster HTML Parser for Ruby” out of other Rubyful-soup(HTree + XPath),scrAPI,ARIEL

www::Mechanize has the ability to automatically navigate through Web pages as a result of interaction (filling forms etc.) while keeping cookies, automatically following redirects and simulating everything else what a real user (or the browser in response to that) would do.

Mechanize is powerful lib BUT we cannot perfectly interact with JavaScript websites. That is, it cannot handle more than one redirects through javascript.

Using mechanize, attempts to gmail webscrap to get all mails (feed exists to get new mails only) and orkut scraps extraction could go through until there is no complex javascript to break.

At first tried to do google search and extract reditt articles using almost all libs.

Then Using Xpath and scRUBYt, I am able to extract details from finance.google.com in xml format.

To a certain extent scRUBYt which is combination of Hpricot and Mechanize on steriods, seems starting step to me to get finance.google.com portfolio.

Also,scRUBYt is faster than mechanize.

Program:

require 'rubygems'
require 'scrubyt'

google_data = Scrubyt::Extractor.define do
fetch 'http://finance.google.com'
click_link 'Portfolios'
fill_textfield 'Email', '<a href="mailto:kiransoumi@gmail.com">kiransoumi@gmail.com</a>'
fill_textfield 'Passwd', '----'
submit
fetch 'http://finance.google.com/finance/portfolio?action=view&pid=1'
click_link 'Transactions'
#Construct the wrapper
stockinfo "/html/body/div/div/table/tbody/tr" do
   symbol "/td[1]/a[1]"
   qty "/td[5]"
   price "/td[6]"
end

end

google_data.to_xml.write($stdout, 1)
Scrubyt::ResultDumper.print_statistics(google_data)

OUTPUT:
[MODE] Learning
[ACTION] fetching document: <a href="http://finance.google.com">http://finance.google.com</a>
[ACTION] clicking link: Portfolios
[ACTION] fetched <a href="https://www.google.com/accounts/ServiceLogin?hl=en&service=finance&nui=1&continue=http%3A%2F%2Ffinance.google.com%3A80%2Ffinance%2Fportfolio%3Faction%3Dview">https://www.google.com/accounts/ServiceLogin?hl=en&service=finance&nui=1&continue=http%3A%2F%2Ffinance.google.com%3A80%2Ffinance%2Fportfolio%3Faction%3Dview</a>
[ACTION] typing <a href="mailto:kiransoumi@gmail.com">kiransoumi@gmail.com</a> into the textfield named 'Email'
[ACTION] typing ---- into the textfield named 'Passwd'
[ACTION] submitting form...
[ACTION] fetched <a href="https://www.google.com/accounts/CheckCookie?continue=http%3A%2F%2Ffinance.google.com%3A80%2Ffinance%2Fportfolio%3Faction%3Dview&service=finance&hl=en&chtml=LoginDoneHtml">https://www.google.com/accounts/CheckCookie?continue=http%3A%2F%2Ffinance.google.com%3A80%2Ffinance%2Fportfolio%3Faction%3Dview&service=finance&hl=en&chtml=LoginDoneHtml</a>
[ACTION] fetching document: <a href="http://finance.google.com/finance/portfolio?action=view&pid=1">http://finance.google.com/finance/portfolio?action=view&pid=1</a>
[ACTION] clicking link: Transactions
[ACTION] fetched <a href="http://finance.google.com/finance/portfolio?action=viewt&pid=1">http://finance.google.com/finance/portfolio?action=viewt&pid=1</a>
Extraction finished succesfully!
  <root>
    <stockinfo>
      <symbol>IBM</symbol>
      <qty>22.00</qty>
      <price>22.00</price>
    </stockinfo>
    <stockinfo>
      <symbol>GOOG</symbol>
      <qty>10.00</qty>
      <price>270.00</price>
    </stockinfo>
    <stockinfo>
      <symbol>INFY</symbol>
      <qty>12.00</qty>
      <price>80.00</price>
    </stockinfo>
    <stockinfo>
      <symbol>INTC</symbol>
      <qty>4.00</qty>
      <price>18.00</price>
    </stockinfo>
  </root>

stockinfo extracted 4 instances.
symbol extracted 4 instances.
qty extracted 4 instances.
price extracted 4 instances.

By

Syndication of My MarketSimplified Portfolio Chart

Its Simple…
Just go to Google gadget Directory and search for MarketSimplified Portfolio Chart or
Click here

If you can click on "Add to your Webpage" button there, then you can reach a page where you can first configure your Gadget Settings by entering your MarketSimplified Portfolio User name and country. And then do some colouring and adjustment of the gadget size by dragging the ends.

Finally,Click on Priview Changes button below.  If you are confirmed and happy with your colorful changes, then click on "Get the Code" button just below the page.

Finally paste the code on your Weblog like me…

By

Top five rated Stocks and good Widget…

 

By

Coming up …! Soon rolling down on your hand…!

Increasing Download Rate per day…! Wow!

What happens when the new version of MarketSimplified Mobile App comes up…???

When was the last time you were confronted with a deluge of unnecessary information screaming for Msf_chart
your attention ?

Market Simplified :

1. World’s first totally user customizable Financial Homepage
2. Specialist Financial Search to give one click response to Financial queries
3. Safeguard your portfolio with a dynamic and perpetual alerts on a range of parameters
4. Carry your portfolio with you ; RSS feeds of your portfolio anytime
5. The stock markets in your hands with the MarketSimplified Mobile

Welcome to the world of Market Simplified! Investing simplified.

For users who use Smart Phones and have GPRS enabled, please lo g in to
www.marketsimplified.com/mobile
to download the latest MSF mobile application available ‘Over The Air’.

Yup..! Its Black…!! …its Berry..!!!

By

My Cubicle…

After a long (sick) break…

So far update as of now is… My cubicle… (I like the way it is …!)
My new Dell Xps laptop on left … Robo on right… My work PC in between…
And I am working on digging out the valuable Diamond app :)

By

Rain, Rain Go Away!

Rain, Rain Go Away ..!
I hate you all the way…

Dont come even some other day…
Rain, Rain Go… away .. !!!

By

Five Hot Technologies for 2007

   1. Ruby on Rails
        Faster, easier Web development (link)

   2. NAND drives
        Bye-bye, HDD?

   3. Ultra-Wideband
        200x personal-area networking

   4. Hosted hardware
        Supercomputing for the masses

   5. Advanced CPU architectures
        Penryn, Fusion and more

Further notes here

By

Day Trader’s Dilemma

by Lawrence Andraschko

from WallStreetPoet.com

Should I sell or should I hold?

If I hold there could be trouble,

But if I sell, the stock could double.

Am I weak or am I bold?

Should I sell or should I hold?

My stock keeps going up.

Better pour myself another cup.

All this coffee makes me jitter,

Have I picked another winner?

Am I weak or am I bold?

Should I sell or should I hold?

This indecision is killing me.

The price is falling and I have to pee.

Do I hold my bladder and my stock,

Or do I sell and use the pot?

Am I weak or am I bold?

Should I sell or should I hold?

The stock goes up and I wait no more,

I sell my shares and hit the floor.

A little profit beats a loss,

How I suffer as my own boss.

Am I weak or am I bold?

Should I sell or should I hold?

Nature keeps calling and I need a plan,

Maybe kitty litter or some sand.

Put it right beneath my desk,

Then I wouldn’t make a mess.

Am I weak or am I bold?

Should I sell or should I hold?

By

CSV in Ruby

To Create CSV file in Rails:

    @models = Model.find(:all, :conditions => ['...'])
    rawdata = StringIO.new
    CSV::Writer.generate(rawdata, ',') do |csv|
      csv << %w(Title Total)
      @models.each do |model|
        csv << [model.title, model.total]
      end
    end

    rawdata.rewind
    send_data(rawdata.read,
      :type => 'text/csv; charset=iso-8859-1; header=present',
      :filename => 'rawdata.csv')

To retrieve, here is the lib…

FasterCSV is intended as a
replacement to Ruby‘s standard CSV library. It was designed to
address concerns users of that library had and it has three primary goals:

  1. Be significantly faster than CSV while remaining a pure Ruby library.

  2. Use a smaller and easier to maintain code base. (FasterCSV is larger now, but
    considerably richer in features. The parsing core remains quite small.)

  3. Improve on the CSV interface.
  4. def retrieve_csv
       csv_file = params[:csv_file]
     
      begin
        Record.transaction do
          fastercsv = FasterCSV.new( csv_file )
          while row = fastercsv.readline
            foo, bar = row
            Record.create!( :foo => foo, :bar => bar )
          end
        end
        redirect_to success_action_path
      rescue
        # do something with the error
        flash[:error] = "CSV import failed"
        redirect_to retrieve_path
      end
    end