<?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>Helion-Prime Solutions blog</title>
	<atom:link href="http://blogs.helion-prime.com/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.helion-prime.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 11 Mar 2010 10:27:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tuning of Postgresql under OpenBSD</title>
		<link>http://blogs.helion-prime.com/2010/02/25/tuning-of-postgresql-under-openbsd.html</link>
		<comments>http://blogs.helion-prime.com/2010/02/25/tuning-of-postgresql-under-openbsd.html#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:04:00 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[openBSD]]></category>
		<category><![CDATA[rdbms]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=664</guid>
		<description><![CDATA[Preamble
I assume that you already made your best with help of your favorite programming language
and recommended postgresql performance tips: http://www.postgresql.org/docs/8.4/static/performance-tips.html
Postgresql resources
No doubt that standard postgresql configuration is far from modern production environments.
Therefore you need to spend enough time with following sources.
1. resource consumption documentation:
http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html
The most important parameters are:
work_mem (integer)
shared_buffers (integer)
2. Query Planning documentation:
http://www.postgresql.org/docs/current/static/runtime-config-query.html
The most important [...]]]></description>
			<content:encoded><![CDATA[<h2>Preamble</h2>
<p>I assume that you already made your best with help of your favorite programming language<br />
and recommended postgresql performance tips: <a href="http://www.postgresql.org/docs/8.4/static/performance-tips.html">http://www.postgresql.org/docs/8.4/static/performance-tips.html</a></p>
<h2>Postgresql resources</h2>
<p>No doubt that standard postgresql configuration is far from modern production environments.<br />
Therefore you need to spend enough time with following sources.</p>
<p><strong>1. resource consumption documentation:</strong><br />
<a href="http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html">http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html</a></p>
<p>The most important parameters are:<br />
work_mem (integer)<br />
shared_buffers (integer)</p>
<p><strong>2. Query Planning documentation:</strong><br />
<a href="http://www.postgresql.org/docs/current/static/runtime-config-query.html">http://www.postgresql.org/docs/current/static/runtime-config-query.html</a></p>
<p>The most important parameters are:<br />
effective_cache_size (integer)<br />
random_page_cost (floating point)</p>
<h2>OpenBSD resources</h2>
<p>The default sizes in the GENERIC kernel are insignificant also and waiting for your tuning as well.<br />
Posgtresql doesn&#8217;t start without enough memory size so always know when you need to increase kern.shminfo.shmmax.</p>
<p><strong>Setting that we can change in /etc/sysctl.conf</strong><br />
the maximum number of System V IPC system-wide semaphore sets (and identifiers) which can exist at any given time:<br />
kern.seminfo.semmni</p>
<p>the maximum total individual System V IPC semaphores which can be assigned by applications:<br />
kern.seminfo.semmns</p>
<p>the amount of shared memory available in the system (bytes):<br />
kern.shminfo.shmmax</p>
<p>the maximum number of shared memory segments:<br />
sysctl kern.shminfo.shmseg</p>
<p>Full list of setting you can see with:<br />
# man sysctl</p>
<p><strong>OpenBSD kernel parameters</strong><br />
So, there are set of parameters that can be tuned only with kernel rebuild. </p>
<p>You should tune them only if system works unstable with default values and you have:<br />
kernel warnings: “uvm_mapent_alloc: out of static map entries”<br />
or panics like:  “panic: malloc: out of space in kmem_map”</p>
<p>NKMEMPAGES<br />
This option defines number of pages in kernel kmem_map structure.</p>
<p>MAX_KMAPENT<br />
It defines number of static entries in kernel kmem_map (kernel virtual memory).</p>
<p>They can be changed in:<br />
/usr/src/sys/arch/conf/GENERIC</p>
<p>As start you need to recheck  &#8216;Building the System from Source&#8217; part of OpenBSD documentation:<br />
<a href="http://openbsd.org/faq/faq5.htm">http://openbsd.org/faq/faq5.htm</a></p>
<p>Usually administrators select these parameters using set of tests on dedicated testing box where<br />
 they emulate load of  production servers.</p>
<h2>Example</h2>
<p>our test server: 1x Intel Quad core CPU, 2GB RAM<br />
software: Ruby on Rails application, postgresql DB, memcached.<br />
load: about 15.000 users/day, peak load: 10 users/sec.</p>
<p>postgresql_dir/data/postgresql.conf</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># RESOURCE USAGE</span><br />
shared_buffers = 738MB<br />
max_prepared_transactions = <span style="color: #000000;">30</span><br />
work_mem = 16MB<br />
max_fsm_pages = <span style="color: #000000;">2000000</span><br />
<br />
<span style="color: #666666; font-style: italic;"># QUERY TUNING</span><br />
effective_cache_size = 512MB<br />
random_page_cost = <span style="color: #000000;">1.7</span></div></td></tr></tbody></table></div>
<p>/etc/sysctl.conf</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">kern.seminfo.semmni = <span style="color: #000000;">256</span><br />
kern.seminfo.semmns = <span style="color: #000000;">2048</span><br />
kern.shminfo.shmmax = <span style="color: #000000;">805306368</span> &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Shared memory segment size is 768M</span></div></td></tr></tbody></table></div>
<p>/usr/src/sys/arch/conf/GENERIC</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">## custom settings</span><br />
option MAX_KMAPENT = <span style="color: #000000;">3072</span><br />
option NKMEMPAGES = <span style="color: #000000;">32768</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2010/02/25/tuning-of-postgresql-under-openbsd.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log rotation in Ruby on Rails applications</title>
		<link>http://blogs.helion-prime.com/2009/11/19/log-rotation-in-ruby-on-rails-applications.html</link>
		<comments>http://blogs.helion-prime.com/2009/11/19/log-rotation-in-ruby-on-rails-applications.html#comments</comments>
		<pubDate>Thu, 19 Nov 2009 12:30:04 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[web-development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=623</guid>
		<description><![CDATA[preamble
Even on mid-size applications logs grow enormously fast, it&#8217;s a pity Rails doesn&#8217;t provide built-in functionality for that like Apache web-server does. Fortunately there is an easy and fast solution for that issue.
1. Install cronolog
“cronolog [http://cronolog.org/] is a simple filter program that reads log file entries from standard input and writes each entry to the [...]]]></description>
			<content:encoded><![CDATA[<h2>preamble</h2>
<p>Even on mid-size applications logs grow enormously fast, it&#8217;s a pity Rails doesn&#8217;t provide built-in functionality for that like Apache web-server does. Fortunately there is an easy and fast solution for that issue.</p>
<h2>1. Install cronolog</h2>
<p>“cronolog [<a href="http://cronolog.org/">http://cronolog.org/</a>] is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time.”</p>
<p>For details, and list of parameters see: [<a href="http://cronolog.org/usage.html">http://cronolog.org/usage.html</a>]</p>
<p>On GNU/Linux Debian:</p>
<pre># apt-get install cronolog</pre>
<h2>2. Setup your Rails application</h2>
<p>Edit necessary environment file: like &#8216;config/environments/production.rb&#8217; file</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># system logger configuration</span><br />
<span style="color:#008000; font-style:italic;"># config.logger = SyslogLogger.new</span><br />
<br />
config.<span style="color:#9900CC;">logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">popen</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;FULL_PATH_TO_CRONOLOG log/production.log.%Y%m%d&quot;</span>, <span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
config.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">level</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>::INFO</div></td></tr></tbody></table></div>
<p>That&#8217;s all, fast and easy .. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2009/11/19/log-rotation-in-ruby-on-rails-applications.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy image scaling for RoR developers</title>
		<link>http://blogs.helion-prime.com/2009/11/02/easy-image-scaling-for-ror-developers.html</link>
		<comments>http://blogs.helion-prime.com/2009/11/02/easy-image-scaling-for-ror-developers.html#comments</comments>
		<pubDate>Mon, 02 Nov 2009 16:21:40 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=588</guid>
		<description><![CDATA[We have common task: image scaling [http://en.wikipedia.org/wiki/Image_scaling], and correct understanding that: we can&#8217;t ask users to provide image of appropriate sizes, just use width and height CSS parameters for images, and thumbnail is always required feature.
Luckily we have ImageMagic library [http://www.imagemagick.org] and program interfaces for popular languages.
install RMagic gem
# gem install rmagick
add small code:
123456789101112131415161718192021222324252627282930require 'rubygems'
require [...]]]></description>
			<content:encoded><![CDATA[<p>We have common task: image scaling [<a href="http://en.wikipedia.org/wiki/Image_scaling">http://en.wikipedia.org/wiki/Image_scaling</a>], and correct understanding that: we can&#8217;t ask users to provide image of appropriate sizes, just use width and height CSS parameters for images, and thumbnail is always required feature.</p>
<p>Luckily we have ImageMagic library [<a href="http://www.imagemagick.org">http://www.imagemagick.org</a>] and program interfaces for popular languages.</p>
<p>install RMagic gem<br />
# gem install rmagick</p>
<p>add small code:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'RMagick'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> ImageController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController<br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> index<br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># determine basic params</span><br />
&nbsp; w = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:w</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; h = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:h</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; path = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:path</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !w.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">empty</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !h.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">empty</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; image = <span style="color:#6666ff; font-weight:bold;">Magick::Image</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; transformed_image = image.<span style="color:#9900CC;">resize_to_fill</span><span style="color:#006600; font-weight:bold;">&#40;</span>w.<span style="color:#9900CC;">to_i</span>, h.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># send image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; send_data<span style="color:#006600; font-weight:bold;">&#40;</span>transformed_image.<span style="color:#9900CC;">to_blob</span>, <span style="color:#ff3333; font-weight:bold;">:disposition</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'inline'</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;image/#{image.format.downcase}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e<br />
&nbsp; &nbsp; &nbsp; &nbsp; Rails.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">error</span> e.<span style="color:#9900CC;">message</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Rails.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">error</span> e.<span style="color:#9900CC;">backtrace</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Error processing image #{type}/#{aliaz}&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:code</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 404, <span style="color:#ff3333; font-weight:bold;">:layout</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Here to re-size images we use &#8216;resize_to_fill&#8217; ImageMagic method:<br />
re-size the image to fit within the specified dimensions while retaining the aspect ratio of the original image, and if necessary, crop the image in the larger dimension.</p>
<p>Sure you understand that resizing takes time and so you should cache re-sized images.</p>
<p>For additional info look thru:<br />
[<a href="http://studio.imagemagick.org/RMagick/doc/">http://studio.imagemagick.org/RMagick/doc/</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2009/11/02/easy-image-scaling-for-ror-developers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-domain applications in Ruby on Rails</title>
		<link>http://blogs.helion-prime.com/2009/09/03/multi-domain-applications-in-ruby-on-rails.html</link>
		<comments>http://blogs.helion-prime.com/2009/09/03/multi-domain-applications-in-ruby-on-rails.html#comments</comments>
		<pubDate>Thu, 03 Sep 2009 14:34:58 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=566</guid>
		<description><![CDATA[preamble
Ruby on Rails is a great framework that still luck some common features, among them: multi-domain support.
Here I will describe fast solution that doesn&#8217;t work for every browser and another one that do the work.
Ok, you did your homework and google something like &#8216;ruby on rails multi-domain&#8217;.
Very often provided solution:
edit environment.rb
1config.action_controller.session = &#123;:domain =&#62; '.mydomain.com'&#125;
With [...]]]></description>
			<content:encoded><![CDATA[<h2>preamble</h2>
<p>Ruby on Rails is a great framework that still luck some common features, among them: multi-domain support.<br />
Here I will describe fast solution that doesn&#8217;t work for every browser and another one that do the work.</p>
<p>Ok, you did your homework and google something like &#8216;ruby on rails multi-domain&#8217;.<br />
Very often provided solution:</p>
<p>edit environment.rb</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>:domain <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'.mydomain.com'</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>With that parameter Rails always read cookies from same domain. In real some browsers forbid for applications to read cookies from other domain due to insecurity of that operation. And as Mozilla Firefox in set of browsers that forbid that we just need another solution.</p>
<p>Now it&#8217;s clear that we should implement necessary functionality other way. </p>
<h2>Here we go:</h2>
<h3>1. will store session ID in the database(by default Rails2 store it in cookies)</h3>
<p>environment.rb:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session_store</span> = <span style="color:#ff3333; font-weight:bold;">:active_record_store</span></div></td></tr></tbody></table></div>
<p>and then execute rake task that create necessary DB migration:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake db:sessions:create</div></td></tr></tbody></table></div>
<p>Apply it with:  rake db:migrate.</p>
<h3>2. setup session parameters</h3>
<p>environment.rb:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rubygems&quot;</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;active_support&quot;</span><br />
<br />
config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:session_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'_myapp_session_id'</span>, &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># session identification key</span><br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:secret</span> &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'89sHslddfsd98klasdKd'</span>, <span style="color:#008000; font-style:italic;"># hash code of session generator(make it random and longer)</span><br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:cookie_only</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,<br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:expire_after</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 1.<span style="color:#9900CC;">week</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># TTL (time to live)</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<h3>3. let&#8217;s create session creation handler</h3>
<p>application_controller.rb:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">before_filter <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>controller<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp;opts = controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">session_options</span><br />
&nbsp; &nbsp;key = opts<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:key</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># use session ID if it's passed</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">if</span> controller.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># session initialization with old ID</span><br />
&nbsp; &nbsp; &nbsp; controller.<span style="color:#9900CC;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:nothing</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; opts<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = controller.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">session_options</span> = opts<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># session initialization with new ID</span><br />
&nbsp; &nbsp; &nbsp; controller.<span style="color:#9900CC;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:nothing</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<h3>4. session pass</h3>
<p>We need to pass session ID as parameter when user change domain name, and within domain we still use cookie.</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">“#{request.session_options[:key]}” =&gt; request.session_options[:id]</div></td></tr></tbody></table></div>
<p>It&#8217;s wise to use session initialization before request.session_options[:id]  invocation due to Rails use lazy loading, and session can be uninitialized.<br />
Use something like: session[:nothing].</p>
<p>Pay attention that information that Rails get from cookie has bigger priority, and so if you have some parameter  in cookie Rails will use it firstly.</p>
<p><b>Note:</b><br />
An attacker can still steal you session ID by sniffing the network, or exploiting javascript, he/she gets the value from the cookie itself. If you care about security so much just use HTTPS.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2009/09/03/multi-domain-applications-in-ruby-on-rails.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Advices for customer as part of project</title>
		<link>http://blogs.helion-prime.com/2009/08/26/advices-for-customer-as-part-of-project.html</link>
		<comments>http://blogs.helion-prime.com/2009/08/26/advices-for-customer-as-part-of-project.html#comments</comments>
		<pubDate>Wed, 26 Aug 2009 13:49:45 +0000</pubDate>
		<dc:creator>vasiliy.kiryanov</dc:creator>
				<category><![CDATA[be smart]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[internet]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=555</guid>
		<description><![CDATA[Today even great application can die alone .. world has too many great applications. me
Do you know what software development company sell?
Not just some abstract peace of software but application that can solve customer&#8217;s problems .. we should understand what customer wants from the application, what tasks he/she wants to solve with application.
We provide to [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Today even great application can die alone .. world has too many great applications. <br/>me</p></blockquote>
<p>Do you know what software development company sell?<br />
Not just some abstract peace of software but application that can solve customer&#8217;s problems .. we should understand what customer wants from the application, what tasks he/she wants to solve with application.</p>
<p>We provide to customer our vision and suggest technology/platform/approach, customer provide ideas/plans/limitations .. together we will end with some satisfied result.  But what then?<br />
Then as usual we get our money and leave customer alone with his application. </p>
<h2>What else we can give to them?</h2>
<p>We should give business advices that can bring closer customer&#8217;s target.<br />
Client can take them or not but part of our work is to give ones. Customers see that we care, that help to build better relationship and get great satisfaction .. we make great applications that work!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2009/08/26/advices-for-customer-as-part-of-project.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
