Sunday 5 May 2013

If you have any doubts over why we are doing something, you should ask someone immediately, or write them down to investigate later


Q:  Full text search

PostgreSQL
Elasticsearch
Sphinx - fully developed
Solr   - fully developed


How does rails index works ?


Facts:

map outputs an array with the ability to do some computational on it.

Facts:

user = User.where(:name => 'tapan')  --> It builds sql query
user.first --> Execute the query in other words it now talks with databases.

NameError
NoMethodError

Curiosity:  Just know commented on this video, waiting for approval

http://www.youtube.com/watch?v=mBXGBbEbXZY

Q. Why do we use symbol ?

 
bihar = {state: 'bihar', capital: 'patna'}

then, india.keys.map(&:object_id) => [163848, 3119208] (some arbitrary ids)

karnataka = {state: 'karnataka', capital: 'bangalore'}

india.keys.map(&:object_id) => [163848, 3119208] (some arbitrary ids)

Here it returns the same object id for keys(state, capital).

So it references the same symbol and thus saves memory.

Q. Why  does Symbol.all_symbols.include? :hello  

       always return true

   => It happens as because it will go and first check in the array whether this particular symbols exists ? and it happens to be present there then returns true : else it will be pushed to the array and then return true

Concatenation

1. puts "tapan" + "sharma"
2. puts "tapan".concat("sharma")
3. puts "tapan" "sharma"

Chaining if's

   
  puts "hello boy" if 1 == 1 if 2 == 2

Ruby zip method


order = %w{1 2 3 4}
animals = %w{ant bat cat dog elephant}
p order.zip(animals)
=> [["1", "ant"], ["2", "bat"], ["3", "cat"], ["4", "dog"]]
p Hash[order.zip(animals)]
=> {"1"=>"ant", "2"=>"bat", "3"=>"cat", "4"=>"dog"}

Array creation

a = [*1..8]

Json


 require 'json'

h = {a: 'apple', b: 'boy', c: 'cat'}
j h 
 => {"a":"apple","b":"boy","c":"cat"}

jj h  
=> {
  "a": "apple",
  "b": "boy",
  "c": "cat"
}

__method__ :

  check for method name.

source_location :

  this locates the method.

Difference between scopes and class method

http://blog.plataformatec.com.br/2013/02/active-record-scopes-vs-class-methods/

Method Look up in Ruby.

Very well explained and written.

http://blog.jcoglan.com/2013/05/08/how-ruby-method-dispatch-works/comment-page-1/#comment-11917"


StringInquirer is a subclass of String


Command to create dump and restore


  pg_dump dbname > outfile

 psql dbname < infile

 Take dump of some tables in postgresql

    pg_dump --table=tutor_invoices --table=students veritas_development > out.sql






No comments:

Post a Comment