<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shanison</title>
	<atom:link href="http://www.shanison.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shanison.com</link>
	<description>For a better future with technology and stock investment</description>
	<lastBuildDate>Sun, 19 May 2013 08:23:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Ruby 1.9.2 Hash Syntax Changes</title>
		<link>http://www.shanison.com/2013/05/19/ruby-1-9-2-hash-syntax/</link>
		<comments>http://www.shanison.com/2013/05/19/ruby-1-9-2-hash-syntax/#comments</comments>
		<pubDate>Sun, 19 May 2013 08:11:57 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1364</guid>
		<description><![CDATA[Symbol is greatly used in Ruby programs. It is an object of Symbol class. It represents some strings inside the Ruby interpreter. When you think that the string you are going to create would probably going to be reused somewhere again, then you should consider using symbols. The benefit of Symbol is really performance. During [...]]]></description>
			<content:encoded><![CDATA[<p>Symbol is greatly used in Ruby programs. It is an object of Symbol class. It represents some strings inside the Ruby interpreter. When you think that the string you are going to create would probably going to be reused somewhere again, then you should consider using symbols. The benefit of Symbol is really performance. During a Ruby program&#8217;s execution, as long as the symbol contents are the same, they are actually the same object, so it will refer to the same object in memory. e.g. </p>
<pre class="ruby" name="code">
user1 = {:name => "Shanison"}
user2 = {:name => "Lin"}
</pre>
<p>Above codes actually only creates 1 symbol object, 2 strings object and 2 hash objects. Imagine that you are creating a lot of hash, the :name symbol would save a lot of object creation. You can even query all the symbols in your program:</p>
<pre class="ruby" name="code">
Symbol.all_symbols # return an array of symbols
</pre>
<p>Enough about the introduction to symbols. What I want to talk about is actually about Hash. When constructing a hash, you would use symbol as the keys quite often. Probably due to this reason, in Ruby 1.9 it introduced a new Syntax for Hash.</p>
<pre class="ruby" name="code">
user1 = {name: "Shanison"}
user2 = {name:  "Lin"}
</pre>
<p>At first glance, this looks pretty much like syntax for defining javascript object. Looks great. However, take note that the colon must be right after the key without any space. So it is not exactly the same as javascript object syntax.</p>
<pre class="ruby" name="code">
user1 = {name : "Shanison"} # This will cause syntax error
</pre>
<p>This shorten syntax sometimes looks short and sweet when you pass it as a parameters.</p>
<pre class="ruby" name="code">
server = Server.new(
addr: "192.167.123.1",
user: 'id_'
)
# Compares to Below
server = Server.new(
:addr => "192.167.123.1",
:user => 'id_'
)
</pre>
<p>However, do note that this syntax only works for symbol keys. So if you want to use strings or numbers as the hash keys, you can&#8217;t write the syntax in this way. e.g. Below code would return you error:</p>
<pre class="ruby" name="code">
user1 = {"name": "Shanison"}  # Give Syntax error
user2 = {1:  "Lin"} # Give Syntax error
</pre>
<p>You can even mix the syntax when your hash has both symbol and numbers as keys, although the combination looks funny.</p>
<pre class="ruby" name="code">
user1 = {name: "Shanison", 1 => "one"}
</pre>
<p>However, when your value is also a symbol, this syntax looks really funny:</p>
<pre class="ruby" name="code">
user1 = {name: :source}
</pre>
<p>Due to above reasons, I still prefer the old syntax. It is just an options and personal preference, so there is no right or wrong in which syntax you adopt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2013/05/19/ruby-1-9-2-hash-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nokogiri with open-uri returns blank file</title>
		<link>http://www.shanison.com/2013/03/25/nokogiri-with-open-uri-returns-blank-file/</link>
		<comments>http://www.shanison.com/2013/03/25/nokogiri-with-open-uri-returns-blank-file/#comments</comments>
		<pubDate>Mon, 25 Mar 2013 14:36:15 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1330</guid>
		<description><![CDATA[I met one very strange problem today. Below code is working fine on my local machine under ruby 1.8.7 with nokogiri version 1.5.9: require 'nokogiri' require 'open-uri' require 'net/http' doc = Nokogiri::HTML(open('http://shareinvestor.com')) puts doc.text However above code is giving me problems on production servers with ruby 1.8.7 and nokogiri version 1.5.9. The last line returns [...]]]></description>
			<content:encoded><![CDATA[<p>I met one very strange problem today.</p>
<p>Below code is working fine on my local machine under ruby 1.8.7 with nokogiri version 1.5.9:</p>
<pre name="code" class="ruby">require 'nokogiri'
require 'open-uri'
require 'net/http'

doc = Nokogiri::HTML(open('http://shareinvestor.com'))
puts doc.text
</pre>
<p>However above code is giving me problems on production servers with ruby 1.8.7 and nokogiri version 1.5.9. The last line returns empty string instead of the whole html. The only difference between the two servers is the ruby patch levels:<br/><br />
my local machine: ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.6.0]<br />
production server: ruby 1.8.7 (2009-3-1 mbari 8B/0&#215;8770 on patchlevel 72) [i686-linux]<br />
<br/><br />
So I thought the open-uri.rb might be different, checking the open-uri.rb found out that they are exactly the same. So I can&#8217;t think of any cause that is causing this problem.  <br/></p>
<p>Anyway below is the fix if you met this issue. You have to use File.read to read the html opened by open-uri.</p>
<pre name="code" class="ruby">require 'nokogiri'
require 'open-uri'
require 'net/http'

doc = Nokogiri::HTML(File.read(open('http://shareinvestor.com').path))
puts doc.text # this one now returns the correct html
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2013/03/25/nokogiri-with-open-uri-returns-blank-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrade Ruby on Rails Application from 2.2.2 to 3.2.12</title>
		<link>http://www.shanison.com/2013/03/18/upgrade-ruby-on-rails-application-from-2-2-2-to-3-2-12/</link>
		<comments>http://www.shanison.com/2013/03/18/upgrade-ruby-on-rails-application-from-2-2-2-to-3-2-12/#comments</comments>
		<pubDate>Mon, 18 Mar 2013 11:42:46 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1291</guid>
		<description><![CDATA[Ruby on Rails has changed a lot these few years. There are some security issues found recently. One of them is regarding the vulnerability in the JSON parser that comes with Active Support. You can read more here. However, the patch provided is only available for Rails 2.3.x and 3.0.x. I checked the code for [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Ruby on Rails</strong> has changed a lot these few years. There are some security issues found recently. One of them is regarding the vulnerability in the JSON parser that comes with Active Support. You can read more <a href="https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/1h2DR63ViGo">here</a>. However, the patch provided is only available for Rails 2.3.x and 3.0.x. I checked the code for Rails 2.2.2 and found that this version is affected as well. Without the official patch, I have to come up with my own patch for that. This is a serious problem if your application is not up to date with Rails. I developed a Ruby on Rails website that provides stocks information about three years ago with a small team, which stayed with Rails 2.2.2. Now it is time to upgrade it to the latest Rails 3.2.12. Below is how I did it and some of the major changes that has to be made in the code.</p>
<p>&nbsp;</p>
<p>The whole project structure has changed quite a lot between Rails 2 and Rails 3 especially with the introduction of asset pipeline and bundlers. The easier way to upgrade your apps is to create a blank new Rails 3 apps and move in all the new folders into your old Rails 2 apps. For the files with the same names under same directories e.g. config/environments.rb, config/environments/production.rb, there are some API/format changes, so you need to compare the contents and see how to merge them. After you have done that, you can try to start your rails applications, which I believe the server can&#8217;t even be started. You should check every single error messages shows up in the console and fix them one by one until everything is fine. Below are some major changes that I met with.</p>
<p>&nbsp;</p>
<ol>
<li>For the app/controllers/application.rb, it should be named as application_controller.rb now. Otherwise &#8216;uninitialized constant ApplicationController&#8217; would be thrown.</li>
<li>ENV['RAILS_ENV'] is now deprecated, use Rails.env instead.</li>
<li>Rails.root class used to be String. Now it is changed to PathName. So you can&#8217;t do things like below:
<pre name="code">File.read(Rails.root + "/config/streaming_config.yml")</pre>
</li>
<li>lib folders are not auto loaded. So you will see some missing constant errors. To auto load the lib folders add below two lines to the config/application.rb.
<pre name="code" class="ruby">config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]</pre>
</li>
<li>filter_parameter_logging is no longer available. To filter out the parameters you can do it in the config/application.rb.
<pre name="code" class="ruby">config.filter_parameters += [:password]</pre>
</li>
<li>You cannot access controller methods in the view with @controller anymore. You have to use controller instead.</li>
<li>For action view rendering, you no longer need to call h(string) to escape HTML output, it is on by default in all view templates. In Rails 2 you need to do below to escape the parameters, if not, you are vulnerable for XSS attacks.
<pre name="code" class="ruby"><%= h @params[:user_name] %></pre>
<p>In Rails 3, this html escape is on by default. However if the variable or contents you are trying to render contains html, and you want to render the html you have to explicitly call raw methods or html_safe method.</p>
<pre name="code" class="ruby"><%= raw @page.content %></pre>
<pre name="code" class="ruby"><%= @page.content.html_safe %></pre>
<p>I forget to put raw or html_safe in some of the views, and it renders escaped html instead. So you may want to check across the whole site to make sure everything is alright.
</li>
<li>For form_tag and form_for, you need to use <%= %> instead of <% %>, otherwise the form won&#8217;t be rendered at all.</li>
<li>will_paginate  2 won&#8217;t work with Rails 3. Have to upgrade to will_paginate 3 otherwise uninitialized constant ActiveRecord::Associations::AssociationCollection error will be thrown.</li>
<li>Array.paginate will throw error.The Array#paginate method still exists, too, but is not loaded by default. If you need to paginate static arrays, first require it in your code: require &#8216;will_paginate/array&#8217;</li>
<li>For active record, save(false) changed to
<pre name="code" class="ruby">save(:validate => false)</pre>
</li>
<li>request.request_uri changed to request.url</li>
<li>REXML::Document is not auto loaded, need to explicitly require it before using.
<pre name="code" class="ruby">require 'rexml/document'</pre>
</li>
<li>rake API changes. The :needs => :environments is deprecated. In Rails 2 :
<pre name="code" class="ruby">task :task_name, :argument_name, :needs => :environment do |t,args|
    # ...
 end</pre>
<p>In Rails 3, you have to do the following:
<pre name="code" class="ruby">task :task_name, [:argument_name] => :environment do |t,args|
    # ...
 end</pre>
</li>
<li>params[:path] used to be an array of the path split by slash. e.g. you might see the value as  ['user', 'details.html'], now it is a string /user/details. Note that params[:path] doesn&#8217;t contains the format.</li>
<li>interpreate_status is not in use any more. You can use Rack::Utils::HTTP_STATUS_CODES[status_code] to do the same thing.</li>
<li>Mailer API changes. In Rails 2, you would call deliver_welcome_email or create_welcome_email. This has been deprecated in Rails 3.0 in favour of just calling the method name itself. So you can call Mailer.welcome_email.</li>
<li>Mail API changes. In Rails 2 you define a mailer like below (this example is copied from rails guide)
<pre name="code" class="ruby">class UserMailer < ActionMailer::Base
  def welcome_email(user)
    recipients    user.email
    from          "notifications@example.com"
    subject       "Welcome to My Awesome Site"
    sent_on       Time.now
    body          {:user => user, :url => "http://example.com/login"}
  end
end</pre>
<p>However in Rails 3 above codes has to be changed to below:</p>
<pre name="code" class="ruby">class UserMailer < ActionMailer::Base
  def welcome_email(user)
    @user = user
    @url =  "http://example.com/login"
    mail(
        :to            => user.email
        :from       =>    "notifications@example.com"
        :subject    =>   "Welcome to My Awesome Site"
        :date        =>       Time.now
    )
  end
end</pre>
</li>
<li>If a action name is not defined in the controller but the corresponding views file exists, in Rails 2, it will call method_missing. However in Rails 3, it won&#8217;t call method_missings. Thus in the help controller we can&#8217;t use the method_missing to dynamic rendering the views.</li>
</ol>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2013/03/18/upgrade-ruby-on-rails-application-from-2-2-2-to-3-2-12/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Invest in Gold in Singapore</title>
		<link>http://www.shanison.com/2012/10/07/how-to-invest-in-gold-in-singapore/</link>
		<comments>http://www.shanison.com/2012/10/07/how-to-invest-in-gold-in-singapore/#comments</comments>
		<pubDate>Sun, 07 Oct 2012 13:24:12 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Investment]]></category>
		<category><![CDATA[gold]]></category>
		<category><![CDATA[Technical Analysis]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1221</guid>
		<description><![CDATA[I still remember the day that I could buy a can of coca cola at 80cents from a vending machine 3 years ago. Now you need to pay S$1.2 for that. 40 cents increase looks small from the absolute amount, but that is actually 50% increase in price! This is how terrible the inflation is [...]]]></description>
			<content:encoded><![CDATA[<p><a class="lightbox" title="gold" href="http://www.shanison.com/wp-content/uploads/2012/10/gold.jpg"><img class="alignright size-full wp-image-1271" title="gold" src="http://www.shanison.com/wp-content/uploads/2012/10/gold.jpg" alt="" width="208" height="186" /></a>I still remember the day that I could buy a can of coca cola at 80cents from a vending machine 3 years ago. Now you need to pay S$1.2 for that. 40 cents increase looks small from the absolute amount, but that is actually 50% increase in price! This is how terrible the inflation is for these few years. At this high inflation environment, the interest rate is as low as equal to zero. Your money in the bank is slowly dwindling away if you don&#8217;t do anything to it. Among the various choice of investment, Gold is a popular choice for hedging against inflation.</p>
<p>If you are thinking of investing in gold or buying gold, here are a few things you can do in Singapore.</p>
<p>&nbsp;</p>
<p><strong>Buying Physical Gold</strong></p>
<p>If you are thinking of buying physical gold, the easiest way is buying jewelry, where you can easily find those jewelry shops in Singapore especially in Little India as Indian loves buying gold. The other way is buying gold coins or gold bar. There are some trading companies doing this e.g. <a title="GoldPrice" href="http://www.goldprice.com.sg" target="_blank">GoldPrice</a> You can either keep the gold at home or some bank. DBS provides Safe Deposit Boxes service, where you can store your golds there without worrying about being stolen.</p>
<p>Trading gold in this way is troublesome and inefficient. There are some company that allow you buy gold bullion online at live gold prices. You may want to check out <a title="BullionVault" href="http://www.bullionvault.com" target="_blank"><span style="color: #333399;">gold at BullionVault</span>.</a></p>
<p>&nbsp;</p>
<p><strong>Gold ETFs</strong></p>
<p>Exchange-Traded Fund (ETF) is an investment fund that can be traded like stocks on stock exchange. There are many physically backed gold ETF in the world. One of the most popular ones is SPDR Gold ETF Trust. SPDR® Gold Shares is the first gold-backed exchange-traded fund to be listed in Asia. Sponsored by the World Gold Trust Services LLC, the SPDR® Gold Shares are designed to track the price of gold and trade like any stock on the exchange. Below is the share price for SPDR Gold Shares, from the charts you can tell that it follows the actual Gold price.</p>
<div id="attachment_1241" class="wp-caption aligncenter" style="width: 310px"><a class="lightbox" title="SPDR Gold Shares" href="http://www.shanison.com/wp-content/uploads/2012/10/SPDR_Gold.png"><img class="size-medium wp-image-1241" title="SPDR Gold Shares" src="http://www.shanison.com/wp-content/uploads/2012/10/SPDR_Gold-300x194.png" alt="SPDR Gold Shares Price" width="300" height="194" /></a><p class="wp-caption-text">SPDR Gold Shares Price</p></div>
<p>&nbsp;</p>
<p><strong>Gold Miner Stocks</strong></p>
<p>Invest in Gold miner stocks can be an alternative way to invest in Gold. However, do note that Gold Miner Stocks&#8217; share price won&#8217;t follow Gold price exactly. If gold price go up 10%, the share price could go up possibly 20%. If gold price drop 10%, the share price could drop more than that. So in another word, investing in gold miner stocks is more risky. High risk comes with higher returns. If you expect gold to be as bullish as previous few years, then investing in gold miner stocks may be a good options.</p>
<p>&nbsp;</p>
<p>LionGold Corp is an SGX-listed investment holding company focussing on gold mining, mine development and exploration. The company changed its name from Think Environmental to LionGold after adopting its gold-focused strategy in 2011. From the chart below, you can also tell that it is much more volatile than gold. So trade with caution.</p>
<div id="attachment_1244" class="wp-caption aligncenter" style="width: 310px"><a class="lightbox" title="LionGold_chart_20121007" href="http://www.shanison.com/wp-content/uploads/2012/10/LionGold_chart_20121007.png"><img class="size-medium wp-image-1244" title="LionGold_chart_20121007" src="http://www.shanison.com/wp-content/uploads/2012/10/LionGold_chart_20121007-300x194.png" alt="Lion Gold TA Chart" width="300" height="194" /></a><p class="wp-caption-text">Lion Gold TA Chart</p></div>
<p>&nbsp;</p>
<p>This article is not meant to give you suggestion on what ETF or stock to trade but some general information on how to buy gold in Singapore. So trade at your own risk. Interesting thing is that Warrant Buffet said that he will never invest in Gold.</p>
<p>&nbsp;</p>
<blockquote><p><em>&#8220;When we took over Berkshire, it was selling at $15 a share and gold was selling at $20 an ounce. Gold is now $1600 and Berkshire is $120,000. Or you can take a broader example. If you buy an ounce of gold today and you hold it at hundred years, you can go to it every day and you could coo to it and fondle it and a hundred years from now, you’ll have one ounce of gold and it won’t have done anything for you in between. You buy 100 acres of farm land and it will produce for you every year. You can buy more farmland, and all kinds of things, and you still have 100 acres of farmland at the end of 100 years. You could you buy the Dow Jones Industrial Average for 66 at the start of 1900. Gold was then $20. At the end of the century, it was 11,400, and you would also have gotten dividends for a hundred years.&#8221; &#8211; Warrant Buffet</em></p></blockquote>
<p>&nbsp;</p>
<p>From investing perspective, I agree with that invest on stocks may give you better return, however, stock market comes with much higher risk. So diversify your investment in stocks, gold, bonds and property is much more ideal for me personally. The weight to invest in each, of course, depends on your risk appetite.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2012/10/07/how-to-invest-in-gold-in-singapore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unset/Remove Apache Response Header &#8211; Protect your server information</title>
		<link>http://www.shanison.com/2012/07/05/unset-apache-response-header-protect-your-server-information/</link>
		<comments>http://www.shanison.com/2012/07/05/unset-apache-response-header-protect-your-server-information/#comments</comments>
		<pubDate>Thu, 05 Jul 2012 13:18:58 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1175</guid>
		<description><![CDATA[When a browser submit a request for a page to the apache web server, it will send back the response data as well as response headers. The response headers usually contains important information like response Status, Content Type, Date and Time of Response etc. However, sometimes if you don&#8217;t configure the web server properly, it [...]]]></description>
			<content:encoded><![CDATA[<p>When a browser submit a request for a page to the apache web server, it will send back the response data as well as response headers. The response headers usually contains important information like response Status, Content Type, Date and Time of Response etc. However, sometimes if you don&#8217;t configure the web server properly, it will expose some important information about the server in the response header. The below screenshot shows a poor configured server:</p>
<div id="attachment_1177" class="wp-caption aligncenter" style="width: 310px"><a class="lightbox" title="server_headers" href="http://www.shanison.com/wp-content/uploads/2012/07/server_headers.png"><img class="size-medium wp-image-1177" title="server_headers" src="http://www.shanison.com/wp-content/uploads/2012/07/server_headers-300x162.png" alt="Poor Configured Response Headers" width="300" height="162" /></a><p class="wp-caption-text">Poor Configured Response Headers</p></div>
<p>&nbsp;</p>
<p>You can see that from the response header I can tell that the website is hosted using Apache server and furthermore it is using Phusion Passenger V 3.0.11. If there is any vulnerability issue with this version of Passenger, the hacker can easily use this information and hack the website! So the solution is to hide this kind of information.</p>
<p>&nbsp;</p>
<p>To do that you have to use the <a title="Apache Header Directive" href="http://httpd.apache.org/docs/2.0/mod/mod_headers.html" target="_blank">Apache Header Directive</a>. Basically this Header Directive is processed just before the response is sent back to the network, so it allows you to overwrite/modify the response header set by your application.</p>
<p>&nbsp;</p>
<p><span style="font-weight: bold;">Load Apache Headers Module. </span>First, make sure you have header module installed, use the following command to see all the loaded modules:</p>
<pre class="ruby" name="code">httpd -M</pre>
<p>Check headers_module is in the list. If header module is not loaded, you have to load it in the httpd config.</p>
<p><strong>Locate your httpd config files</strong>. If you are not sure where is your config files, run the following command to show the compile settings:</p>
<pre class="ruby" name="code">httpd -V</pre>
<p>It should show HTTPD_ROOT as well as SERVER_CONFIG_FILE. In my case, the following is the output for this two settings:</p>
<p><strong><em>-D HTTPD_ROOT=&#8221;/usr/local/httpd&#8221;</em></strong></p>
<p><strong><em>-D SERVER_CONFIG_FILE=&#8221;conf/httpd.conf&#8221;</em></strong></p>
<p>From here, you knows that your httpd.conf location is /usr/local/httpd/conf/httpd.conf. After you locate httpd.conf, edit this file and add the following line to load the header module</p>
<pre name="code" class="ruby">LoadModule headers_module modules/mod_headers.so</pre>
<p>Now, do httpd -M again, you should see the loaded modules include headers_module.</p>
<p>After headers_module is loaded, include the following lines of config in the httpd.conf, if the settings are there, make sure it is the correct value.</p>
<pre name="code" class="ruby">ServerSignature Off
ServerTokens Prod</pre>
<p>Normally apache would display a trailing footer line, which includes information like server name, version etc,  under server generated documents, e.g. error message etc. So ServerSignature Off would turn this off. So it won&#8217;t include this trailing footer line. ServerTokens Prod will only return &#8220;Apache&#8221; in the Server header without any version number.  For details explanation, refer to this <a href="http://httpd.apache.org/docs/current/mod/core.html">apache documentation</a>.</p>
<p>&nbsp;</p>
<p>Further more, we should totally unset the Server header and X-Powered-By header, so include the following lines in the httpd.conf as well.</p>
<pre name="code" class="ruby">
# If mod_headers module is included, we will disable the Server response header totally
&lt;IfModule mod_headers.c&gt;
  Header unset Server
  Header unset X-Powered-By
&lt;/IfModule&gt;</pre>
<p>With the above changes, you should have already unset or removed those apache response headers that expose important security informations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2012/07/05/unset-apache-response-header-protect-your-server-information/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Oracle SQL Injection</title>
		<link>http://www.shanison.com/2012/06/18/oracle-sql-injection/</link>
		<comments>http://www.shanison.com/2012/06/18/oracle-sql-injection/#comments</comments>
		<pubDate>Mon, 18 Jun 2012 14:56:38 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1148</guid>
		<description><![CDATA[How could you do SQL Injection with Oracle? SQL Injection are the top one web application security risk ranked according to Open Web Application Security Project (OWASP) . Basically it allows the attackers to attack the database through a website. If the vulnerability is present, hacker could get any data or even drop your database! [...]]]></description>
			<content:encoded><![CDATA[<p>How could you do SQL Injection with Oracle?</p>
<p>SQL Injection are the top one web application security risk ranked according to Open Web Application Security Project (<a title="OWASP" href="https://www.owasp.org/index.php/OWASP_Top_Ten_Project">OWASP</a>) . Basically it allows the attackers to attack the database through a website. If the vulnerability is present, hacker could get any data or even drop your database! Basically it grants the hacker DBA roles. Probably one interesting thing is to look at how we could attack an application using SQL Injection. Let&#8217;s talk about a basic example. I am going to use PHP as an example, although I don&#8217;t quite like using PHP (personal preference). If you are using Ruby on Rails, you shouldn&#8217;t meet this kind of problem.</p>
<pre name="code" class="php">"select name from users where id ='$user_id'";</pre>
<p> The problem lies the direct input of the user input of $user_id in the sql statement. If the user submit the $user_id as follows, it can do any thing:</p>
<pre name="code" class="sql">shanison';update users set is_admin=1 where id='shanison</pre>
<p>With this input, the above sql becomes:</p>
<pre name="code" class="sql">"select name from users where id ='shanison';update users set is_admin=1 where id='shanison'";</pre>
<p>And this is how you can make yourself becomes admin. This is fundamental idea be hide the SQL Injection. However if you do this for a php application connected with oracle with the following codes, what would you get?</p>
<pre name="code" class="sql">$statement = oci_parse($connection, "select name from users where id='$user_id'");
oci_execute($statement);</pre>
<p>You will get the following error ORA-00911: invalid character. The problem lies with the sql statement separator ;. Oracle has a protection that it won&#8217;t allow multiple statements to be exectued at the same time, which makes the above attack impossible. However, there is one smart way to bypass this this limitation, here is one sql statement you can use:</p>
<pre name="code" class="sql">shanison' and (select dbms_xmlquery.newcontext(' declare pragma
autonomous_transaction; begin execute immediate ''update users set
is_admin = 1 where id=:usr'' using ''shanison''; commit;
end;') from dual) is not null or '' = '</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2012/06/18/oracle-sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sell in May and go away 2012</title>
		<link>http://www.shanison.com/2012/06/02/sell-in-may-and-go-away-2012/</link>
		<comments>http://www.shanison.com/2012/06/02/sell-in-may-and-go-away-2012/#comments</comments>
		<pubDate>Sat, 02 Jun 2012 02:05:35 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Stock Market]]></category>
		<category><![CDATA[Trading Psychology]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1136</guid>
		<description><![CDATA[&#8220;Sell in May and go away&#8221; has proven to be true again for 2012. As pointed out by David Silver, over the past 22 years, 15 of them are strong Mays. Only these two years 2010 and 2011, the Sell in May and go away seems to be correct. The below summary chart is taken [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;Sell in May and go away&#8221; has proven to be true again for 2012.  As pointed out by David Silver, over the past 22 years, 15 of them are strong Mays. Only these two years 2010 and 2011, the Sell in May and go away seems to be correct. The below summary chart is taken from seekingalpha.com for reference.</p>
<div id="attachment_1137" class="wp-caption aligncenter" style="width: 310px"><a class="lightbox" title="sell_in_may" href="http://www.shanison.com/wp-content/uploads/2012/06/sell_in_may.png"><img class="size-medium wp-image-1137" title="sell_in_may" src="http://www.shanison.com/wp-content/uploads/2012/06/sell_in_may-300x170.png" alt="" width="300" height="170" /></a><p class="wp-caption-text">May Market Performance (Source-http://seekingalpha.com)</p></div>
<p style="text-align: left;">&nbsp;</p>
<p style="text-align: left;">The Dow Jones recent high of 13338 was actually on May 1 2012. It closed April at 13213 and at the end of May it closed off at 12393. The Dow Jones lost 820 points for 2012 May, that was 6% dropped in May. Yesterday was the beginning of June, and it continued to plunged 2.22%.</p>
<p style="text-align: left;">&nbsp;</p>
<p style="text-align: left;">The <strong>Halloween Indicator </strong>is a variant of &#8220;Sell in May and go away&#8221;. &#8220;It is the belief that the period from November to April inclusively has significatnly stronger growth on average than the other months.&#8221; (source &#8211; Wikipedia) So the strategy to take is that before November you should start to buy some stocks. Of course, you can use Technical Indicators to judge your best entry points in the market instead of following this stock market edge blindly. After that you keep for a few months and before May, you find a chance to take your profit.</p>
<p style="text-align: left;">&nbsp;</p>
<p style="text-align: left;">If we were to follow this, we would have made quite a lot of profit for the past half a year. Crisis are sometimes opportunities. For long term investors, the recent sell off may be a good chance to accumulate some stocks. We may see more sell off in June due to possibility of Grexit.</p>
<p>&nbsp;</p>
<p style="text-align: left;">But the important thing to learn is that every time in crisis, you should get your shopping list ready. Check the stocks that are deeply undervalues and will be able to survive though the crisis. The most important thing is that you must have cash ready! If you have bought a lot of stocks in April this year in the hopes that it may go much higher although since the beginning of 2012, the stock market has rallied so much, you won&#8217;t have much money left when there are some good bargain buys. This is human psychology. When everyone is greedy, you are greedy as well. When everyone is fearful, you are more fearful. So you buy at high and sell at low. You can only contribute money to the rest of stock market players.</p>
<p>&nbsp;</p>
<p style="text-align: left;">So let&#8217;s <strong>get your cash and shopping list ready</strong>. &#8220;When everyone is greedy, you should be fearful! When everyone is fearful, you should be greedy&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2012/06/02/sell-in-may-and-go-away-2012/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Red Dot Ruby Conference 2012</title>
		<link>http://www.shanison.com/2012/05/22/red-dot-ruby-conference-2012/</link>
		<comments>http://www.shanison.com/2012/05/22/red-dot-ruby-conference-2012/#comments</comments>
		<pubDate>Tue, 22 May 2012 13:28:02 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1127</guid>
		<description><![CDATA[I attended the Red Dot Ruby Conference this year at NUS University Cultural Centre last Friday and Saturday. It was a two days event and attracted approximately 200 programmers around the world. Llya Grigorik from google gave a very interesting talk on how to build a faster web using various technics. If you are experiencing [...]]]></description>
			<content:encoded><![CDATA[<p>I attended the Red Dot Ruby Conference this year at NUS University Cultural Centre last Friday and Saturday. It was a two days event and attracted approximately 200 programmers around the world.<br/><br/></p>
<p>Llya Grigorik from google gave a very interesting talk on how to build a faster web using various technics. If you are experiencing slow website problem, you may want to check out his slides at <a href="http://www.igvita.com/slides/2012/html5devconf">Building a Faster Web</a>.<br/><br/></p>
<p>There are also a lot of interesting topics that were discussed during the conference e.g PUBSUB infrastructure, Client Slide Templating, Using Redis to improve site performance, CoffeeScript etc. <br/><br/></p>
<div id="attachment_1129" class="wp-caption aligncenter" style="width: 310px"><a class="lightbox"  title ="reddotrubyconf2012" href="http://www.shanison.com/wp-content/uploads/2012/05/reddotrubyconf20121.jpg"><img src="http://www.shanison.com/wp-content/uploads/2012/05/reddotrubyconf20121-300x199.jpg" alt="Red Dot Ruby Conference 2012" title="reddotrubyconf2012" width="300" height="199" class="size-medium wp-image-1129" /></a><p class="wp-caption-text">Red Dot Ruby Conference 2012</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2012/05/22/red-dot-ruby-conference-2012/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross Domain Ajax Request</title>
		<link>http://www.shanison.com/2012/05/11/cross-domain-ajax-request/</link>
		<comments>http://www.shanison.com/2012/05/11/cross-domain-ajax-request/#comments</comments>
		<pubDate>Fri, 11 May 2012 10:03:44 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1109</guid>
		<description><![CDATA[Cross Domain Ajax Request is something that is prohibited by the browser becomes it violates the Same Origin Policy. According to wikipedia, the term &#8220;origin&#8221; is defined using the domain name, protocol, port number. Two resources are considered to be the same origin if and only if all these values are exactly the same. This [...]]]></description>
			<content:encoded><![CDATA[<p>Cross Domain Ajax Request is something that is prohibited by the browser becomes it violates the Same Origin Policy. According to wikipedia, the term &#8220;origin&#8221; is defined using the domain name, protocol, port number. Two resources are considered to be the same origin if and only if all these values are exactly the same.  This also implies that even if the two resources are in different subdomains, it is not allowed as well.<br/></p>
<p>In order to do cross domain ajax request, there is one way to do it using JSONP. JSONP, which is short for &#8220;JSON with padding&#8221; is a complement to the base JSON data format. It provides a method to request data from a server in a different domain. This is viable because there is no restriction on including third party javascript files in the website. So here is how it works. E.g. you are requesting a server http://sampleserver.com/sampledata.json to return the following json</p>
<pre name="code" class="javascript">{ "name" : "Shanison" }</pre>
<p>Instead of directly requesting this using XMLHttprequest, you use javascript to insert a script tag in the html,</p>
<pre name="code" class="javascript"><script type="text/javascript" src="http://sampleserver.com/sampledata.json"></script></pre>
<p>Now the browser would send the requests and download the response, but the problem is that the response is JSON instead of javascript. So the trick here is that for server instead of returning JSON, it returns a function call with the JSON:</p>
<pre name="code" class="javascript">callBack({ "name" : "Shanison" })</pre>
<p>After the javascript is downloaded, it will call the method callBack, which will takes the JSON as a parameter. Inside this callBack method, you can get the response of the JSON and do what ever you want.</p>
<p>So if you are using RAILS and JQuery, here is what you can do. Jquery provides a way to directly call ajax with JSONP as requested dataType and you don&#8217;t have to do the things as create a call back methods and create the script tag and inserted into the html. If you use jQuery, this is what  you normally do ajax Request:</p>
<pre name="code" class="javascript">    $.ajax({
      url     : 'http://sampleserver.com/sampledata.json',
      type    : 'GET',
      dataType:  'json',
      success : function (response) {
        if (response['success'])
        {
          loadData(response['html']);
        }
      }
    })</pre>
<p>To change it to use jsonp, you just need to change the dataType to &#8216;jsonp&#8217;, everything else remains the same. Jquery will do the magic I described for you. At the same time, it will send a parameter &#8216;callback&#8217; to the server, which is the call back methods name that is generated by jQuery, it is a random name.</p>
<pre name="code" class="javascript">    $.ajax({
      url     : 'http://sampleserver.com/sampledata.json',
      type    : 'GET',
      dataType:  'jsonp',
      success : function (response) {
        if (response['success'])
        {
          loadData(response['html']);
        }
      }
    })</pre>
<p>Now the only thing needs to be changed is on the application server. The application needs to make sure the response can return JSONP instead of JSON. If you are using Rails, to render the response in JSON, you usually do:</p>
<pre name="code" class="ruby">render :json => {:success => true, :html => prices_html}</pre>
<p>To render the response with JSONP, which would wrap the JSON with the callback method submitted by the javascript:</p>
<pre name="code" class="ruby">render :json => {:success => true, :html => prices_html}, :callback => params[:callback]</pre>
<p>With all this, you should be able to do Cross Domain Ajax Request using jQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2012/05/11/cross-domain-ajax-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Dump MySQL database and Import from SQL Dump</title>
		<link>http://www.shanison.com/2012/03/05/how-to-dump-mysql-database-and-import-from-sql-dump/</link>
		<comments>http://www.shanison.com/2012/03/05/how-to-dump-mysql-database-and-import-from-sql-dump/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 15:10:19 +0000</pubDate>
		<dc:creator>shanison</dc:creator>
				<category><![CDATA[general programming]]></category>

		<guid isPermaLink="false">http://www.shanison.com/?p=1020</guid>
		<description><![CDATA[If you need to backup your database, you can use mysqldump command. mysqldump -uuser -ppassword database_name &#62; backup.sql If you need to dump a single table, you can do the following: mysqldump -uuser -ppassword database_name table_name &#62; backup.sql This should generate a bunch of Create Table and Insert Sql statements in the .sql files. So [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to backup your database, you can use mysqldump command.</p>
<pre name="code" class="ruby">mysqldump -uuser -ppassword database_name &gt; backup.sql</pre>
<p>If you need to dump a single table, you can do the following:</p>
<pre name="code" class="ruby">mysqldump -uuser -ppassword database_name table_name &gt; backup.sql</pre>
<p>This should generate a bunch of Create Table and Insert Sql statements in the .sql files.</p>
<p>So how do you import the database from your sql dump files. Let&#8217;s say you have the backup.sql in your computer now. First thing you need to do is upload this dump to the database server. To do this, you can use scp command to copy the files and do a secure file transfer.</p>
<pre name="code" class="ruby">scp -rP port_num backup.sql root@server_name:/root/backup</pre>
<p>After that you have to go to the mysql command tools by :</p>
<pre name="code" class="ruby">mysql -uroot -ppassword database_name</pre>
<p>After authenticated, you run the following again to import:</p>
<pre name="code" class="ruby">source /root/backup/backup.sql</pre>
<p><span id="more-1020"></span>
<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-4184280849240058";
/* 728x90, created 04/05/10 */
google_ad_slot = "4472566135";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shanison.com/2012/03/05/how-to-dump-mysql-database-and-import-from-sql-dump/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
