Friday, December 13, 2013

ActiveRecord::ConnectionTimeoutError

If one is getting or started getting error like this
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)):
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in wait_poll'
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `loop'
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `wait_poll'
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:136:in `block in poll'

Then it is something that is missing in your database.yml
{environment_name}:
  adapter: mysql2
  encoding: utf8
  database: {product_name}_environment_name
  username: username
  password: password
  socket: /var/run/mysqld/mysqld.sock

Add correct values for 'reaping_frequency' and 'pool' in connection parameter and it might look like
{environment_name}:
  adapter: mysql2
  encoding: utf8
  database: {product_name}_environment_name
  pool: 15
  reaping_frequency: 3
  username: username
  password: password
  socket: /var/run/mysqld/mysqld.sock
Options descriptions
  • pool: number indicating size of connection pool (default 5)
  • checkout_timeout: number of seconds to block and wait for a connection before giving up and raising a timeout error (default 5 seconds).
  • reaping_frequency: frequency in seconds to periodically run the Reaper, which attempts to find and close dead connections, which can occur if a programmer forgets to close a connection at the end of a thread or a thread dies unexpectedly. (Default nil, which means don't run the Reaper).
  • dead_connection_timeout: number of seconds from last checkout after which the Reaper will consider a connection reapable. (default 5 seconds).

Knowledge base taken from http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html

Friday, December 6, 2013

Ctrl + Alt + F1 for TTY window

To open a console window and fix Ubuntu if it anywhere halts, command is press
Ctrl + Alt + F1
and a TTY prompt appears and now it is all yours.

Friday, November 29, 2013

Rails: redirect_to with flash

Hi,

In rails one can provide(not in older versions) flash messages directly in redirect_to method while residing in controller's action to redirect to different path like
redirect_to login_path, :notice => 'Please login'

But one thing needs attention here is, it works only for named routes and not for routes without names like

redirect_to {controller: 'session', action: 'login'}, :notice => 'Please login'

Small but this point should be taken in consideration.

Friday, November 8, 2013

3 column css layout with center fludic and fixed width left right column

How can we make a 3 column layout where left and right most column are with fixed width while the middle column should be fludic (meaning it consumes the whatever is left on screen now)
Concept is pretty simple: Make two two-column layout and insert one into the other :)
Step 01: Make a  two column layout where right column is fixed width and left consumes the left-over screen space.
.container_1 {
   height: auto;
   overflow: hidden;
}
   
.container_1 .right {
    width: 100px;
    float: right;
    background: #DDD;
}

.container_1 .left {
    background: #CCC;
    width: auto;
    overflow: hidden;
}
<div class="container_1">
<div class="right">right content</div>
<div class="left">left content</div>
</div>
Step 02: Make another two column layout where left column is fixed width and right consumes the left-over screen space.
.container_2 {
   height: auto;
   overflow: hidden;
}
   
.container_2 .left_2 {
    background: none repeat scroll 0 0 #BBB;
    float: left;
    width: 180px;
}

.container_2 .right_2 {
    background: none repeat scroll 0 0 #AAA;
    overflow: hidden;
    width: auto;
}
<div class="container_2">
<div class="left_2">left content</div>
<div class="right_2">right content</div>
<div class="clearfix"></div>
</div>

Step 03: Insert container_2 div in container_1's left column div.
Here is the working example
http://jsfiddle.net/praveen_kumar_sinha/fSf8T/


Saturday, May 25, 2013

InvalidAuthenticityToken while file upload in rails 4

Hi Friends,

Am back again and this time really after a long time. Actually occupied with my current company and it is bootstrapping :) wish me luck.

Any how recent problem that i faced was, uploading file (multipart form request) was giving "ActionController::InvalidAuthenticityToken" error in rails4 while a normal form post was working great, which is kind of strange and it was giving error for synchronous and asynchronous request both.

So whats the way to fix it ? 
Add your own authenticity_token params which is missing in rails form (which is strange again) but add a hidden field something like

<%= hidden_field_tag :authenticity_token, form_authenticity_token -%>

and now everything is back to normal :) i hope for you too.

Thanks
Praveen

Friday, February 1, 2013

How to get database size in MySql


SELECT table_schema "DB Name", sum( data_length + index_length ) / 1024 / 1024 "DB Size in MB" 
FROM information_schema.TABLES GROUP BY table_schema ;

Courtesy: http://stackoverflow.com/questions/1733507/how-to-get-size-of-mysql-database

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...