Wednesday, November 9, 2011

Mysql - How to search for exact word match using REGEXP?

If you are looking to match EXACT words then don't use LIKE keyword.
You could do word boundaries with the following REGEXP. 
SELECT * FROM TABLE WHERE field_name RLIKE "[[:<:]]foo[[:>:]]";
In Ruby code you can use it like
Model.find(:all, :conditions => "field_name RLIKE 'foo.*'")
or
Model.find(:all, :conditions => "field_name REGEXP 'foo.*'")

Thursday, November 3, 2011

Javascript to check uncheck all checkbox in a Table

<a href="#" id="check_<%= id %>" onclick="checkParent('<%= id %>', true); return false;">All</a>

<a href="#" id="uncheck_<%= id %>" onclick="checkParent('<%= id %>', false); return false;" style="display:none;">All</a>

<table id="table_<%= id %>">
  <tr>
    <td>
      <%= check_box_tag "locations[]", location.id, false, :onchange => "validate();" ,:id => "locations", :class => "location" %>
    </td>
  </tr>
</table>

function checkByParent(aId,aChecked) {
   
    var inputs_in_table = document.getElementById("table_"+aId).getElementsByTagName("input");
    for(var i=0; i<inputs_in_table.length; i++)
    {
        if(inputs_in_table[i].type == "checkbox") inputs_in_table[i].checked= aChecked;
    }
    if (aChecked == true)
    {
      document.getElementById("check_"+aId).style.display = "none";
      document.getElementById("uncheck_"+aId).style.display = ""; 
    }
    else if(aChecked == false)
    {
      document.getElementById("check_"+aId).style.display = "";
      document.getElementById("uncheck_"+aId).style.display = "none"; 
    }
  }

Thursday, September 29, 2011

extract urls

I have some content with a list of URLs contained in it.

I am trying to grab all the URLs out and put them in an array.

I have code like:

content = "Sample of URLs: http://www.google.com and http://www.google.com/index.html which I want to grab"

And I am trying to get the end results to be:

['http://www.google.com', 'http://www.google.com/index.html']

Either of two ways you can extracts URLs

1) urls = content.split(/\s+/).find_all { |u| u =~ /^https?:/ }

Or you can grab it by using REGEX

2) urls = content.scan(/(?:http|https):\/\/[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(?:(?::[0-9]{1,5})?\/[^\s]*)?/ix)

but note that it won't match pure IP-address URLs (like http://127.0.0.1), because of the [a-z]{2,5} for the TLD.

Wednesday, August 24, 2011

Install Skype CallRecorder

Download skype-call-recorder-0.8.tar.gz from http://atdot.ch/scr/download/

Prerequisites
sudo apt-get install cpp
sudo apt-get install qt4-dev-tools
sudo apt-get install libmp3lame-dev
sudo apt-get install libid3-dev
sudo apt-get install libvorbis-dev

Install Make

To install make need to go on path where download file resides.

sapna@sapna-desktop:~$ cd /home/sapna/Downloads/skype-call-recorder-0.8/
sapna@sapna-desktop:~/Downloads/skype-call-recorder-0.8$ cmake .
sapna@sapna-desktop:~/Downloads/skype-call-recorder-0.8$ make
sapna@sapna-desktop:~/Downloads/skype-call-recorder-0.8$ sudo make install

Restart PC or use like below
skype-call-recorder &

Setup OS from fresh install of Ubuntu 10.04

Setup OS from fresh install of 10.04
1. Apply any updates requested by Update Manager
2. Install ssh using Synaptics PackageManager
3. sudo apt-get update
4. sudo apt-get install build-essential libreadline6-dev
5. sudo apt-get install postgresql-server-dev-8.4 postgresql-8.4
6. sudo apt-get install libmagickwand-dev
7. sudo apt-get install git-core curl subversion
8. sudo apt-get install libxslt-dev libxml2-dev
9. bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
10. logout and login
11. rvm install 1.8.7-p330
12. rvm install rubygems 1.3.7
13. rvm use 1.8.7-p330

Gem installation specific for ruby 1.8.7
1. gem install rails -v=2.1.2
2. gem install rodf -v=0.1.8
3. gem install roo -v=1.3.11
4. gem install uuidtools -v=2.1.1
5. gem install RedCloth -v=4.2.7
6. gem install rmagick -v=2.13.1
7. gem install zipruby -v=0.3.6
8. gem install pg -v=0.10.1
9. gem install fastercsv -v=1.5.4
10. gem install linefit -v=0.1.0
11. gem install gruff -v=0.3.6
12. gem install mezza-rubyzip
13. gem uninstall rubyzip
* Don't worry about dependency alert. Resolved by mezza-rubyzip
14. gem install testunitxml
15. gem install nokogiri -v=1.4.4
16. gem install xml-simple -v=1.1.0

Postgresql pg_hba.con
1. sudo pico /etc/postgresql/8.4/main/pg_hba.conf
2. replace ident and md5 with trust
* sudo /etc/init.d/postgresql-8.4 restart
3. psql -U postgres < FISHSOURCE_DUMP.SQL

Password for null GNOME keyring in SVN

This happens because your subversion system is trying to use the gnome-keyring for authentication and you've accidentally deleting your GNome keyring.

> Password for '(null)' GNOME keyring:

A solution suggested to avoid the SVN prompting for a password for a keyring. That is typing command in the terminal.

> rm ~/.gnome2/keyrings/login.keyring

After giving this command in the terminal I could svn up and committed code.Usual username and password for SVN were asked and after entering them, the codes are successfully committed.

Monday, January 3, 2011

Break continues text(WRAP TEXT)

When there is continues text like "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" it disturbs the text format.There are 2 ways to do it
1)Adding newline or break after every 100 characters using Javascript.
2)Wrap text by adding style into div tag

Example of first way
-----------------------------------
<div id="company_expertise">
<%long_string = "MYCompanyExpertiseMYCompanyExpertiseMYCompanyExpertiseMYCompanyExpertise"%>
<%= hidden_field_tag "hnd_company_expertise", long_string %>
</div>
<script type="text/javascript">

str1 = document.getElementById("hnd_company_expertise").value;
str = str1.replace(/(.{100})/g, "$1\n");
document.getElementById("company_expertise").innerHTML = str;
</script>
Example of second way
-----------------------------------------
<div style="word-wrap: break-word;">
<%= "MYCompanyExpertiseMYCompanyExpertiseMYCompanyExpertise" %>
</div>