Thursday 15 November 2012

Equality method

Sometimes i get caught by the equality methods and thus have decided to concrete it so that it stays
in me for years to come


 eql? 

 => whether the contents are same or equal
       a = "cat" ; b = "dog" ; c = "cat"

a.eql? b => false ( that is obvious ... how can a cat be same as dog)

a.eql? c => true ( it definitely make sense as long as the content are same)

a == c  => true

N.B : Be careful while using == method as because Numeric type perform type conversion across.

Say for example
         2 == 2.0 => true
but
        2.eql? 2.0 => false


equal?

a = ["cat", "dog"]; b = ["cat", "dog"]

a.object_id => 12346
b.object_id => 34567

Since a and b objects have same content but the message(object_id) called on the receivers(a and b) returns different values, so the equal? method checks for the same object id.

a = :cat; b = :cat

a.object_id => 123
b.object_id => 123

In this case both a and b are referring to the same object.

Tuesday 6 November 2012

Tuesday 23 October 2012

MathML

What is MathML?

MathML 3.0 was released as a W3C Recommendation on 21 October 2010. It is a revision of MathML 2.0, issued seven years ago. A product of the W3C Math Working Group, MathML is a low-level specification for describing mathematics as a basis for machine to machine communication which provides a much needed foundation for the inclusion of mathematical expressions in Web pages. It is also important in publishing workflows for science and technology and wherever mathematics has to be handled by software. The new version brings, for instance, improvements for accessibility of mathematics, and for formulas in languages written from right to left. 


Mathematical Markup Language (MathML) is an application of XML for describing mathematical notations and capturing both its structure and content. It aims at integrating mathematical formulae intoWorld Wide Web pages and other documents. It is a recommendation of the W3C math working group.

Wednesday 3 October 2012

Called id for nil


 "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id"
As a Ruby on Rails developer I am very much familiar with the above kind of error and often i used to bang my head as to why this.... and at last am able to find the reason behind it.

When Ruby interpreter boots up it initializes FalseClass, TrueClass and NilClass. As we know that false, true variable work 
exactly the same way as nil does.They are singleton instances of 
FalseClass and TrueClass,respectively.


false.object_id
 => 0

true.object_id
 => 2

nil.object_id
 => 4

What happened to 1 and 3? Well, the first bit is reserved for Fixnum values (numbers) only


Monday 23 April 2012

SSL handshake failed: Secure connection truncated.



One fine morning i found that my svn update or svn up was not working and was totally blank? :P
Here is what i did to make my svn stand up... :)
  1. sudo apt-get install libneon27

  2. cd /usr/lib

  3. sudo rm libneon-gnutls.so.27

  4. and create a soft link 
       sudo ln -s /usr/lib/libneon.so.27 libneon-gnutls.so.27
and finally svn was running.  :P



Wednesday 28 March 2012

Comparing execution time between string and symbols of ruby


Hi,
   You all must be knowing the difference between Ruby string and symbol but i want to prove a point that symbols execution time is less than string.

Try this piece of code in Pry or IRB

 require 'benchmark'

str = Benchmark.measure do
  10_000_000.times do
    "test"
  end
end.total

sym = Benchmark.measure do
  10_000_000.times do
    :test
  end
end.total


Comparing symbols is much faster than string:


require 'benchmark'

str = Benchmark.measure do
  10_000_000.times do
    "test" == "test"
  end
end.total

sym = Benchmark.measure do
  10_000_000.times do
    :test == :test
  end
end.total