Posted by Dhaval Parikh on May 20, 2009
Hey all
After a long time I am posting something about stock markets. The reason is everyone was bearish and no one was ready to listen to ne thing negative so I stopped posting. And thats 100% true. Now I am seeing people coming back (especially my friends who were trading aggressively in the last bull run) and asking me about their holdings and talking about stock markets especially after the 2 upper circuits on back of election results.
Just before few weeks most of the analyst described every rally as a bear market rally. No one was expecting the NIFTY to cross 3800 levels. Everyone seemed to be bearish on market. Everyone was backing their views by talking about bad economic conditions, negative global cues blah blah.. Now with the election results things seem to have changed totally. People are no longer talking about global cues, economic condition and it seems that bulls have returned into business. Now suddenly India seems to have decoupled from global markets. and with the same govt coming into power people have again started talking about 8% GDP and so on.
What has changed in these few days that people have forgotten every thing and are just buying blindly? Brokerages are talking about 20k levels on sensex http://in.news.yahoo.com/48/20090520/1237/tbs-market-watchers-predict-new-high-by.html. FII’s suddenly overweight on India and you will see every thing turned Bullish from Bearish. (Especially those who were bearish just 2 weeks back
This sounds really funny to me but most importantly its very confusing for those who are stuck with their holding which they bought when markets was @ 18k-20k and are thinking to hold or sell.
According to me the current movement in the market is because of over excitement and is overdone. People are putting in money blindly since there is a left out feeling. Every thing is moving up.. Personally I don’t feel that this rally should sustain. People already holding stocks should book out profits and stay with cash. “CASH IS KING” and no one will argue that. Profit booking to my mind is never a bad thing to do. If your investments have doubled book out capital and hold on to the profits. I just noticed that even companies which have posted net loss are moving up 10% – 20% every day. Reminds me of the last leg of the bull rally when each and every single stock was moving.
Ne ways having said that I think one must book profits and we could see nifty coming back to 3800 levels or even less going forward. And as and when economic conditions improve one should again start investing or buy stocks which are available at dirt cheap price going forward.
Though I cannot term this move as a bear market rally or a bull market but I am sure about one thing that the valuations doesn’t seem to be cheap any more and economic environment has not changed. So profit booking will be the ideal strategy.
Hope you have liked this post. If you have any questions pls post a comment and I shall reply.
Thanks
Tags: bear market rally, new bull run, nifty views, Stock Markets
Posted by Dhaval Parikh on May 20, 2009
Most of the new websites are having the feature of localization or internationalization on their site. With introduction of rails 2.3 this feature is provided by default But if you are still working in rails 2.0 or 2.1 then GlobalLite is the solution for you.. http://code.google.com/p/globalite/
How ever while implement it in one of my projects I noticed that the localized date time module used in the plugin has a problem when you have time_select tag in your form.
So when you use a time_select tag in your form it will generate an error message “Can’t convert nil into string”. The problem is in the file called localized_action_view.rb which you will find in plugins/globalite/lib/rails folder.
Apply the code below to get it fixed
def select_month(date, options = {}, html_options = {})
if options[:locale]
@original_locale = Locale.code
Locale.code = options[:locale]
end
val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ”
if options[:use_hidden]
hidden_html(options[:field_name] || ‘month’, val, options)
else
month_options = []
monthnames = :date_helper_month_names.l
abbr_monthnames = :date_helper_abbr_month_names.l
month_names = options[:use_month_names] || (options[:use_short_month] ? abbr_monthnames : monthnames)
month_names.unshift(nil) if month_names.size < 13
1.upto(12) do |month_number|
month_name = if options[:use_month_numbers]
month_number
elsif options[:add_month_numbers]
month_number.to_s + ‘ – ‘ + month_names[month_number]
else
month_names[month_number]
end
month_options << ((val == month_number) ?
%(<option value=”#{month_number}” selected=”selected”>#{month_name}</option>\n) :
%(<option value=”#{month_number}”>#{month_name}</option>\n)
)
end
@selector = select_html(options[:field_name] || ‘month’, month_options, options)
Locale.code = @original_locale if options[:locale]
return @selector
end
# Locale.code = @original_locale if options[:locale]
# return @selector
end
You may even Comment the date module in the code plugins/globalite/lib/rails/localized_action_view.rb
this will make use of default rails date time. so nothing will get affected if you do this. But the solution mentioned about is a better one.
Njoi the power of Internationalization and make sure site global.
Tags: globalite plugin, globalite plugin error, internationalization in rails, localization in rails, ruby on rails, time_select tag error
Posted by Dhaval Parikh on May 5, 2009
Older version of file_coulmn plugin is not working in rails 2.2.
If you want to get working in rails 2.2 then you need to modify file_coulmn.rb file.
Update the line #619 in vendor/plugins/file_column/lib/file_column.rb from
Inflector.underscore(self.name).to_s,
to
ActiveSupport::Inflector.underscore(self.name).to_s,
Or you can download the latest plugin from the github.com: http://github.com/rust/file_column/
If you are looking to implement the old File column plugin you may visit
http://blog.dhavalparikh.co.in/2008/02/file-column-plugin/
Tags: file column, file upload in rails, filecolumn plugin, ruby on rails
Posted by Dhaval Parikh on Apr 4, 2009
Well I m going to cover the topic how to generate charts using rails. there are number of options available such as follows
Here are the plugins through which we can generate charts in rails
1) Gruff charts http://nubyonrails.com/articles/gruff-graphing-library-for-ruby
2) Sparklines http://nubyonrails.com/articles/sparklines-graph-library-for-ruby
3) Scruffy charts http://scruffy.rubyforge.org/
4) Ziya plugin http://liquidrail.com/2007/1/4/charting-the-rails/ (flash charts)
I found google charts the best of these..( ofcourse that suited my requirements). The gc4r plugin in rails is really helpful for easy integration of google charts in your rails application.
Here is how Charts are generated by Google API.
Install: ruby script/plugin install http://gc4r.googlecode.com/svn/trunk/
Supported features:
1.line chart
2.bar chart (vertical and horizontal)
3.pie chart (both 2D and 3D)
4.title, title color and size
5.data colors and legend
6.data scaling
7.multiple axis
#Controller
use_google_charts
#In method of controller
Default Chart or Hello World Chart
@chart = GoogleChart.new
Set the width of chart
@chart = GoogleLineChart.new :width => 300, :height => 200
Set the data
dataset = GoogleChartDataset.new :data => [10,50,4,10,16]
data = GoogleChartData.new :datasets => dataset
@chart = GoogleLineChart.new :width => 300, :height => 200
@chart.data = data
add a chart title
dataset = GoogleChartDataset.new :data => [10,50,4,10,16]
data = GoogleChartData.new :datasets => dataset
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => ‘Java vs. Ruby Montly Job Opportunities’
@chart.data = data
Set title in array instead of string
dataset = GoogleChartDataset.new :data => [10,50,4,10,16]
data = GoogleChartData.new :datasets => dataset
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => ['Java vs. Ruby', 'Montly Job Opportunities']
@chart.data = data
Multiple data in chart
dataset1 = GoogleChartDataset.new :data => [10,50,4,10,16]
dataset2 = GoogleChartDataset.new :data => [99, 81, 25, 54, 80]
data = GoogleChartData.new :datasets => [dataset1, dataset2]
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => ['Java vs. Ruby', 'Montly Job Opportunities']
@chart.data = data
Add colors
dataset1 = GoogleChartDataset.new :data => [10,50,4,10,16],:color => ‘FF0000?
dataset2 = GoogleChartDataset.new :data =>[99,81,25,54,80],:color => ‘0000FF’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => ['Java vs. Ruby', 'Montly Job Opportunities']
@chart.data = data
Define legend
dataset1 = GoogleChartDataset.new :data =>[10,50,4,10,16],:color => ‘FF0000?, :title => ‘Java’
dataset2 = GoogleChartDataset.new :data=>[99,81,25,54,80],:color => ‘0000FF’, :title => ‘Ruby’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => ['Java vs. Ruby', 'Montly Job Opportunities']
@chart.data = data
Define Axis
dataset1 = GoogleChartDataset.new :data =>[10,50,4,10,16],:color => ‘FF0000?, :title => ‘Java’
dataset2 = GoogleChartDataset.new :data=>[99,81,25,54,80],:color => ‘0000FF’, :title => ‘Ruby’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
axis = GoogleChartAxis.new :axis => [GoogleChartAxis::LEFT, GoogleChartAxis::BOTTOM]
@chart = GoogleLineChart.new :width => 250, :height => 150, :title => ['Java vs. Ruby', 'Montly Job Opportunities']
@chart.data = data
@chart.axis = axis
Define Right and X Axis
dataset1 = GoogleChartDataset.new :data=> [10,50,4,10,16],:color => ‘FF0000?, :title => ‘Java’
dataset2 = GoogleChartDataset.new :data=>[99,81,25,54,80],:color => ‘0000FF’, :title => ‘Ruby’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
axis = GoogleChartAxis.new :axis => [GoogleChartAxis::LEFT, GoogleChartAxis::BOTTOM, GoogleChartAxis::RIGHT, GoogleChartAxis::BOTTOM]
@chart = GoogleLineChart.new :width => 300, :height => 200, :title => ['Java vs. Ruby', 'Montly Job Opportunities']
@chart.data = data
@chart.axis = axis
Define Bar Chart:
@chart = GoogleBarChart.new :width => 300, :height => 200, :title => ['Java vs. Ruby', 'Montly Job Opportunities']
Define 3D Pie Chart:
@chart = GooglePieChart.new :width => 400, :height => 200, :title => ['Java vs. Ruby', 'Montly Job Opportunities'], :chart_type => GooglePieChart::PIE_3D
#view:
<%= image_tag @chart.to_url %>
Tags: charts in rails, gc4r, gc4r in rails, google charts, ruby on rails
Posted by Dhaval Parikh on Apr 4, 2009
Want to do benchmark or stress testing on your rails applications? Then look @ httpref
What is httpref?
Httperf is a tool for measuring web server performance. It provides a flexible facility for generating various HTTP workloads and for measuring server performance. The focus of httperf is not on implementing one particular benchmark but on providing a robust, high-performance tool that facilitates the construction of both micro- and macro-level benchmarks. The three distinguishing characteristics of httperf are its robustness, which includes the ability to generate and sustain server overload, support for the HTTP/1.1 and SSL protocols, and its extensibility to new workload generators and performance measurements.
Source url : – http://www.hpl.hp.com/research/linux/httperf/
Steps to do
1) download httpref from http://sourceforge.net/projects/httperf/
2) install the tool
3) check out commands on http://www.hpl.hp.com/research/linux/httperf/httperf-man-0.9.pdf
Thats all
Find out how many http requests your site can handle..
Njoi
For more info you can post comments here
Tags: ruby on rails, Stress/Benchmark testing in rails
Posted by Dhaval Parikh on Apr 2, 2009
The code Below will help to export the data in excel in Ruby on Rails
#Controller
class UserController < ApplicationController
def export
headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Disposition'] = 'attachment; filename="report.xls"'
headers['Cache-Control'] = ''
@users = User.find(:all)
end
#View
export.html.erb
<%= link_to "Export as Excel", export_person_url %>
_report.html.erb
<table border="1">
<tr>
<th>Name</th>
</tr>
<% @users.each do |u| %>
<tr>
<td><%= u.name %></td>
<% end %>
</tr>
</table>
Please note :- This method might might be deprecated. You may visit http://spreadsheet.rubyforge.org/ for more info. Thanks
Tags: export excel xls, export to xls in rails, rails xls, ruby on rails