Tuesday, August 26, 2014

has_many :grandchildren trick

class Person < ActiveRecord::Base
  belongs_to :parent, class: Person
  has_many :children, class: Person, foreign_key: :parent_id
  has_many :grandchildren, class: Person, through: :children, source: :children
end

Monday, August 25, 2014

Little bit ruby


% Notation
%q[ ] # Non-interpolated String (except for \\ \[ and \])
%Q[ ] # Interpolated String (default)
%r[ ] # Interpolated Regexp (flags can appear after the closing delimiter)
%i[ ] # Non-interpolated Array of symbols, separated by whitespace
%I[ ] # Interpolated Array of symbols, separated by whitespace
%w[ ] # Non-interpolated Array of words, separated by whitespace
%W[ ] # Interpolated Array of words, separated by whitespace
%x[ ] # Interpolated shell command

Sunday, August 24, 2014

Little bit about Graphs

simple - no multiarcs and loop
non-simpl(pseudog) - multiarcs and loop

complete - each node conect beetwen each other directly
conected - directly or nondirectli all nodes are conected
tree - conected graph without circle
spanning tree - tree with (nodes-1 == arcs), min arcs for connect all nodes
isomorphick - graph when (arcs == nodes)
sub - part of graph

ActiveSupport::Inflector

ActiveSupport::Inflector - transforms words from singular to plural, class names to table names, modularized class names to ones without, and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept in inflections.rb. 

Friday, August 22, 2014

PostgreSQL: array field

If we have array field in postgresql (like `tags`), we can use it for search as well:

- search records which contain `tag`
`ruby` = ANY(tags)
- search through array with tags
`{ruby, python, java}` && tags
- all tags should be equal `ruby`
`ruby` = ALL(tags)
 
 
Blogger Templates