Friday, May 8, 2009

Some life updates

Actually this month is happening... as life is as usual.
Just resigned from MPST(MPS Technologies Limited) and am stretching my legs and thank god that even summers are chilling now-a-days so it is all very pleasant.
and I voted too this central elections (it is only applicable if you known about current Indian political status of India).
And ya the most happening thing that i did this week was i took the test drive of Toyota innova, and to be fare i thought i was disappointed for the gear knob vibrations from toyota but latter on, i thought every other car is only way behind it.... so why give it a bad name.. so it is good and perfect if you care about your family and wanna visit places.. it is a nice car that's for sure.
And as was expected, I also visited the tata showroom to ask in for tata most famous car after nano, exactly the safari The tata safari... and not going against my expectations, they didn't had any car to give the test drive and according to them they give test drive on vehicles which are ordered for other customers, now that's bad.
And here is a car comparison that i have not done before..
Innova is
  • good interiors
  • good exteriors
  • not so good vibrating gear in diesel
  • it doesn't rules the road
  • No 4*4 wheel drive
  • but very stable and great family car
  • Service is prompt i will buy innova if i can park it in near future

About Safari
  • "Reclaim you life" slogans fits in, but is life so lost??
  • Great exteriors and equally bad interiors
  • finish is not finished yet, come on guys increase the price by 2 lakhs but don't decrease the expectations
  • Why is roof mounted AC looks as if it is not part of roof (learn something from innova)
  • Service (Needs a big big improvement)
  • And please do have a separate car to test drive

:)

I was so mentally boosting myself to buy a safari but they have shattered my dreams, what to do and why to do!! both questions are playing

Any how people its late in night and that too of no-work... i want to fit my "Reclaim your sleep" slogan now.

bbye and good luck

Saturday, May 2, 2009

Pretty urls with name or title in ruby on rails

Hi folks,

Something on which is very old.. might not be very interesting for many of you who are into rails development. I am talking about the pretty-urls the SEO stuff(forget all this, it is for good readability of url).

So what my basic funda that i have gathered from last three years is that, every resource is identified by an identifier in rails(generally called id, in terms of database), but displaying the id doesn't sounds legal to me.. so to hide the ids and to have a nice looking readable

we can have title or name fields in the database's relation(table) and to make use of pretty urls, we make corresponding column like stripped_title or stripped_name.
create a file "make_pretty_url.rb" in initializers in config and append the following code.


puts "===================================================="
puts "Adding engine to make pretty url(s)"
puts "===================================================="
module ActiveRecord
class Base
after_create :make_or_update_pretty_url_name

def make_or_update_pretty_url_name
parent_column = nil
stripped_column = self.attributes.collect {|x| x.to_s.include?("stripped_") ? x : nil}.flatten.compact.first
if stripped_column
parent_column = stripped_column.gsub("stripped_","")
if self.send(parent_column)
self.send("#{stripped_column}=",stripp_it(self.send(parent_column)))
if self.class.find(:all, :conditions => ["#{stripped_column} = ?",self.send(stripped_column)]).length > 0
self.send("#{stripped_column}=","#{self.send(stripped_column)}-#{self.id.to_s}")
end
self.send("save")
end
end
end

def stripp_it(str)
str.strip.downcase.gsub(/[^a-z0-9]/,"-").gsub(/(-)+/,"-").gsub(/(-)+$/,"")
end
end
end


it will automatically create stripped_{column_name} and will take care of duplicates and instead of using find_by_id(), find_by_stripped_{column_name} will be used to get the resource and "make_or_update_pretty_url_name" method will also be available for any manual work too.

Hope this just adds in the knowledge base of stuff, and if there is anything about it, let me know through comments..

Friday, April 17, 2009

RAILS: interning empty string

Hi folks,

Really after a long time, writing a post on ROR (even a simple post). AN the reason for delay.. work as usual and secondary i want people to educate on an error, with the statement as "interning empty string" something showing thing like this.


Being from IT industry and not much into literature, first thought came in my mind after hitting this error was "what does interning means?" and the answer from dictionary.com says "to restrict to or confine within prescribed limits" which just meant some breakage of boundary of something and i am the culprit( as always :)) )

But an ware of what i did, started hitting Ctrl + Z (to undo my bad deeds :))) but no luck!! just nothing.. i was like what!! what is that which is not getting undone over here and even google search was showing some very unresponsive result... so was left alone to trigger army against this.
And finally i got the answer and it was...

If you have a partial defined something like "_partial_name.html.erb" everything is fine till the time you don't append an extra dot to the partial file name something like "_partial_name..html.erb" it will through "interning empty string" even if you don't render the partial anywhere


So guys and gals next time try to be more concentrated on renaming a partial, because it can lead to something where even google searches don't have a definite answer to.

That is it for the day.

Happy coding and happy engineering

Tuesday, March 31, 2009

Thursday, March 26, 2009

send_file or send_data in link_to_remote

Hi guys,

really really long time i did anything here :).. and no this time not an usual bhaana(excuse) will do but an genuine reason.. was busy building something good.. and it is a secret(just can't disclose it here like this).

Anyhow coming to point.. i was doing a general routine development task for my company and i got hit by a situation like this.. where i was making an ajax call to a controller/action and in response i was sending a stream i.e (send_data and send_file) but as the post was xmlhttp everything was working fine but download was not available (and yeh over here i coded it for download not the inline stuff). What to do now.... i searched it ya ya googled it and response was not a solution that i can rely on(it might not be google's fault must be mine, but why am i favoring it.. it must be google fault lol :)) )

So i solved it my own way by redirecting the update to other action and coding the stream in the newly redirected action :)

Here are some snippets of it....

<%=link_to_remote "Export the result",:url => {:controller => "some_controller", :action => "ask_to_export"},:with => "'record_ids=1-2-3-4-5-6'" -%>

def ask_to_export
render :update do |page|
page.redirect_to :action => "process_and_export", :record_ids => params[:record_ids]
end
end

def process_and_export
outfile = ""
CSV::Writer.generate(outfile) do |csv|
csv << ["praveen","kumar","sinha",1,2,3,nil,""]
end
send_data outfile, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; filename=report_#{Time.now.to_f.to_s}.csv"
end

I hope this must be helpful to some one stucked over here and googling it

Thanks :)

Sunday, March 8, 2009

NetBook ASUS EeePC

O my god!!! i got this small little machine.... the coolest gadget till yet. and have some snaps ....



Tech specs are intel Atom Duo, 2 GBytes of Ram, the ddr2 one and the sleek and so bright 10 inches screen
and only 5% keyboard is what it all sacrificed it for this look.. apart from the optical drive and now i have to do something to not to miss it :))

Earlier had one dell but due to some faults in the system
its wifi stopped working and its Ram was Half of Gb and its upgrading was costing me about Rs. 2200.00, which was a bit more than i actually expected so i went to NehruPlace and changed the system it self and got this new stylish looking baby... it will do my needs and it is quite a bit handy too so small in dimension and good enough battery life of about 5 hrs and keyboard is not bothering me too either although its right shift key is a bit awkwardly placed :)

I am looking it for some more stuff to get onboard but that will be something which i think is an ongoing process for a person like me :)

That is it of for me.. the biggie news of the week

Monday, February 23, 2009

SSL and RubyonRails

Hi guys and gals too :),

Am back after a fair long interval this time, ya ya same old reason was busy with office and all. But recently did something good(if not unusual).
And the heading is telling it very correct, did implemented the SSL and used https for some of my pages in rubyonrails.

As many of my readers know, i am new to ubuntu so is new to apache too(initially i used to think, these dealings are sort of system admin stuff) but hey after all it is a software and some bit of configurations.. so i thought lets do it.. and i did it...

So now trimming all the conversation.. the aim of my application was to implement https(SSL) for the "payment gateway" and "pick package" page
and here is the solution
for the prerequisite purpose i assume that you have apache and ruby on rails setup in your system and you have an ROR application which needs https protocol for some of the pages

Step 00: Create a ssl certificate signed by yourself (by following these steps)
install the ssl-cert package
sudo aptitude install ssl-cert

# to create a self-signed certificate.. it will open several dialog boxes, keep on answering the question in correct format(some 7-8 inquiries are there) and at the end you will have your self-signed certificate
sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /path/to/ssl/certictare/selfsigned.pem

Step 01: first of all enable the modes(for apache)
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod rewrite
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod headers


Step 02: set the virtual host
goto apache root directory(which is at /etc/apache2 in my case) and execute following commands
#to switch to apache directory
cd /etc/apache2

#to disable the default site(which have the default configuration of apache)
sudo a2dissite default
#create a new configuration for virtual host by copying the default site configuration and (rename 'ourapplication' with your application name)
sudo cp sites-available/default sites-available/ourapplication
#to enable our application site configuration in apache
sudo a2ensite ourapplication

Step 03: edit the newly created ourapplication configuration, which is available at /etc/apache2/sites-available/ourapplication using any of your favorite editor
sudo gedit /etc/apache2/sites-available/ourapplication


and it should look something lie this
<VirtualHost *:80>
ServerName ourapplication
ProxyPass / http://somename.com:3000/
ProxyPassReverse / http://somename.com:3000/
</VirtualHost>

<VirtualHost *:443>
ServerName ourapplication
ProxyPass / http://somename.com:3000/
ProxyPassReverse / http://somename.com:3000/
ProxyPreserveHost On
RequestHeader set X_FORWARDED_PROTO 'https'

SSLEngine On
SSLProxyEngine On
SSLCertificateFile /path/to/self/signed/certificate/selfsigned.pem
SSLProxyMachineCertificateFile /path/to/self/signed/certificate/selfsigned.pem
</VirtualHost>


Step 04: We also have to change the proxy configuration, so that proxy request can be handled as we desire it to do
sudo gedit /etc/apache2/mods-available/proxy.conf

change the setting from
previous proxy setting
<proxy>
AddDefaultCharset off
Order deny,allow
Deny from all
Allow from .example.com
</proxy>
to new proxy setting
<proxy>
AddDefaultCharset off
Order deny,allow
Allow from all
</proxy>

Step 05: To reload the new setting so that apache can follow our rule..
sudo /etc/init.d/apache2 force-reload
(but it should not give any error, and it will not if no wrong is done to it form the above mentioned procedures)
if it gives some ouitpit like this
* Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Step 06: Now all apache work is done, you had to do small amount of effort in your rails application and here they
a) install a plugin
ruby script/plugin install ssl_requirement

b) include it in the application controller so that it can use ssl using
include SslRequirement

c) to use https on any particular action of some controller use
class EcommerceController < ApplicationController
ssl_required :action_name_1, :action_name_2, :action_name_3
# some more codes..............
end


if you have any query just drop me a comment, otherwise all is well as expected :)

Honda Civic & A/C problems.

Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...