Showing posts with label uri. Show all posts
Showing posts with label uri. Show all posts

Thursday, October 13, 2011

Escape or Encode the character using javascript or ruby

Guys,
          When we are storing the data in the database using any encoding method like UTF-8 and retrieve data in javascript it gives us in output in decode and unescape format.

To solve above issue using javascript or ruby
Javascript functions:
escape(String) - unescape(String)
encodeURI(String) - decodeURI(String)
encodeURIComponent(String) - decodeURIComponent(String)

Ruby methods:
CGI.escape(String) - CGI.unescape(String) or CGI.unescapeHTML(String)
URI.escape(String) - URI.unescape(String)

Online tool for escape/unescape, encode/decode the character.
http://www.the-art-of-web.com/javascript/escape/

Wednesday, October 5, 2011

Avoid the memory blockage during large xml request

Guys,
        When i am playing with handling the xml request through net::http discover the problem of memory blockage and just worried about how to handle that. This problem happen b'coze i have bulk of xml data in the request. So, i form the one of the solution by using the block of net http.

When we using the block of net::http. It yields each fragment of the entity body in turn as a string as it are read from the socket.

Lets we consider 2 scenario:

require 'rubygems'
require 'net/https'
require 'uri'
uri = URI.parse("http://google.com")
http = Net::HTTP.new(uri.host, uri.port)

case 1:
response = http.post('http://google.com', 'query=language')

case 2:
# using block
   File.open('test.txt',  'w') { |f|
      http.post('http://google.com', 'query=language') do |str|
          f.write str
       end
   }

In case 1 it loads the entire response in memory. While in case 2 it read each fragment and write into file. so when we use block it's avoid memory blockage.
For more information just follow

Hope above post will help you to avoid memory blockage and increase performance.