Thursday, September 20, 2012

Axlsx to support line break (\n)

Hello Rubies,
      Yesterday when i was playing with axlsx gem find something interesting. Requirement is need to allow line break in content. And current axlsx gem does not support that feature. So add this patch to your existing gem or either point directly to git repository b'coze that patch is unpublished as for now.

Add this line to axlsx1.2.3/lib/axlsx/workbook/worksheet/worksheet.rb

Remove line #500  

str.gsub(/[[:cntrl:]]/,'')

and Replace with

  if RUBY_VERSION == "1.8.7"
    nasty_control_char_matcher = Regexp.new("[\x01\x02\x03\x04\x05\x06\x07\x08\x1F\v\xE2]")
  else
    nasty_control_char_matcher = Regexp.new("[\x01\x02\x03\x04\x05\x06\x07\x08\x1F\v\u2028]")
  end

  str.gsub(nasty_control_char_matcher,'')

or

gem 'axlsx', '1.2.3', :git => 'git://github.com/randym/axlsx.git'

Hope this post is useful to you folks :).

Wednesday, September 5, 2012

jumping of browser window when using cursor keys

Hello Guys,
           There is wired problem when using auto completer on page and try to use arrow key for navigation.. it simply jump the browser window.

To over come this problem just add the patch in controls.js

replace line 212 to 214 with

    if(this.index > 0) {this.index--;}
    else {
      this.index = this.entryCount-1;
      this.update.scrollTop = this.update.scrollHeight;
    }
    selection = this.getEntry(this.index);
    selection_top = selection.offsetTop;
    if(selection_top < this.update.scrollTop){
    this.update.scrollTop = this.update.scrollTop-selection.offsetHeight;
    }

replace line 217 to 220 with

    if(this.index < this.entryCount-1) {this.index++;}
    else {
      this.index = 0;
      this.update.scrollTop = 0;
    }
    selection = this.getEntry(this.index);
    selection_bottom = selection.offsetTop+selection.offsetHeight;
    if(selection_bottom > this.update.scrollTop+this.update.offsetHeight){
      this.update.scrollTop = this.update.scrollTop+selection.offsetHeight;
    }
  
add line after 297
  this.update.scrollTop = 0;

In short by replacing two functions markPrevious() & markNext() will fix our problem.

Execute raw query and manual connection

Hello Rubies,
           Some time when we have huge query that it will be easy to use RAW SQL compare to ruby's active record query.

ActiveRecord::Base.connection.query <<-END
   /* Raw sql query */
  Select * from table where conditions
END

Custom connection and query

env = RAILS_ENV
config = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(config[env])

schemas = ActiveRecord::Base.connection.select_values("select * from pg_namespace where nspname not in ('public','information_schema') AND nspname NOT LIKE 'pg%'").inspect

Toggle div using ruby on rails

Hello Guys,
        Toggle is the function of prototype.js. We just have to use it to perform toggling.

eg.

html = "Toggle me <span id='collapse'>"
html << link_to_function(image_tag("arrow_normal.png", :style => 'border:none;'), "$('collapse').toggle();$('expand').toggle(); new Effect.Highlight('DIVID',{endcolor:'#ffffff', startcolor:'#ffffc8', duration:2.0}); return false;")
html << "</span>"    
html << "<span id='expand' style='display:none'>"
html << link_to_function(image_tag("arrow-down.png", :style => 'border:none;'), "$('collapse').toggle();$('expand').toggle();return false;")
html << "<div id='DIVID'> HELLO </div> </span>"

Initially it show the text as Toggle me with right arrow. but when you click on that i replace the right arrow to down arrow. And display the container area with text HELLO as per above eg.