Android SQLite database – A tutorial

1.   Create the DatabaseHelper class. This class is responsible for creating the database. The onUpgrade() method will simply delete all existing data and re-create the table. It also defines several constants for the table name and the table columns.

public class DatabaseHelper extends SQLiteOpenHelper {

	  private static final String DATABASE_NAME = "property.db";
	  private static final int DATABASE_VERSION = 1;
	  public static final String TABLE_PROPERTY = "property";
	  public static final String COLUMN_ID = "_id";
	  public static final String COLUMN_NICKNAME = "nickname";
	  public static final String COLUMN_TENANT = "tenant";
	  public static final String COLUMN_ADDRESS = "address";
	  public static final String COLUMN_LOAN = "loan";

	  // Database creation sql statement
	  private static final String DATABASE_CREATE = "create table "
	      + " integer primary key autoincrement, " 
	      + COLUMN_NICKNAME + " text not null"
	      + COLUMN_TENANT + " text"
	      + COLUMN_ADDRESS + " address not null"
	      + COLUMN_LOAN + " integer);";

	  public DatabaseHelper(Context context) {
	    super(context, DATABASE_NAME, null, DATABASE_VERSION);

	  public void onCreate(SQLiteDatabase database) {

	  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	        "Upgrading database from version " + oldVersion + " to "
	            + newVersion + ", which will destroy all old data");


Displaying Git commit version in Rails

At times, you’re doing rapid development and you’d like to frequently update the GIT commit version that is in use

1.  Create a ‘config/initializers/git_revision.rb’ file and update the following:

module MyProject
     REVISION=`git log --pretty=format:'%h' -n 1`

2.  In your _footer.html.erb or equivalent view file, call the following:

Version: <%= MyProject::REVISION %>

This should display the version as follows:

Version: 774318e

Route ‘Sign In’ to the previous page

Ever noticed after doing an elaborate search, your website asks you to do a ‘Sign in’.  After logging in, it forgets all about your search results and takes you back to your home page.

When using Rails with Devise, you may have noticed that ‘signing in’ takes you to the home page of the controller.

In order to go to the last page that redirects you to the ‘devise sign in ‘ page, make the following changes to your Devise ‘Sessions Controller’

#Take me to the referring page after sign in
def after_sign_in_path_for(resource)
    redirect_to request.referrer

This should redirect to the ‘referring’ or the ‘calling’ page.

Polk Audio RTi A7 Review – Speaker Obession

RTi A7 Image

My research for speakers a level above kept revolving around these RTi A7s.   When I looked at them in the shop they were a perfect color and contour match.  I got a sense of accomplishment when I realized that my speaker search had come to an end.  I love stereo listening and these speakers are built around that.  I was originally thoroughly impressed with the A9s’ but realized that they were really tall for my place and also required a lot of power.  The A7s were more of a match and now I realize that its more than that.

Sound reproduction is incredible.  Even the slightest of sounds are made crystal clear from the speakers.   I did not like the addition of  a subwoofer for stereo listening as it interfered with the clarity.   I use a Denon AVR 3310CI to drive these speakers and they have produced excellent results.  I use it for a lot of low volume listening that I’ve found to appreciate.  And when it comes to high volume, they can go as high as you can take.   Adding an amp would definitely benefit, but there’s nothing wrong without one.

HD Audio, Blu ray discs and audio CDs bring out the best in this speaker.  They discriminate a bit if you’re using compressed audio however high the bit rate may be.  The Restorer function in the AVR 3310 seemed to help a little bit with that.   Addition of a sub woofer definitely takes it to a different level, but I had to increase the volume/channel level to match it with the speakers performance.  The A7s go as low as 30Hz but I set the crossover to 100Hz for excellent bass delivery.  Needless to say, without  a subwoofer the bass is very tight and just enough.   Lovely when you’re reading a book and listening to concert hall music.

I still have to bi-amp them with the AVR to see if the results are any different although I’ve read at places that they dont make a big difference.  The binding posts are excellent and the speaker construction is truly extraordinary.  A simple tap and placing a ear on the walls of the speaker reveals excellent resonance built into the cabinet.  Oh yes, the cabinet,  that is a thing of beauty that matched with my wooden flooring.  It is well constructed and no cheap materials in this speaker unit.   Removing the front panel cover reveals a view of professionalism.  Silk dome tweeters,  polymer mid range and 2 woofers give this speaker quite a look when contrasted with a darker shade of silver.   Venting ports are supplied in the front and back.   With a power range of upto 300W you cannot go wrong for home usage.   Watching movies was a true delight when I had all the lights off.  The sound orientation was brilliant when I couldnt exactly realize where it was coming from.

These speakers are no way in my budget but I realized that the value for money is truly a ratio worth passing of without consideration.  And I was glad when I was right this time.   I really appreciate the engineers at Polk who have come out with such a precise speaker.   You guys made it a part of my second life.

Integrating PaperClip Gem to a Rails Model

Include the gem in ‘Gemfile’

gem "paperclip", "~> 3.0"

1.  Add a rails migration to the model

      rails g migration addAvatarColumnToMenu
      invoke  active_record
      create db/migrate/20131113072946_add_avatar_column_to_menu.rb

2.  Edit your migration

 class AddAvatarColumnToMenu < ActiveRecord::Migration
   def self.up
     change_table :menus do |t|
        t.attachment :avatar
   def self.down
      drop_attached_file :menus, :avatar

3.  Add the following to your model

class Menu < ActiveRecord::Base
  has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"

4.  Run the migration

 rake db:migrate
==  AddAvatarColumnToMenu: migrating ============================
-- change_table(:menus)
-> 0.5326s
==  AddAvatarColumnToMenu: migrated (0.5328s) ===================

5.  You should see the 4 columns added if you run “rails console”

avatar_file_name: string, avatar_content_type: string, avatar_file_size: integer, avatar_updated_at: datetime

6.  Add this to your “new” and “update” views

<%= form_for @menu, :url => menus_path, :html => { :multipart => true } do |form| %>
  <%= form.file_field :avatar %>
<% end %>

7.  Add this to the ‘show’ view

<%= image_tag @menu.avatar.url %>
<%= image_tag @menu.avatar.url(:medium) %>
<%= image_tag @menu.avatar.url(:thumb) %>

8.  Restart the server to get the new table data set.