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>

Friday, June 18, 2010

How to create virtual hosts in Windows (wamp) web server?

To create virtual hosts or virtual domains in your Apache server on Windows using WAMP server is just a matter of editing few files. Find the walk-through below.

Prerequisites : Apache server for Windows

Step 1 – Setting up the ‘host’ file

1. Find the ‘host’ file in ‘C:\WINDOWS\system32\drivers\etc’ folder (or where you installed windows)
2. Open it with Notepade or any text editor.
3. You will see following lines

# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
::1 localhost

4. Add the desired domain names in the end of the text (after the default localhost settings indicated above) it can be anything with or without extension (see the examples below)

127.0.0.1 mydomain.local
127.0.0.1 www.mydomain
127.0.0.1 mywebsite
127.0.0.1 subdomain.mydomain.local

Step 1 is done.

Step 2 – Configuring the Apache ‘httpd.conf’ and ‘httpd-vhosts.conf’ files

1. First we’ll enable a configuration file located in the WAMP server Apache folder. For this, open up the ‘httpd.conf’ file from the the “ c:\wamp\bin\apache\apahce2.2.11\conf” folder.
2. Find the below lines and delete the # key in front of the second line to un-comment and enable it.

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

This will include the particular configuration file where we’ll setup the virtual hosts and their folders.
3. Now we’ll find the ‘httpd-vhosts.conf’ file located in the Apache server. Usually we can find it in “c:\wamp\bin\apache\apahce2.2.11\conf\extra\” in the WAMP server (replace the apache version number after the \apache\ folder)

Add these lines in that file to enable the virtual hosts (which we created in step 1)

NameVirtualHost 127.0.0.1
# This line will make virtual host based on names not IPs

DocumentRoot "c:/wamp/www”
#this is default root for websites in WAMP
ServerName localhost
#this is default localhost domain


Now again we’ll add another block of virtualhost which will point out custom domain this time.


DocumentRoot "c:/wamp/www/mydomain.local"
#We’ll create a folder inside /www/ folder for our domain files.
#No restrictions in the folder name but we’ll keep it same to make it
#easily identifiable.
ServerName mydomain.local
#this is our custom domain we added in the first step


So, the final look of the file will be like this:

NameVirtualHost 127.0.0.1


DocumentRoot "c:/wamp/www”
ServerName localhost



DocumentRoot "c:/wamp/www/mydomain.local"
ServerName mydomain.local


We can add virtual hosts as many as we needed using the same block. Once everything is added in the ‘host’ file as in step 1 and in the apache config files as in the step 2, we’ll have to restart the WAMP server to take effect new changes we’ve done. Click the WAMP server icon in the system notification area and chose ‘Restart All services’.

Thats it. Now you can access the domain by typing ‘http://mydomain.local’ in the address bar of your favorite browser.

Work locally with IIS and virtual hosts on windows

Here it shows how you can easily create virtual hosts on a windows machine to run multiple sites simultaneous each one having its own domain

Prerequisites : IIS Server for Windows

Steps:
1)Need to add instance in hosts file resides in C:\WINDOWS\system32\drivers\etc path. Add instance 127.0.0.1 mytestsite.local in host file.

2)Then need to start your server like ruby script/server -p 3000

3)Now run site using URL mytestsite.local:3000

Thus newly created instance can execute on custom url.

You can add multiple instance also.
e.g 127.0.0.1 mytestsite.local
      127.0.0.1 new.mytestsite.local