Friday, 11 December 2015

Suppress ready and complete log messages from rack-timeout

The rack-timout gem has an annoying habit of logging two lines for each request at INFO level, e.g.:
source=rack-timeout id=11b2abd0-d4af-4a13-9c5a-a8729af45e40 wait=15ms timeout=29985ms state=ready
source=rack-timeout id=11b2abd0-d4af-4a13-9c5a-a8729af45e40 wait=15ms timeout=29985ms service=165ms state=completed

I like logging at INFO in production because I get a log message per request.

You can reduce the log level rack-timeout uses to log those states by adding this to your initializer:
Rack::Timeout::StateChangeLoggingObserver::STATE_LOG_LEVEL[:ready] = :debug
Rack::Timeout::StateChangeLoggingObserver::STATE_LOG_LEVEL[:completed] = :debug

Thursday, 24 September 2015

Bootstrap and Equal Height Columns

We have a page with 3 columns: a left sidebar, main content in the middle and a right aside for help content. The columns are re-ordered for small screens using Bootstrap's push/pull classes. The content is dynamic and quite often there's a significant different in height.

We wanted to either shade the columns or put a vertical line in between. At 768px and below no background and the usual stacking.

This turned out to be quite a challenge, but http://webdesign.tutsplus.com/tutorials/quick-tip-solving-the-equal-height-column-conundrum--cms-20403 came to my rescue.

There was a wrinkle caused by the Bootstrap columns having position: relative applied to them.

This may not be the best solution (requires extra markup), but it felt like a reasonable compromise:

<div class="row column-background-wrapper">
  <span class="column-background column-1"></span>
  <div class="col-sm-3">
    ...
  </div>

  <span class="column-background column-2"></span>
  <div class="col-sm-5">
    ...
  </div>

  <span class="column-background column-3"></span>
  <div class="col-sm-4">
    ...
  </div>
</div>

And the CSS:

.column-background-wrapper {
  position: relative;
}

.column-background {
  display: none;
}

@media (min-width: 768px) {
  .column-background {
    bottom: 0;
    display: block;
    position: absolute;
    top: 0;
    z-index: -1;
  }

  .column-1 {
    left: 0;
    background-color: #eee;
    width: 25%;
  }

  .column-2 {
    left: 25%;
    // no background needed
    width: 41.66666667%;
  }

  .column-3 {
    left: 66.66666667%;
    background-color: #eee;
    width: 33.33333333%;
  }

}

The % values in the CSS change according to your column setup. And if you use different column sizes at different screen sizes, you would need to replicate that configuration with your own media queries.

http://www.bootply.com/Toa7I16QEQ

Tuesday, 24 March 2015

Basic Rails App

To create a basic application in Rails with some model validation:

rails new demo
cd demo
rails generate scaffold idea name:string{50} description:text{100}
rake db:migrate
cat > app/models/idea.rb <<EOF
class Idea < ActiveRecord::Base
  validates :name, presence: true, length: { maximum: 50 }
  validates :description, length: { maximum: 100 }
end
EOF
rails s

Friday, 27 February 2015

Heroku, Rails, Postgres and database purge and setup

If you delete Rails migrations after they are used, and then reset your production Heroku Postgres database:

heroku pg:reset DATABASE

All you can do to get your database schema back (error free) is 
heroku run rake db:schema:load. If you then try to heroku run rake db:seed (and you have foreign keys) you will get errors like:

PG::InsufficientPrivilege: ERROR:  permission denied: "RI_ConstraintTrigger_a_12949367" is a system trigger

The solution is to reset your development database and then push that pristine copy to heroku, ie.

# wipe and recreate your development database
bundle exec rake db:purge db:setup
# wipe your production database
heroku pg:reset DATABASE

# push your local development database to Heroku
heroku pg:push yourappname_development HEROKU_POSTGRESQL_PINK_URL --app yourappname

yourappname_development - your local development database name
HEROKU_POSTGRESQL_PINK_URL - your production Heroku database name (heroku pg:info to find out)
yourappname - your Heroku application name



Another case where this error comes up is using fixtures to update "static" data in production database. If you are using Heroku you cannot just become the Postgres super-user and disable the constraint.

But this works (from a psql prompt, eg. heroko pg:psql) ...

# verify the foreign key constraint on the table and it's name:
\d table_name
# drop the foreign key constraint
alter table table_name drop constraint fk_rails_01234abcde;
#
# now run your fixtures and/or whatever re-seeding you need to do
#
# create the dropped foreign key
alter table table_name add constraint fk_rails_01234abcde foreign key(column_name) references other_table(id);

Friday, 30 January 2015

Integrate a Bootswatch theme into a Rails 4 app by hand

Adding yet another Gem into my application just to incorporate a Bootstrap theme (from Bootswatch)  seemed like overkill. Doing it manually was not hard…

Following the instructions for the bootstrap-sass Gem, we start with an app/assets/stylesheets/application.css.scss that looks like:

  @import "bootstrap-sprockets";
  @import "bootstrap";

Say we want to use the Yeti theme, download the _bootswatch.scss and _variables.scss files from the Bootswatch site. Place the files in a vendor/assets/stylesheets/bootswatch/yeti/ directory in your Rails project. 

Finally add the new @import statements in your app/assets/stylesheets/application.css.scss file, leaving it looking like:

  @import "bootswatch/yeti/_variables";
  @import "bootstrap-sprockets";
  @import "bootstrap";
  @import "bootswatch/yeti/_bootswatch";

The order of the imports is important. I have a comment block above those imports that reads:

  // order is important here
  // 1. theme variable overrides
  // 2. theme variables
  // 3. any core bootstrap variable overrides
  // 4. bootstrap-sockets and bootstrap
  // 5. theme styles
  // 6. application styles

Thursday, 22 January 2015

Linuxmint Dropbox icon ugly background

Linuxmint 17.1 "Rebecca"
NVidia proprietary driver (331.113)

After installing the NVidia drivers, the Dropbox icon in the system tray has (in my case) a solid black background rather than the colour of the panel.

Found the fix at http://crunchbang.org/forums/viewtopic.php?pid=414074#p414074

cd ~/.dropbox-dist/dropbox-lnx.x86_64-3.0.5
cp -p libGL.so.1 libGL.so.1.orig
ln -sf /usr/lib/nvidia-331/libGL.so.1

After that stop and start Dropbox and the icon background colour is normal

Tuesday, 14 August 2012

Mac OSX NoSleep

Little bit of Free Software to give you some control over what happens when you close your MaxBook's lid.

http://code.google.com/p/macosx-nosleep-extension/