Sunday, October 25, 2009

sanitize gem issue

I have used ‘sanitize’ gem to remove HTML tags from entered text
the version i was using was ‘1.0.8’

After using it for a while, i found an issue in it where calling
Sanitize.clean(“’”) will return “#39;” while quote isn’t HTML character

Looking around for a reason for this issue, i found that this is a defect that was detected in older versions and that it is now fixed in version ‘1.1.0’

So anyone who has this issue can simply remove his installed gem and install the latest one

Monday, August 31, 2009

smtp 555 5.5.2 Syntax error (Net::SMTPFatalError)

This title was part of an error message i got while dealing with action_mailer

i looked everywhere for a reason for this error message and found so many reasons but none of them matched with my case

So i liked to share why i got this error. Simply because i was adding no recipients to my email. I know it is very weird to send an email without having a recipient but getting this error message i much more weird and strange

/usr/lib/ruby/1.8/net/smtp.rb:930:in `check_response': 555 5.5.2 Syntax error. 24sm123817eyx.21 (Net::SMTPFatalError)
        from /usr/lib/ruby/1.8/net/smtp.rb:899:in `getok'
        from /usr/lib/ruby/1.8/net/smtp.rb:842:in `rcptto'
        from /usr/lib/ruby/1.8/net/smtp.rb:834:in `rcptto_list'
        from /usr/lib/ruby/1.8/net/smtp.rb:833:in `each'
        from /usr/lib/ruby/1.8/net/smtp.rb:833:in `rcptto_list'
        from /usr/lib/ruby/1.8/net/smtp.rb:654:in `sendmail'
        from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:683:in `perform_delivery_smtp'
        from /usr/lib/ruby/1.8/net/smtp.rb:526:in `start'
        from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:681:in `perform_delivery_smtp'
        from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:523:in `__send__'
        from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:523:in `deliver!'
        from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:395:in `method_missing'
        from test_sending_emails_in_ruby.rb:31 

this is the error message i got and it was solved when i added a recipient

Monday, June 29, 2009

Memory Leakage while using Mechanize

I was working on a task that scrape several web pages. After running this task for a while, i found that memory taken by my process is raising forever until it was about to eat all memory available of the server.

after some investigation regarding this matter, i knew that the problem was in my understanding to how mechanize agent works

let me explain with an example

agent = WWW::Mechanize.new
while(true)
page = agent.get(“www.example.com”)
end

in this example, memory will be consumed because mechanize keeps history within the agent, i looked in its documentation and found that there is a parameter which is called “max_history” which when set will fix this issue i think but didn’t try

also a fix to such issue, if you don’t need history is to write your code like that

while(true)
agent = WWW::Mechanize.new
page = agent.get(“www.example.com”)
end

That’s it, maybe this piece of information can be useful for someone facing this issue just like me

Monday, June 15, 2009

Install Mechanize On Debian

Installing mechanize gem on Debian should be as easy as running this command

gem install mechanize

but this won’t succeed unless you install these packages on your Debian machine

apt-get install libxml-dev libxslt1-dev

Once installed, gem will be installed seamlessly

Update:

if the above apt-get command didn't work with you and you got an error that package doesn't exist

try this new line

apt-get install libxml2-dev libxslt1-dev

as some packages names has changed

[Linux] Mounting windows folders

Due to my new configuration which is using Windows as my default OS and Debian shell through Virtualbox, my need to have a folder shared between these two environment become a must in order to ease file sharing and exchange.

At first, i depended on “shared folders” feature of VirtualBox which after a while failed as i always get a “Protocol Error” whenever i deal with files IO on that shared folder.

That’s why i looked for another solution that is more stable than that one and reached to using “CIFS” as a way to mount windows shared folder on my Debian machine.

The steps are very easy to be made and gives you a stable robust solution away from VirtualBox problems. i can summarize these steps as follows

  1. install on your Debian machine “smbfs” package which will add this new type of mounting called “CIFS”
  2. suppose your machine IP is “192.168.1.6” and you shared a folder on it called “work” and this folder is secured to be used only with certain group which is administrators and one of these administrators is named “BioNuc” and have a certain password then your command will be                                                                                         mount -t cifs -o username=BioNuc ‘\\192.168.1.6\work’ <linux-path-to-mount-on-it>
  3. After writing this line, you will be asked to insert your password in order to make mount process successful

That’s it, Enjoy sharing folders seamlessly

Monday, April 13, 2009

Giants Alliance

Two giants are there one called Windows and another called Linux. As i am fan of Windows Interfaces and Usability (by the way i use Windows XP) and also fan of the extreme shell power of Linux, I wished if i can exploit these two powers at the same time.

The solution i found was using Windows XP as my primary OS and adding Debian version on virtual machine. You may be asking why should this solution be said when it is well known and made by some many users but actually, i made some modifications to this solution.

What i did can be summarized in these following points:

  • installing debian without any interface at all, just a shell no more
  • using virtual machine shared folder technique to share a folder between my XP machine and my Linux machine
  • installed ZOC program which is a powerful shell program that allows connecting using openssh and supports multi tabs which is very important feature not available in putty
  • installed openssh-server on debian
  • fixed an IP for my debian machine so as to save my openssh configuration one time only without changing it each time i connect to it

This way, i enjoy my XP machine and whenever i need the shell of linux. i connect using openssh on my debian virtualized machine and do what i want

I use this solution while developing ROR applications, i prepared the environment i use as follows

  • installed ruby, rails, mysql on my debian machine
  • opened remote connections to mysql database so as to use MySQL Query Browser from XP machine

Now, i open my IDE on XP machine that changes in folders place in the shared folder between two machines and i open my server from virtual machine and test apps on debian machine IP rather than my localhost

This experience is great and i enjoy it so much as i feel i have the power of each environment Windows & Linux at the same time

In order to optimize the performance of my Virtual Machine somehow, i raised the priority of these virtualized processes to ‘High’ or even ‘Realtime’. it is now better but not perfect

I think in order to raise the performance significantly, i need to buy another motherboard supporting Intel VT technology. Using such technology i can move virtualization from software layer (being a process that Windows XP Scheduler deal with) to hardware layer which should improve performance as stated

That’s it, i suggest you try this experience and Enjoy as i do

Sunday, April 12, 2009

Export Google Document To WIKI STYLE Document

the idea is simple and only needed is that you do some simple steps and you are done

follow the following steps:

  • save google document as HTML file
  • view html page source and extract the html inside document body tag
  • use this great tool and add in it the html you copied and you will have the wiki style document generated

That’s it, you now have the document you wrote in WIKI style. Take this text and play with it as you wish