Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Git blog

  • Loading branch information...
commit 1166153b1f6fdfbc2de676b092fe1af7b154099e 0 parents
@bogdan authored
Showing with 9,972 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +102 −0 Rakefile
  3. +9 −0 _config.yml
  4. +15 −0 _extensions/jekyll_ext.rb
  5. +21 −0 _includes/cloud.html
  6. +9 −0 _includes/tags.html
  7. +123 −0 _layouts/default.html
  8. +35 −0 _layouts/post.html
  9. +4 −0 _layouts/tag.html
  10. +74 −0 _posts/2009-04-03-upload-files-with-selenium-ide
  11. +9 −0 _posts/2009-04-08-technical-documentation.html
  12. +8 −0 _posts/2009-04-09-brain-async.html
  13. +22 −0 _posts/2009-04-10-success-components.html
  14. +33 −0 _posts/2009-04-23-clear-upload-file-input-field.html
  15. +61 −0 _posts/2009-04-28-ant-task-to-install-tomcat-service.html
  16. +20 −0 _posts/2009-04-29-some-programming-aphorisms.html
  17. +43 −0 _posts/2009-04-30-update-and-create-timestamps-with-mysql.html
  18. +26 −0 _posts/2009-05-04-jboss-seam-usage-makes-the-application-code-crazy.html
  19. +29 −0 _posts/2009-05-05-what-do-you-expect-from-interface.html
  20. +52 −0 _posts/2009-05-13-how-to-choose-a-good-sexy-title-for-your-article.html
  21. +44 −0 _posts/2009-06-02-avoid-nested-select-double-single-table-complex-query.html
  22. +20 −0 _posts/2009-06-08-pragmatic-review-view-google-wave-criticism-technolog.html
  23. +40 −0 _posts/2009-06-29-bdd-user-stories-productive-tdd-criticism.html
  24. +37 −0 _posts/2009-07-30-computer-science-programming-criticism-object-database-design.html
  25. +58 −0 _posts/2009-10-27-objects-behaviour-inheritance-with-rspec.html
  26. +16 −0 _posts/2009-12-01-vim-as-ruby-on-rails-ide-development-perfomanc.html
  27. +37 −0 _posts/2010-01-24-sql-queries-activerecord-rails-named-scopes-stack.html
  28. +14 −0 _posts/2010-03-29-quality-develop-application-improve-usability-design.html
  29. +69 −0 _posts/2010-04-05-ruby18-private-protected-incapsulatio.html
  30. +35 −0 _posts/2010-04-20-dom-element-class-html-javascript-reference.html
  31. +147 −0 _posts/2010-06-08-nesting-namespace-route-non-flat-controllers-hierarchy-rails.html
  32. +41 −0 _posts/2010-06-30-ultimate-rspec-matcher-to-test-validation.html
  33. +80 −0 _posts/2010-07-11-bdd-rspec-matcher-to-test-named_scope-scoped-rails-3.html
  34. +45 −0 _posts/2010-08-26-populate-db-pattern-fake-data.html
  35. +26 −0 _posts/2010-09-30-good-passwords-theory.html
  36. +62 −0 _posts/2010-11-03-dynamic-context-in-rspec-dont-repeat-yourself.html
  37. +31 −0 _posts/2011-03-18-ajax-jquery-debug-javascript.html
  38. +58 −0 _posts/2011-03-28-do-git-commits-associated-to-hoptoad-errors.html
  39. +42 −0 _posts/2011-04-06-javascript-injection-in-json-inserted-directly-into-script-tag.html
  40. +44 −0 _posts/2011-05-20-migrate-wordpress-jekyll-post-preview.md
  41. +27 −0 atom.xml
  42. +1 −0  build
  43. +178 −0 css/default.css
  44. +129 −0 css/default.sass
  45. +1,231 −0 gusiev_com.sql
  46. BIN  images/email.jpg
  47. BIN  images/favicon.ico
  48. BIN  images/fork.png
  49. BIN  images/me.jpg
  50. BIN  images/rss.png
  51. +92 −0 importer.rb
  52. +39 −0 index.html
  53. +56 −0 pages/about.html
  54. +12 −0 pages/contacts.html
  55. +3 −0  robots.txt
  56. +9 −0 tags/activerecord.html
  57. +7 −0 tags/ajax.html
  58. +7 −0 tags/ant.html
  59. +7 −0 tags/aphorism.html
  60. +8 −0 tags/application.html
  61. +7 −0 tags/architecture.html
  62. +7 −0 tags/article.html
  63. +7 −0 tags/author.html
  64. +8 −0 tags/bdd.html
  65. +8 −0 tags/behavior.html
  66. +7 −0 tags/behaviour.html
  67. +7 −0 tags/class.html
  68. +7 −0 tags/commit.html
  69. +7 −0 tags/context.html
  70. +7 −0 tags/controller.html
  71. +12 −0 tags/criticism.html
  72. +7 −0 tags/css.html
  73. +7 −0 tags/data.html
  74. +9 −0 tags/database.html
  75. +7 −0 tags/debug.html
  76. +7 −0 tags/design.html
  77. +7 −0 tags/documentation.html
  78. +7 −0 tags/dom.html
  79. +7 −0 tags/element.html
  80. +7 −0 tags/encapsulation.html
  81. +7 −0 tags/escape.html
  82. +7 −0 tags/fake.html
  83. +7 −0 tags/file.html
  84. +7 −0 tags/git.html
  85. +7 −0 tags/hoptoad.html
  86. +10 −0 tags/howto.html
  87. +9 −0 tags/html.html
  88. +7 −0 tags/humor.html
  89. +8 −0 tags/idea.html
  90. +9 −0 tags/index.html
  91. +7 −0 tags/inheritance.html
  92. +7 −0 tags/input.html
  93. +7 −0 tags/interface.html
  94. +7 −0 tags/it-related.html
  95. +9 −0 tags/java.html
  96. +10 −0 tags/javascript.html
  97. +7 −0 tags/jboss.html
  98. +7 −0 tags/jekyll.html
  99. +7 −0 tags/jquery.html
  100. +7 −0 tags/json.html
  101. +7 −0 tags/liquid.html
  102. +7 −0 tags/lsp.html
  103. +7 −0 tags/matcher.html
  104. +7 −0 tags/method.html
  105. +7 −0 tags/migration.html
  106. +7 −0 tags/mind.html
  107. +7 −0 tags/mysql.html
  108. +8 −0 tags/named_scope.html
  109. +7 −0 tags/nesting.html
  110. +7 −0 tags/oop.html
  111. +7 −0 tags/password.html
  112. +8 −0 tags/pattern.html
  113. +7 −0 tags/perfomance.html
  114. +7 −0 tags/php.html
  115. +7 −0 tags/populate.html
  116. +7 −0 tags/privacy.html
  117. +10 −0 tags/programming.html
  118. +7 −0 tags/quality.html
  119. +8 −0 tags/query.html
  120. +9 −0 tags/rails.html
  121. +7 −0 tags/random.html
  122. +7 −0 tags/reader.html
  123. +7 −0 tags/review.html
  124. +7 −0 tags/route.html
  125. +10 −0 tags/rspec.html
  126. +12 −0 tags/ruby.html
  127. +7 −0 tags/science.html
  128. +7 −0 tags/seam.html
  129. +7 −0 tags/security.html
  130. +7 −0 tags/select.html
  131. +7 −0 tags/service.html
  132. +8 −0 tags/sql.html
  133. +7 −0 tags/success.html
  134. +7 −0 tags/tdd.html
  135. +7 −0 tags/technology.html
  136. +8 −0 tags/test.html
  137. +7 −0 tags/testing.html
  138. +7 −0 tags/timestamp.html
  139. +7 −0 tags/title.html
  140. +7 −0 tags/tomcat26px.html
  141. +8 −0 tags/usability.html
  142. +7 −0 tags/user story.html
  143. +7 −0 tags/validation.html
  144. +7 −0 tags/vim.html
  145. +7 −0 tags/wave.html
  146. +7 −0 tags/windows.html
  147. +7 −0 tags/wordpress.html
  148. +7 −0 tags/xss.html
  149. +5,867 −0 wordpress.2011-05-18.xml
1  .gitignore
@@ -0,0 +1 @@
+_site/
102 Rakefile
@@ -0,0 +1,102 @@
+require 'rubygems'
+require 'jekyll'
+require "fileutils"
+require "sass/plugin"
+
+task :dev => :build do
+ c = Thread.new do
+ `compass watch --sass-dir css --css-dir css`
+ end
+ j = Thread.new do
+ `ejekyll --server --auto`
+ end
+ sleep(1)
+ c.join
+ j.join
+end
+
+task :build => [:tags, :cloud, :sass] do
+ def f(name)
+ File.dirname(__FILE__) + "/" + name
+ end
+ begin
+ FileUtils.mkdir_p(f("build"))
+ FileUtils.mkdir_p(f("tmp"))
+ FileUtils.mv(f("build/.git"), f("tmp"))
+ puts `jekyll --no-auto build`
+ ensure
+ FileUtils.mv(f("tmp/.git"), f("build"))
+ end
+end
+
+desc 'Generate tags page'
+task :tags do
+ puts "Generating tags..."
+
+ include Jekyll::Filters
+
+ FileUtils.mkdir_p("tags")
+ options = Jekyll.configuration({})
+ site = Jekyll::Site.new(options)
+ site.read_posts('')
+ site.tags.sort.each do |tag, posts|
+ html = ''
+ html << <<-HTML
+---
+layout: tag
+title: Posts tagged "#{tag}"
+---
+ <h1 id="#{tag}">Posts tagged "#{tag}"</h1>
+ HTML
+
+ html << '<ul class="posts">'
+ posts.each do |post|
+ post_data = post.to_liquid
+ html << <<-HTML
+ <li><a href="#{post.url}">#{post_data['title']}</a></li>
+ HTML
+ end
+ html << '</ul>'
+
+ File.open("tags/#{tag}.html", 'w+') do |file|
+ file.puts html
+ end
+ end
+ puts 'Done.'
+end
+
+
+task :cloud do
+ puts 'Generating tag cloud...'
+ include Jekyll::Filters
+
+ options = Jekyll.configuration({})
+ site = Jekyll::Site.new(options)
+ site.read_posts('')
+
+ html = ''
+
+ site.tags.sort.each do |category, posts|
+
+ s = posts.count
+ if s > 1
+ font_size = 14 + (s*1.8);
+ html << "<a href=\"/tags/#{category}.html\" title=\"Pages tagged #{category}\" style=\"font-size: #{font_size}px; line-height:#{font_size}px\" rel=\"tag\">#{category}</a> \n"
+ end
+ end
+
+ File.open('_includes/cloud.html', 'w') do |file|
+ file.puts html
+ end
+
+ puts 'Done.'
+end
+
+task :sass do
+ directory = File.dirname(__FILE__) + "/css"
+ Sass::Plugin.options[:template_location] = directory
+ Sass::Plugin.options[:css_location] = directory
+ Sass::Plugin.check_for_updates
+end
+
+
9 _config.yml
@@ -0,0 +1,9 @@
+rdiscount: true
+pygments: true
+auto: true
+lsi: true
+paginate: 10
+permalink: "/:year/:month/:title"
+url: "http://gusiev.com"
+content_delimeter: "<!--more-->"
+
15 _extensions/jekyll_ext.rb
@@ -0,0 +1,15 @@
+module Jekyll
+
+ class Post
+ def preview_content
+ delimeter = @site.config['content_delimeter'] || '<!-- -**-END-**- -->'
+ self.content.split(delimeter)[0]
+ end
+ end
+
+ AOP.around(Post, :to_liquid) do |post_instance, args, proceed, abort|
+ result = proceed.call
+ result['preview'] = post_instance.preview_content
+ result
+ end
+end
21 _includes/cloud.html
@@ -0,0 +1,21 @@
+<a href="/tags/activerecord.html" title="Pages tagged activerecord" style="font-size: 19.4px; line-height:19.4px" rel="tag">activerecord</a>
+<a href="/tags/application.html" title="Pages tagged application" style="font-size: 17.6px; line-height:17.6px" rel="tag">application</a>
+<a href="/tags/bdd.html" title="Pages tagged bdd" style="font-size: 17.6px; line-height:17.6px" rel="tag">bdd</a>
+<a href="/tags/behavior.html" title="Pages tagged behavior" style="font-size: 17.6px; line-height:17.6px" rel="tag">behavior</a>
+<a href="/tags/criticism.html" title="Pages tagged criticism" style="font-size: 24.8px; line-height:24.8px" rel="tag">criticism</a>
+<a href="/tags/database.html" title="Pages tagged database" style="font-size: 19.4px; line-height:19.4px" rel="tag">database</a>
+<a href="/tags/howto.html" title="Pages tagged howto" style="font-size: 21.2px; line-height:21.2px" rel="tag">howto</a>
+<a href="/tags/html.html" title="Pages tagged html" style="font-size: 19.4px; line-height:19.4px" rel="tag">html</a>
+<a href="/tags/idea.html" title="Pages tagged idea" style="font-size: 17.6px; line-height:17.6px" rel="tag">idea</a>
+<a href="/tags/java.html" title="Pages tagged java" style="font-size: 19.4px; line-height:19.4px" rel="tag">java</a>
+<a href="/tags/javascript.html" title="Pages tagged javascript" style="font-size: 21.2px; line-height:21.2px" rel="tag">javascript</a>
+<a href="/tags/named_scope.html" title="Pages tagged named_scope" style="font-size: 17.6px; line-height:17.6px" rel="tag">named_scope</a>
+<a href="/tags/pattern.html" title="Pages tagged pattern" style="font-size: 17.6px; line-height:17.6px" rel="tag">pattern</a>
+<a href="/tags/programming.html" title="Pages tagged programming" style="font-size: 21.2px; line-height:21.2px" rel="tag">programming</a>
+<a href="/tags/query.html" title="Pages tagged query" style="font-size: 17.6px; line-height:17.6px" rel="tag">query</a>
+<a href="/tags/rails.html" title="Pages tagged rails" style="font-size: 19.4px; line-height:19.4px" rel="tag">rails</a>
+<a href="/tags/rspec.html" title="Pages tagged rspec" style="font-size: 21.2px; line-height:21.2px" rel="tag">rspec</a>
+<a href="/tags/ruby.html" title="Pages tagged ruby" style="font-size: 24.8px; line-height:24.8px" rel="tag">ruby</a>
+<a href="/tags/sql.html" title="Pages tagged sql" style="font-size: 17.6px; line-height:17.6px" rel="tag">sql</a>
+<a href="/tags/test.html" title="Pages tagged test" style="font-size: 17.6px; line-height:17.6px" rel="tag">test</a>
+<a href="/tags/usability.html" title="Pages tagged usability" style="font-size: 17.6px; line-height:17.6px" rel="tag">usability</a>
9 _includes/tags.html
@@ -0,0 +1,9 @@
+<h4 class="tags">
+ {% for category in post.tags %}
+ <a href="/tags/{{ category }}.html">{{ category }}</a>
+ {% endfor %}
+ {% for category in page.tags %}
+ <a href="/tags/{{ category }}.html">{{ category }}</a>
+ {% endfor %}
+</h4>
+<div class="clear"></div>
123 _layouts/default.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+ <head>
+ <title>Bogdan Gusiev's blog</title>
+ <meta name="robots" content="follow, all" />
+ <link rel="stylesheet" href="/css/default.css" type="text/css" media="screen" />
+ <link rel="alternate" type="application/rss+xml" title="Bogdan Gusiev's blog RSS Feed" href="/atom.xml" />
+ <link rel="shortcut icon" href="/images/favicon.ico"/>
+ <title>{{ page.title }}</title>
+ <link rel="icon" href="/images/favicon.ico"/>
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
+ </head>
+
+ <body>
+
+ <div id="wrapper">
+
+ <div class="header">
+ <div class="title">
+ <h1><a href="/">Bogdan Gusiev's blog</a></h1>
+ <h4>How to make your Ruby on Rails application</h4>
+ </div>
+
+ <div class="pages">
+ <a href="/">Home</a>
+ <a href="/pages/about.html">About me</a>
+ <a href="/pages/contacts.html">Contacts</a>
+ </div>
+ <a href="/pages/about.html" class="avatar">
+ <img src="/images/me.jpg"/>
+ </a>
+ <div class="clear"></div>
+ <hr/>
+ </div> <!-- Closes header -->
+
+
+ <div id="main">
+
+ <div id="content">
+ {{ content }}
+ </div>
+ <div class="vsplit">
+ </div>
+ <div id="sidebar">
+ <div class="recent-posts">
+ <h2>Recent Posts</h2>
+ <a class="rss" href="/atom.xml">
+ <img src="/images/rss.png" alt="Bogdan Gusiev&#8217;s blog" />
+ </a>
+ <div class="clear"></div>
+ <ul>
+ {% for post in site.posts limit:5 %}
+ <li>
+ <a href='{{ post.url }}'>{{ post.title }}</a>
+ </li>
+ {% endfor %}
+ </ul>
+ </div>
+ <div class="sidebarbox">
+ <h2>Search</h2>
+ <p>Use the form below to search the site:</p>
+ <form method="get" id="searchform" action="">
+ <input type="text" placeholder="Search keywords" name="s" id="searchbox"/>
+ <input type="submit" class="submitbutton" value="Find it" />
+ </form>
+ <script>
+ $('#searchform').submit(function(event) {
+ event.preventDefault();
+ window.location.href = "http://google.com/search?q=site:gusiev.com " + $('#searchbox').val();
+ });
+ </script>
+ </div>
+ <div class="sidebarbox tag-cloud">
+ <h2>Browse by tags</h2>
+ {% include cloud.html %}
+ </div>
+ </div><!-- Closes Sidebar_full -->
+ <div class="clear"></div>
+ </div> <!-- Closes Sidebar -->
+ <div class="clear"></div>
+
+ </div><!-- Closes Main -->
+
+
+ <div class="footer">
+ <hr/>
+ <!--LiveInternet counter-->
+ <script type="text/javascript">
+ document.write("<a href='http://www.liveinternet.ru/click' "+
+ "target=_blank><img src='http://counter.yadro.ru/hit?t40.6;r"+
+ escape(document.referrer)+((typeof(screen)=="undefined")?"":
+ ";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
+ screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
+ ";"+Math.random()+
+ "' alt='' title='LiveInternet' "+
+ "border='0' width='31' height='31'><\/a>");
+ </script><!--/LiveInternet-->
+ <!--SpyLOG-->
+ <span id="spylog2009244"></span><script type="text/javascript"> var spylog = { counter: 2009244, image: 26, next: spylog }; document.write(unescape('%3Cscript src%3D"http' + (('https:' == document.location.protocol) ? 's' : '') + '://counter.spylog.com/cnt.js" defer="defer"%3E%3C/script%3E')); </script>
+ <!--SpyLOG-->
+ <script type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script>
+ <script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-12663165-1");
+ pageTracker._trackPageview();
+ } catch(err) {}</script>
+ The Content of this blog can be published anywhere with the link to original source.
+ </div><!-- Closes morefoot -->
+
+
+
+
+ </body>
+ </html>
+
+
+
35 _layouts/post.html
@@ -0,0 +1,35 @@
+---
+layout: default
+---
+<div id="post">
+ <h2>
+ {{ page.title }}
+ <div class="date">{{ page.date | date_to_string }}</div>
+ </h2>
+ {{ content }}
+ {% include tags.html %}
+
+ <div id="related">
+ <h3>Related Posts</h3>
+ <ul class="posts">
+ {% for post in site.related_posts limit:3 %}
+ <li><span>{{ post.date | date_to_string }}</span> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li>
+ {% endfor %}
+ </ul>
+ </div>
+
+ <div id="disqus_thread"></div>
+<script type="text/javascript">
+ var disqus_shortname = 'gusiev'; // required: replace example with your forum shortname
+
+ //var disqus_identifier = '{{ page.url }}';
+ //var disqus_url = '{{ site.url }}{{ page.url }}';
+
+ (function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ })();
+</script>
+</div>
+
4 _layouts/tag.html
@@ -0,0 +1,4 @@
+---
+layout: default
+---
+{{ content }}
74 _posts/2009-04-03-upload-files-with-selenium-ide
@@ -0,0 +1,74 @@
+---
+layout: post
+title: Upload files with Selenium IDE
+tags:
+- selenium
+- java
+---
+I started using selenium about 2 weeks ago. Find it as a very good QA tool.
+But after a few successfully written tests I met the problem: Selenium is not able to use file input field. JavaScript permission restriction doesn't allow it.<br/><br/>
+
+Here is my solution written with <a target="_blank" href="http://jinvoke.com">JInvoke library</a>: Jinvoke provides the classes to simulate the input to file chooser form.<br/>
+
+<!--more-->
+<hr/>
+The problem I meat is selenium is stuck when simulate the click on upload file input. I have to launch the concurent thread that do the file name input. Thread code(Note file name should be given in Java format like 'c:/boot.ini):
+
+<div class="bordered">
+<code>import javax.swing.*;
+import java.awt.event.KeyEvent;
+import java.awt.*;
+
+/**
+ * @author Bogdan Gusiev
+ * Date 29.03.2009
+ */
+public class FileChooserThread extends Thread {
+
+ public FileChooserThread(String file) {
+ super(new FileRunner(file));
+ }
+}
+
+class FileRunner implements Runnable {
+
+ private String fullName;
+
+ public FileRunner(String fileName) {
+ this.fullName = fileName;
+ }
+
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ Robot robot = new Robot(); //input simulation class
+ for (char c : fullName.toCharArray()) {
+ if (c == ':') {
+ robot.keyPress(KeyEvent.VK_SHIFT);
+ robot.keyPress(KeyEvent.VK_SEMICOLON);
+ robot.keyRelease(KeyEvent.VK_SHIFT);
+ } else if (c == '/') {
+ robot.keyPress(KeyEvent.VK_BACK_SLASH);
+ } else {
+ robot.keyPress(KeyStroke.getKeyStroke(
+ Character.toUpperCase(c), 0).getKeyCode());
+ }
+ }
+ robot.keyPress(KeyEvent.VK_ENTER);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}</code>
+</div>
+Here is selenium call method:
+
+<div class="bordered">
+<code >protected void chooseFile(String element, String fileName) {
+ Number positionLeft = selenium.getElementPositionLeft(element);
+ Number positionTop = selenium.getElementPositionTop(element);
+ new FileChooserThread(fileName).start(); //launch input thread.
+ //this method will held current thread while FileChooser gives the file name
+ selenium.clickAt("file", positionLeft + "," + positionTop);
+}</code></div>
9 _posts/2009-04-08-technical-documentation.html
@@ -0,0 +1,9 @@
+---
+layout: post
+title: Technical documentation
+tags:
+- documentation
+- it-related
+---
+There is no one technical book I read more than a half. Is everybody doing this way?
+I recommend book authors to explain themselves in more short form.
8 _posts/2009-04-09-brain-async.html
@@ -0,0 +1,8 @@
+---
+layout: post
+title: Brain async
+tags:
+- mind
+---
+Many people came to the question: Why do our brain is having so many gaps: forget important info, quickly change opinion, stuck when doing usual actions, etc? Well, try to look from the different side.<br/>
+Our brain is about 4 million of neurons('processors') that works completely async: neural impulses follow though brain without any rules and permissions, every neuron process the information in there own way, no body is able to re implement such a large information processing system. From this point of gap are normal and true solutions and that is being solved by our brain every day is a miracle.
22 _posts/2009-04-10-success-components.html
@@ -0,0 +1,22 @@
+---
+layout: post
+title: "Components of success "
+tags:
+- success
+---
+People from different countries are reaching success in completely different way. And that is good because no matter who you are you can be successful. I heard a lot of success stories and now can summarize - what components are required to build your own success story...<br/>
+<!--more-->
+<br/>
+Here are the components:<br/>
+<h5> Hard work </h5>
+That's it. This is may be the most important one. Don't think you can be successful while sitting on the chair and do nothing.
+
+<h5> Intellect </h5>
+Many people work hard whole life and stay where they are without moving ahead. That is a pity that sometimes hard work is done in the wrong direction. Also try to look several steps ahead and see the perspective of the work you do.
+
+<h5>Risk</h5>
+Risk is a very helpful component. You can go the most reliable way. But in fact add some risk can seriously improve the result. Do something without risk is impossible because there is always a risk that your work is useless.
+
+<h5>Luck</h5>
+Yes, that's it. This component is very important. All above components are nothing without luck and there is also some good and bad tricks in our way that we can not forecast.
+
33 _posts/2009-04-23-clear-upload-file-input-field.html
@@ -0,0 +1,33 @@
+---
+layout: post
+title: "Clear upload file input field "
+tags:
+- javascript
+- howto
+- input
+- file
+- html
+---
+Many web developers came to the problem that they are not able to change value of file input field from Java Script in the web application. There is no access to value field of file input tag because of security restriction. However there is a trick how to erase this field if you need it in your application. <br/>
+<!--more-->
+<hr/>
+You can simply redraw the html block where your input tag is located. In this case all data will remain the same except the selected file value.
+
+<pre><code>
+&lt;div id="uploadFile_div"&gt;
+&lt;input type="file" class="fieldMoz" id="uploadFile"
+ onkeydown="return false;" size="40" name="uploadFile"/&gt;
+&lt;/div&gt;
+&lt;a onclick="clearFileInputField('uploadFile_div')"
+ href="javascript:noAction();"&gt;Clear&lt;/a&gt;
+</code></pre>
+Java Script function below looks strange but acts exactly in the way we want:
+<pre><code>
+&lt;script&gt;
+function clearFileInputField(tagId) {
+ document.getElementById(tagId).innerHTML =
+ document.getElementById(tagId).innerHTML;
+}
+&lt;/script&gt;
+
+</code></pre>
61 _posts/2009-04-28-ant-task-to-install-tomcat-service.html
@@ -0,0 +1,61 @@
+---
+layout: post
+title: Ant task to install tomcat service26px
+tags:
+- java
+- howto
+- ant
+- tomcat26px
+- windows
+- service
+---
+If you are familiar to run Apache Tomcat as Windows service, you can install it with the ant task. <i>build.xml</i> file sample under the cut line.
+<!--more-->
+<hr/>
+First of all let's do some properties setup:
+
+<pre><code>catalina.home=d:/java/tomcat-6.0.18
+tomcat.executable=${catalina.home}/bin/tomcat6.exe
+tomcat.service.executable=\
+${catalina.home}/bin/service.bat
+tomcat.service.name=myproject
+# parameters that will be used in the jvm
+tomcat.service.jvm.ms=128
+tomcat.service.jvm.mx=256
+</code></pre>
+Service startup task consists of 5 exec commands:
+<ul>
+ <li>Stop service if currently running</li>
+ <li>Delete service if installed</li>
+ <li>Install service with bat script</li>
+ <li>Update service with some parameters</li>
+ <li>Start service</li>
+</ul>
+
+Here is the implementation:
+<pre><code>
+ &lt;target name="tomcat.service.install" description="Install tomcat service"&gt;
+
+ &lt;exec command="net stop ${tomcat.service.name}"
+ failifexecutionfails="false"
+ failonerror="false"/&gt;
+
+ &lt;exec command="${tomcat.executable} //DS//${tomcat.service.name}"
+ failifexecutionfails="false"
+ failonerror="false"/&gt;
+ &lt;exec executable="${tomcat.service.executable}"
+ failifexecutionfails="true" failonerror="true"&gt;
+ &lt;env key="CATALINA_HOME" value="${catalina.home}"/&gt;
+ &lt;arg value="install"/&gt;
+ &lt;arg value="${tomcat.service.name}"/&gt;
+ &lt;/exec&gt;
+ &lt;exec executable="${tomcat.executable}"&gt;
+ &lt;arg value="//US//${tomcat.service.name}"/&gt;
+ &lt;arg value="--JvmMs=${jvm.ms}"/&gt;
+ &lt;arg value="--JvmMx=${jvm.mx}"/&gt;
+ &lt;arg value="--Startup=auto"/&gt;
+ &lt;/exec&gt;
+ &lt;exec command="net start ${tomcat.service.name}"
+ failifexecutionfails="true" failonerror="true"/&gt;
+ &lt;/target&gt;
+</code></pre>
20 _posts/2009-04-29-some-programming-aphorisms.html
@@ -0,0 +1,20 @@
+---
+layout: post
+title: Aphorisms about programming
+tags:
+- humor
+- programming
+- aphorism
+---
+I am not clever. I am just yet another way to use google.<br/>
+Good programmer should be lazy.<br/>
+The hole in your pocket is not critical unless you have a hole in your other pocket.<br/>
+<!--more-->
+<hr/>
+Software is like sex - better when it is free. Linus Torvalds.<br/>
+Sometimes the theory meets practice. Practice wins. Always.<br/>
+10% of your zeals brings you 90% of success. Other 90% just 10% of success.<br/>
+About haste: The perfection of a clock is not in the speed of the movement, but in its correctness.<br/>
+Don't be satisfied with an apparent fix; full understanding is the standard.<br/>
+If you only know one language, no matter how well you know it, you're not a great programmer.<br/>
+The only "best practice" you should be using all the time is "Use Your Brain".<br/>
43 _posts/2009-04-30-update-and-create-timestamps-with-mysql.html
@@ -0,0 +1,43 @@
+---
+layout: post
+title: Update and create timestamps with MySQL
+tags:
+- howto
+- mysql
+- timestamp
+- database
+---
+A lot of relational tables need created and update timestamps columns. I prefer having them for all tables with no exception. However, most of applications I am working on are running MySQL. MySQL has minor limitation on timestamps. Unfortunately you can create only one time stamp column that has <em> DEFAULT NOW()</em> value. Read more to see how to avoid this limitation. <!--more-->
+<hr/>
+The simplest way to do this is create the following columns in the table:
+<div class="bordered"><code>stamp_created timestamp default now(),
+stamp_updated timestamp default now() on update now()) </code></div>
+But MySQL will return the following error: <br/>
+<em>ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_ in DEFAULT or ON UPDATE clause</em> <br/>
+You can use only one of the definitions in one table. However here is the way how to create both timestamps columns:
+<pre><code> create table test_table(
+id integer not null auto_increment primary key,
+stamp_created timestamp default '0000-00-00 00:00:00',
+stamp_updated timestamp default now() on update now()
+); </code></pre>
+Note that it is necessary to enter nulls into both columns during "insert":
+<pre><code> mysql&gt; insert into test_table(stamp_created, stamp_updated) values(null, null);
+Query OK, 1 row affected (0.06 sec)
+mysql&gt; select * from t5;
++----+---------------------+---------------------+
+| id | stamp_created | stamp_updated |
++----+---------------------+---------------------+
+| 2 | 2009-04-30 09:44:35 | 2009-04-30 09:44:35 |
++----+---------------------+---------------------+
+2 rows in set (0.00 sec)
+mysql&gt; update test_table set id = 3 where id = 2;
+Query OK, 1 row affected (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 0
+mysql&gt; select * from test_table;
++----+---------------------+---------------------+
+| id | stamp_created | stamp_updated |
++----+---------------------+---------------------+
+| 3 | 2009-04-30 09:44:35 | 2009-04-30 09:46:59 |
++----+---------------------+---------------------+
+2 rows in set (0.00 sec)
+mysql&gt;
+</code></pre>
26 _posts/2009-05-04-jboss-seam-usage-makes-the-application-code-crazy.html
@@ -0,0 +1,26 @@
+---
+layout: post
+title: JBoss Seam usage makes the application code crazy!
+tags:
+- java
+- programming
+- jboss
+- seam
+- criticism
+---
+Seam Application has a number of good innovations but let's find out if we lose some advantages that we had before. I started application development with JBoss Seam one year ago. With the code base growth I have had more and more problems in workflow development .
+<!--more-->
+<hr/>
+I noticed that there are many problems which we have not had before, for example:
+<ul>
+ <li>Utility methods calls are not straight and clear now.</li>
+ <li>Find all usages IDE has feature became useless because of mass EL calls.</li>
+ <li>There is much of the meta programming in such a severe OOP language as Java.</li>
+ <li>It is impossible to debug JSF templates</li>
+ <li>Seam Exceptions look so unclear.</li>
+</ul>
+
+Programming with Seam has all disadvantages of script languages like PHP or Ruby.
+ I definitely admit that some features like Conversations and Native AJAX support made a big step forward. There is a lot of information in the net about How cool is seam but I tried to reveal the underside.<br/>
+<br/>
+Think twice before switching to Seam.
29 _posts/2009-05-05-what-do-you-expect-from-interface.html
@@ -0,0 +1,29 @@
+---
+layout: post
+title: What do you expect from the interface?
+tags:
+- java
+- programming
+- interface
+- idea
+- lsp
+---
+Read a great article today - <a href="http://www.google.com.ua/url?sa=t&source=web&ct=res&cd=3&url=http%3A%2F%2Fwww.objectmentor.com%2Fresources%2Farticles%2Flsp.pdf&ei=xjb_Sbi-EJbItge-ocmSDA&usg=AFQjCNFnNI0DmzofjWDQEGILAT-W1L8Mtw&sig2=okCh8NuqsQslKMTSWOlaTw"> Liskov Substitution Principle (LSP)</a>. It let me understand that Interface is not just a list of methods.<br/>
+<!--more-->
+<hr/>
+Let's review the following utility function:
+<div class="bordered">
+<code>public static void processList(List list) {
+ list.clear();
+ list.add(new Object());
+}</code>
+</div>
+It accepts the object that implements <em>java.utils.List</em> interface as the parameter.
+What do you expect to receive in result? The list with one element, right?<br/>
+But does the result really meet your expectation? Who knows, the object that implements list interface do not guarantee you 'Act as container' behavior. It just implements all the methods of the interface and nothing else.<br/>
+Actually all methods of the interface <strike>should have</strike> have a notation of their usage. If you do not follow these notations - you should not inherit your object from the interface even if the object has all the methods of the interface.<br/>
+<br/>
+<strong>Idea:</strong> Maybe one day programming languages will have unit tests as part of interface and validate each instance that implements this interface with them.
+
+
+
52 _posts/2009-05-13-how-to-choose-a-good-sexy-title-for-your-article.html
@@ -0,0 +1,52 @@
+---
+layout: post
+title: How to choose a sexy title for your article
+tags:
+- howto
+- idea
+- title
+- article
+- reader
+- author
+---
+Most of the people will not spend a minute reading your article if they wouldn't get interested from the very beginning. What resides at the beginning of any article? <strong>It is the title of course.</strong>
+That is why choose a good title is very important for every content posted in the net.
+<!--more-->
+<hr/>
+
+Title should not reflect the overall idea of your article, let it <b>just be cool</b>. Attracting users attention is more important. It should be the key point of what are you righting about<br/>
+<br/>
+
+Here is my idea: <strong>Title looks cool for the reader if it is close to his thoughts. </strong><br/>
+Reader should feel himself close to the topic you are going to speak about.
+Let's find out and see what do our mind filled in and describe some title choosing principles:
+
+<h4>Emotions</h4>
+Emotions acts like a catalyst. Expressing strong emotion in the title will give you the most effective result. People are getting interested not only when your emotion correspond to their but also vice versa.<br/>
+Example: <a href="/2009/05/jboss-seam-usage-makes-the-application-code-crazy/">JBoss Seam usage makes the application code crazy!</a>
+
+<h4>Questions</h4>
+In most cases the reader is somebody who want to know more about the world. Put a question in the title and it will engage everybody who wants to know the answer. <br/>
+Like this one: <a href="/2009/05/what-do-you-expect-from-interface/">What do you expect from the interface?</a>
+
+
+<h4>Famous topics</h4>
+<ul>
+ <li>Humor is top theme on every forum, every blog, every site all the time. Joking title is a good way to awake the interest.</li>
+ <li>Sex. You noticed the title of this article, right?</li>
+ <li>Weather</li>
+ <li>Politics</li>
+ <li>Sports</li>
+ <li>etc.</li>
+</ul>
+<br/>
+Making a slight reference in the title to one of above mentioned topics will attract much more attention to your article<br/>
+I hope this information was helpful. Thanks for reading.
+
+
+
+
+
+
+
+
44 _posts/2009-06-02-avoid-nested-select-double-single-table-complex-query.html
@@ -0,0 +1,44 @@
+---
+layout: post
+title: Double select from a single table in complex SQL query.
+tags:
+- sql
+- nesting
+- query
+- select
+---
+When I start learning SQL I have to write a lot of nested queries when working on complex select statements from a single table. Now, I feel more comfortable with it and show how to avoid nesting. There are cases when you have to compare one row of the table with all others to get the result:
+<ul>
+ <li>Select next element to current by the value of some field</li>
+ <li>Select records that are unique by some complex expression</li>
+ <li>Select all records that have the same parameter as given record.</li>
+</ul>
+You can get rid of nesting in all above cases. Let's review the example.
+<!--more-->
+
+<hr />Let's say we have the list of elements in `elements` table and we have the id of some element in this table. Now we have to get the next element from the list ordered by `sort_field`.
+That could be easily done with the nested select statement:
+<pre>
+<code>select * from elements e
+where e.sort_field >=
+ (select * from elements where element_id = #value#) and
+ e.element_id != #value#
+order by e.sort_field limit 1;
+</code>
+</pre>
+Looks not very cool.
+Let's do the select statement from `element` table twice to avoid nesting:
+<pre><code>-- The e1 is the result row and e2 is a helper row
+--that was picked up using nested select previously.
+select e1.* from elements e1, elements e2
+--conditional statement will look like
+where e1.sort_field &gt;= e2.sort_field and
+ e1.element_id != e2.element_id and
+ e2.element_id = #value#
+-- and the end of the query remains almost the same
+order by e1.sort_field limit 1
+</code></pre>
+
+Do not scare of double select from single table. That is the same technique as if they were different tables.
+
+
20 _posts/2009-06-08-pragmatic-review-view-google-wave-criticism-technolog.html
@@ -0,0 +1,20 @@
+---
+layout: post
+title: Pragmatic review of Google Wave technology
+tags:
+- criticism
+- technology
+- review
+- wave
+---
+Have a good time watching the <a href="http://www.youtube.com/watch?v=v_UyVmITiYQ">Google Wave presentation video</a>. Looks like an excellent open technology that will make our life easier. I like the overall idea. It is really awesome. But I personally admit some things that seems useless to me...<br/>
+<!--more-->
+<hr/>
+Starting from the very beginning I need to say: Wow! Now we can organize all communication threads to the widespread object called <strong>Wave</strong> that will be readable and editable by any other application. No more browsing dozen of sites and tracking all changes around - all interested waves can be reorganized in the way you want.<br/>
+Let's review the features now:<br/>
+<ul>
+ <li> Act as Wiki. Wiki can be handled via Waves too, but not sure about parallel editing. That looks sexy on presentation but has no sense in action.</li>
+ <li>Translation to another languages. I would like to have that on my desktop. Don't think it would be useful then doing the real time communication. Machine translation never was good enough.</li>
+ <li> Spell checker based on language model. Many people around worked on language model and no one has built it strong enough to handle automatic spell check. Let's wait for release and see if Google guys reach the success here.</li>
+
+</ul>
40 _posts/2009-06-29-bdd-user-stories-productive-tdd-criticism.html
@@ -0,0 +1,40 @@
+---
+layout: post
+title: When BDD user stories is productive
+tags:
+- criticism
+- bdd
+- tdd
+- test
+- behavior
+- application
+- user story
+---
+When you are skilled Unit tests writer it is not very easy to estimate the potential of BDD. Moreover in most cases BDD is used as a human-readable wrapper for unit tests. Do you really think that programmers need such abstract layer? Of course not... Users needs them.<br/>
+<!--more-->
+<hr/>
+
+Saying Users I mean every non technical person who will treat to application quality some how.
+Featured innovation of BDD is <strong>User Stories</strong> - a human-readable bit of specification with technical test implementation behind it. <br/>
+Let's review the following example from the blog specification:
+<pre><code>
+ Given I signed up as Author
+ When I write article "TDD and BDD"
+ And text of article is "BDD is ...."
+ And I post article
+ Then I should see "Article is created"
+ And I should see article title "TDD and BDD"
+</code></pre>
+As you can see unlike TDD human readability is the term that was brought to the high priority in BDD. But that is not yet a BDD story.<br/>
+We need the programming implementation for each phrase in the story, like this:
+<pre><code>
+"I signed up as Author":
+ signInAsAuthor();
+</code></pre>
+
+Programmer's task is to chose the implementation that will validate described behavior. User doesn't know about any programming back end of the story. When the test failed he just knows that some behavior of the application is not working properly any more. <br/>
+From this point of view the key principle of user story implementation is that it should <strong>guarantee</strong> with the most high probability that the user can complete described actions.<br/>
+
+Therefore user stories are the most productive when the implementation is done using <strong>GUI Robots</strong> like SWT bot, Selenium.
+
+
37 _posts/2009-07-30-computer-science-programming-criticism-object-database-design.html
@@ -0,0 +1,37 @@
+---
+layout: post
+title: Computer science ain't as good as it should be
+tags:
+- programming
+- database
+- criticism
+- science
+- oop
+---
+When I start studying computer science in the University class I truly believe that it is all I need to get started writing good programs. Algorithms > Functional programming > OOP > Databases > MVC is a step-by-step path of all people that learn programming of the web application. But...
+<!--more-->
+<br/><br/>
+Programming basics like conditions, variables, cycles and functions are mandatory for everyone just like writing and speaking for a baby.<br/>
+
+But more advanced knowledge are less useful and optional. All of these:
+<ul>
+ <li>Object hierarchy</li>
+ <li>Normalized database model</li>
+</ul>
+are turned into dust by more important
+<ul>
+ <li>Do it as fast as possible</li>
+ <li>Customer wants!</li>
+</ul>
+
+Each framework declare it's own way to organize the application Classes. If you are working on CRUD(create-read-update-delete) data application you don't need to think about object hierarchy yourself anymore. All you need to do is understand where you need place the function that handle data processing. And the principles a well declined in the framework manual.
+Normalized database is only a myth in a real world application. In 80% of cases the database design is evident to the developer. In other 20% the database couldn't be normalized at all.<br/>
+<br/>
+
+When you start learning programming try to let your knowledge be "moved to production" as fast as possible. In other words: Have a programming practice as fast as possible and you will understand what kind of programming theory you really need. Concentrate your education on all cases you met and avoid learning things that you could possible come across.
+
+
+
+
+
+
58 _posts/2009-10-27-objects-behaviour-inheritance-with-rspec.html
@@ -0,0 +1,58 @@
+---
+layout: post
+title: Objects behaviour inheritance with RSpec
+tags:
+- test
+- ruby
+- rspec
+- behaviour
+- inheritance
+---
+About half of a year ago I was writing about <a href="http://gusiev.com/2009/05/what-do-you-expect-from-interface/">object interface and Liskov Substitution Princeple</a>. In short: Any class instance that extends the base class should pass all <span style="text-decoration: line-through;">unit tests</span> behaviour tests written for base class instance. It was a surprise for me that this concept has already been implemented in RSpec.<br/><br/>
+
+<!--more-->
+My previous article was primary inspired by Java programming language and it's interface concept. Unlike Java, Ruby does not have interfaces, but behaviour inheritance is still actual for both languages. RSpec seems the first testing framework that provide the ability to validate LSP and behavior inheritance with 'it_should_behave_like'. <br/>
+With Ruby modules(mixins) feature we can build reusable code and include it in different classes<a href="http://ruby-doc.org/core/classes/Module.html">(read more)</a>. With RSpec we can bundle the tests as well.<br/>
+
+<br/>
+
+Let's review the following module that uses one of the Rails callback and adds some logging:<br/>
+<pre><code>
+module LoggedModel
+ def after_save
+ super
+ handle_logging
+ end
+end
+</code></pre>
+and the some tests group for this module:<br/>
+<pre><code>
+describe LoggableModel
+ it "should be loggable" do
+ LoggableModel.should ...
+ end
+end</code></pre>
+Now, we have a tested code that is going to be used in many cases like this:<br/>
+<pre><code>class MyModel
+ include LoggableModel
+ def after_save
+ do_some_other_thing
+ end
+end</code></pre>
+
+OK, let's see what we have: after_save in MyModel overwrites after_save in LoggableModel and breaks the logging. This is simplest example when the behavior inheritance may be broken. Rspec shared examples groups allows you to ensure that the code in LoggableModel is used correctly from any inherited class. Let's change the definithin of LoggableModel tests.<br/>
+<pre><code>
+shared_examples_for "logged model" do
+ it "should be loggable" do
+ subject.should...
+ end
+end
+</code>
+</pre>
+'Subject' is the ultimate RSpec magic that let us make a simple abstraction with the tested class and reuse these shared examples in MyModel spec:
+<pre>
+<code>describe MyModel do
+ it_should_behave_like 'loggable model'
+end</code>
+</pre>
+In this way we will rerun the LoggableModel examples for MyModel and make sure that it's behavior wasn't broken.
16 _posts/2009-12-01-vim-as-ruby-on-rails-ide-development-perfomanc.html
@@ -0,0 +1,16 @@
+---
+layout: post
+title: Vim as IDE - new development era for me
+tags:
+- vim
+- perfomance
+---
+I was using Vim to do the minor editing in config files for ages. Vim is advanced on basic navigation and editing operations. However I was always prefer IDE for programming because of it's specific to language navigation('go to definition' feature is awesome!), integrated debugger. But while gaining the experience I noticed that all advanced features began to be less important then basic ones. And you should try Vim if you feel the same.<br/>
+<!--more-->
+<hr/>
+
+The basic concept of vim is that: Vim think in the same way as you do. For example: I want to delete 'd' everything inside 'i' brackets ')' and vim understands my command: di) <br/>
+You shouldn't type a dozen of button to move cursor around and finally delete the selected fragment.
+It's hard to adapt because people are use to think in the way that there text editor do. Vim does vice versa. Some people are saying that they don't like vim because it make them think a lot. That's wrong! Vim is trying to make you free from thinking about editing and concentrate on the content.<br/>
+
+General editing in Vim considered up to every small details. Ask yourself if there is some usual task that I am doing inefficiently and search the Vim feature to optimize that in 3-5 keys. And in ninety nine percent of cases you will find it as built in vim command or a plugin.
37 _posts/2010-01-24-sql-queries-activerecord-rails-named-scopes-stack.html
@@ -0,0 +1,37 @@
+---
+layout: post
+title: Advanced SQL and named scopes stack with ActiveRecord
+tags:
+- sql
+- query
+- ruby
+- rails
+- activerecord
+- named_scope
+---
+If you ever work with rails application that is a little bit more complex then a simple CRUD you would know that some of the ActiveRecord magic doesn't work for complex SQL queries. I am primary talking about named scopes stack feature.<br/>
+<!--more-->
+<hr/>
+Let's review the following named_scope that suppose to be usable in different combinations with others:
+<pre><code>named_scope :network_of, lambda {|user|
+{
+:select =&gt; "u.*"
+:from =&gt; "users u, followings f1, followings f2",
+:conditions =&gt; "f1.follower_id = #{user.id} AND " +
+"f1.followed_id = f2.follower_id AND " +
+"f2.followed_id = u.id"
+}</code></pre>
+It suppose to returns all people that are followed by people that are followed by the given person.
+From the SQL point of view that is the simpliest and fastest way to do that with a plain SQL.
+But this solution will have some issues with Active Record named scopes stack magic.
+See that User.network_for(current_user).all(:limit =>5) will result in SQL exception primary because (:limit => 5) doesn't know about the table alias "users u".
+We can not use it in fact.<br/>
+The second problem comes to the foreground when we will try to use ActiveRecord features like
+User.network_for(current_user).all(:include => :orders). ActiveRecord handles :include in the very different ways and in some cases you will see the SQL exception here as well.<br/>
+The problem is that :include sometimes appends some joins to the query that is concatenated to the last table in the :from parameter. To solve that we should make "users" table to be the last one declared in :from parameter.
+<pre><code>:select => "users.*"
+:from => "followings f1, followings f2, users",
+:conditions => "f1.follower_id = #{user.id} AND " +
+"f1.followed_id = f2.follower_id AND " +
+"f2.followed_id = users.id"</code></pre>
+Summary I would say that using :joins instead of :from/:conditions would give more flexibility and stackability to your named scopes but sometimes :from is more clear and here you got the tip how to use it.
14 _posts/2010-03-29-quality-develop-application-improve-usability-design.html
@@ -0,0 +1,14 @@
+---
+layout: post
+title: A dream to develop application that I will use
+tags:
+- application
+- quality
+- design
+- usability
+---
+Developing sites for communities you never join, enterprise applications for company you never work in, services you never find useful... a serious problem of IT industry. All misunderstanding between customers and developers come from that reason.
+<br/><br/>
+It would be so great if we could always feel ourselves as a user of our applications and make something useful, but not spend time on improving features that won't be familiar. Being a user of the developed application makes it really possible to develop ergonomic and pretty design.
+<br/><br/>
+Unfortunately most of the companies are ignoring that simple rule and unfortunately in some cases it is hard to follow. But anyway that is the only one way to build the best product.
69 _posts/2010-04-05-ruby18-private-protected-incapsulatio.html
@@ -0,0 +1,69 @@
+---
+layout: post
+title: "Ruby1.8: 'private' doesn't give expected level of privacy"
+tags:
+- criticism
+- ruby
+- encapsulation
+- privacy
+- method
+---
+The classic OOP pattern usually called encapsulation implemented in ruby with <em>private</em> and <em>protected</em> <del>keywords</del> methods. The distinction between API and implementation works great with both. The problem is that <em>private</em> doesn't hide method for inherited classes.
+<!--more-->
+<hr/>
+See the simple example below:
+
+<pre><code>
+class A
+ private
+ def implementation
+ puts 'private A'
+ end
+end
+
+class B < A
+ def api
+ implementation
+ end
+end
+
+B.new.api
+</code></pre>
+
+And we won't get exception at the last line.<br/>
+The real difference between protected and private methods is more specific.<br/>
+At first: <em>implementation</em> method can not be called like <em>self.implementation</em> even from class A.
+<pre><code>class A
+ def api
+ self.implementation #exception here
+ end
+ private
+ def implementation
+ puts 'private A'
+ end
+end
+
+A.new.api
+</code></pre>
+Seamless pure gap. You can do such call if the method would be protected. Can't imagine the case when this limitation is useful. <br/>
+<br/>
+The second difference is a bit esoteric. Two instances of the same class can access protected methods of each other but not private methods.
+
+<pre><code>class A
+ def api(another) #suppose to receive an instance of a
+ implementation == another.implementation
+ end
+ protected
+ def implementation
+ puts 'private A'
+ end
+end
+A.new.api(A.new)
+</code></pre>
+Fine for <em>protected</em> but fail for <em>private</em>. Well, this kind of protection do not make a real because of it's rareness.
+<br/><br/>
+
+You might do any decision on the points above.<br/>
+My conclusion is to not use <em>private</em> at all, because it doesn't give the level of privacy that I expect. <em>private</em> is not suitable for such an extremely dynamic language as Ruby.
+
+
35 _posts/2010-04-20-dom-element-class-html-javascript-reference.html
@@ -0,0 +1,35 @@
+---
+layout: post
+title: DOM element class - css reference or javascript reference?
+tags:
+- javascript
+- html
+- dom
+- css
+- class
+- element
+---
+Designer have used element class attribute for CSS styling for ages. Nowadays classes are also used in javascript selectors. This overlapping cause additional problems: Changes in js may cause broken design and changes in design may cause broken js. The last one may be hard to detect especially when design and css are handled by different person.
+<!--more-->
+<hr/>
+Element class seems the best way to query the element from DOM in js code. Other variants like it's relative possition to other elements are very fragile. Let's say that we have the following DOM:
+<pre><code>&lt;a&gt; Delete&lt;/a&gt;
+&lt;a&gt; Edit&lt;/a&gt;</code></pre>
+And both links are handled with javascript. How would you separate them?
+<ul>
+ <li><strong>By order</strong>(first, second) will cause problems if designer would like to change the order.</li>
+ <li><strong>By id</strong> will fail if you would have a list of elements where each has these links</li>
+ <li><strong>By label</strong> is just a fuck up and won't work for multi language application</li>
+</ul>
+The only one variant that provide the best stability is reference <strong>By class</strong>.
+But as stated above class also serves for another purpose - styling.
+
+The thing that might help is a special prefix(for example "js") for all 'JavaScript classes'.
+Like:
+<pre><code>&lt;a class="js-new-comment big-blue-button"&gt; New Comment &lt;/a&gt;</code></pre>
+
+And the convention that classes with prefix should only be used in javascript selectors and classes without prefix in CSS.
+<br/><br/>
+Yes, sometimes it may look like:
+<pre><code>&lt;input type='button' class="js-follow-button follow-button"&gt; Follow this person &lt;/input&gt;</code></pre>
+But that makes sense to eliminate maintenance problem described above.
147 _posts/2010-06-08-nesting-namespace-route-non-flat-controllers-hierarchy-rails.html
@@ -0,0 +1,147 @@
+---
+layout: post
+title: Advanced non-flat controllers hierarchy with rails
+tags:
+- ruby
+- rails
+- controller
+- route
+- architecture
+---
+REST became the best practice for organizing CRUD server side interface.
+But what to do when we have something more than hello-world application that
+goes forward from data CRUD and provides many presentations
+of the same data with different filters and different layouts?
+<!--more-->
+<br/>
+
+<h3>How the flat controller architecture goes to hell</h3>
+
+Starting from REST-full controller people use to stick to them and add more and more actions to the same class. And that is how the controller code goes to hell:
+
+<pre><code>class UsersController &lt; ApplicationController
+#
+# Filters
+#
+skip_before_filter :check_user_is_valid, :only =&gt; [:edit, :update]
+before_filter :require_user, :only =&gt; [
+:update, :edit, :settings, :disconnect_twitter, :connect_facebook_account, :google_contacts
+]
+
+before_filter :load_user, :except =&gt; [
+:index, :new, :create, :remote_validate_email, :autocomplete_for_user_full_name,
+:remote_validate_facebook_uid, :google_contacts
+]
+
+before_filter :check_permissions, :only =&gt; [ :edit, :update, :settings, :update_photo, :connect_facebook_account ]
+
+before_filter :load_invitation, :only =&gt; [:new, :create]
+before_filter :ensure_authenticated_to_facebook, :only =&gt; :connect_facebook_account
+before_filter :initialize_form, :only =&gt; [:edit]
+
+#
+# And 20 almost independent actions goes here
+# And the twice longer tests file for this controller
+#
+
+end
+</code></pre>
+
+<h3> Namespaces and nesting </h3>
+The root of the problem is in ignoring the following simple rule:
+<strong>The default choice for implementing new feature is do it in other controller</strong>
+It's always better to have 20 controllers with one action then one controller with 20 actions.
+Usually there is no compromise variant. And 20 controllers with one action ain't as bad as you imagine.<br/>
+<br/>
+
+In order to handle the large number of controller we are actively using the namespaces and nested resources features. Let me give an example: User has many projects, Project belongs to category. We need to list projects per user and per category. In the flat hierarchy you would be confused but namespaces and nesting solves the problem.<br/>
+
+<pre><code>map.resources :categories do |c|
+ c.namespace :categories do |categories|
+ categories.resouces :projects
+ end
+end
+map.resources :users do |u|
+ c.namespace :users do |users|
+ users.resouces :projects
+ end
+end
+
+class Categories::ProjectsController
+
+ def index
+ @projects = ....
+ end
+end
+
+class Users::ProjectsController
+
+ def index
+ @projects = ....
+ end
+end</code></pre>
+
+
+Everyone heard about restful authentication but not so many people applied this idea to other not so restful from the first sight things. Like TwitterConnectionController:
+
+<pre><code>class Users::TwitterConnectionController < ApplicationController
+
+ def create
+ end
+
+ def destroy
+ end
+end</code></pre>
+
+Many people will be pushing all such staff to UsersController until their editors would run out of memory.
+
+<h3>Out of scope</h3>
+
+State control actions are not in REST but should be one day. Placing them in the same controller with CRUD is generally a good idea:
+
+<pre><code>class ArticlesController
+
+ def {new, create, update, edit, destroy}
+ end
+
+ def publish
+ @article.publish!
+ redirect_to articles_path
+ end
+
+end</code></pre>
+
+<h3>Some sugar from generators</h3>
+
+Rails <em>generate</em> script supports namespaces very well:
+<pre><code>$ ./script/generate <del>rspec_</del>controller users/categories
+ create app/controllers/users
+ create app/helpers/users
+ create app/views/users/categories
+ create spec/controllers/users
+ create spec/helpers/users
+ create spec/views/users/categories
+ create spec/controllers/users/categories_controller_spec.rb
+ create spec/helpers/users/categories_helper_spec.rb
+ create app/controllers/users/categories_controller.rb
+ create app/helpers/users/categories_helper.rb</code></pre>
+
+And classes created in appropriate namespace and folder as well as specs for them.
+The only one thing you should do manually is add routes.
+
+<h3>Drawbacks</h3>
+
+Every engeneering solution has it's drawbacks. While you have different controllers that operates on the same classes you might need to reuse functionality among them.
+I preffer to solve it by mixing in a module:
+<pre><code>class Users::ProjectController
+
+ include UserNestedResource
+
+end</code></pre>
+
+Some people use inheritance instead. Both ways are almost the same. Nothing hard here as well.
+
+<h3>Summary</h3>
+
+At the end I 'll just repeat it again:<br/>
+Default policy for placing two actions that has some kind of connection is <strong>SPLIT</strong>.
41 _posts/2010-06-30-ultimate-rspec-matcher-to-test-validation.html
@@ -0,0 +1,41 @@
+---
+layout: post
+title: Ultimate rspec matcher to test validation
+tags:
+- rspec
+- rails
+- activerecord
+- validation
+- pattern
+---
+After a first thousand of tests using Rspec I fount it very annoying to repeat my self testing the standard code as spec code is usually twice longer than code it test. I've started to look for a way to simplify the patterns and make it reusable. Among other nice rspec tricks there is possibility to write custom Rspec matchers. Spec the validation is just two lines of code for each attribute now.
+<!--more-->
+
+
+<h3> Existing solutions </h3>
+After doing some search around I found Shoulda and remarkable gems that provide a way of doing this. Here is one of remarkable variant (others are just ugly):
+<pre><code>it { should validate_numericality_of(:age, :greater_than => 18, :only_integer => true) }</code></pre>
+But that is huge contradiction with BDD methodology because it doesn't make you think about behavior. People use to copy-paste code from model to spec and all possible bugs within. As the result <strong>nothing is tested</strong>... I don't even say about "test first".
+
+<h3> Easy DSL and Implementation </h3>
+When I implement validation everything I care about is: what values should be accepted and what values should not. An easy DSL that realize this pattern would be:
+<pre><code>describe User do
+ it { should accept_values_for(:email, "john@example.com", "lambda@gusiev.com") }
+ it { should_not accept_values_for(:email, "invalid", nil, "a@b", "john@.com") }
+end</code></pre>
+That's it! Two lines of code per attribute. And that is perfectly fine for "test first" principle.<br/>
+Rspec authors take care about custom Rspec matcher. So the implementation is very easy.
+Fork me on github: <a href="http://github.com/bogdan/accept_values_for">accept_values_for rpec matcher</a>. The <strong>accept_values_for</strong> pattern is a true BDD way and unlike Remarkable it really do testing.
+
+<h3> validates_uniqueness_of </h3>
+This is very special validation because you always need more then one record to test it. So, the pattern for uniqueness validation is:
+<pre><code>describe User do
+ context "if user with email 'aa@bb.com' exists" do
+ before do
+ User.create!(@valid_attributes.merge(:email =&gt; 'aa@bb.com')
+ end
+ it { should_not accept_values_for(:email, "aa@bb.com") }
+ end
+end</code></pre>
+<h3> Summary </h3>
+Custom matcher is just 50 lines of code that make your life much easier. Do not scare to write your own. Custom matcher to test ActiveRecord#named_scope coming soon.
80 _posts/2010-07-11-bdd-rspec-matcher-to-test-named_scope-scoped-rails-3.html
@@ -0,0 +1,80 @@
+---
+layout: post
+title: Ultimate rspec matcher to test named_scope or scoped
+tags:
+- bdd
+- rspec
+- activerecord
+- named_scope
+- matcher
+---
+After having a good practice on using <a href="http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/">Ultimate rspec matcher to test validation</a> I think it's time to implement one for testing named scopes - custom finders. Testing these finders is daily task. Here is how it can be done with minimum amount of code and maximum readability.
+<!--more-->
+<h3>Discovery <del>(Animal Planet)</del></h3>
+
+What do we expect from the custom finder?
+We expect that it should find assets A, B, C and should not find assets D, E, F.
+And sometimes the order is important: it should find A, B C with exact order.
+
+With respect to <em>let</em> rspec feature let's take an example: Product has and belongs to many categories. We need to have a scope to filter products within the specified category:
+
+<pre><code>describe "#by_category_id" do
+ let(:given_category) do
+ Factory.create(:given_category)
+ end
+
+
+ let(:product_in_given_category) do
+ Factory.create(
+ :product,
+ :categories => [category]
+ )
+ end
+
+ let(:product_not_in_given_category) do
+ Factory.create(
+ :product,
+ :categories => [Factory.create(:category)]
+ )
+ end
+
+ # This might be tricky to redefine subject as the finder result
+ # but in this way we can delegate the matcher to subject and
+ # avoid writing test descriptions.
+ subject { Product.by_category_id(given_category.id) }
+
+ it { should discover(product_in_given_category) }
+ it { should_not discover(product_not_in_given_category) }
+
+ end
+</code></pre>
+
+Factory girl was used in this example because factories kickass when we test finders. As you can see the example has a perfect readability with no one line of plain English text. I didn't include the description in my examples but you can easily make them if they make sense for you.<br/>
+Note: Be aware of the lazy loading of your finder. <em>let</em> is initialized lazy too. You should make sure it is called before the actual query to the database.
+If you don't want to care about lazy loading their is <em>let!</em> method that could be easily copy-pasted from Rspec 2.0. Unlike <em>let</em> it doesn't have lazy initialization:
+<pre><code>def let!(name, &block)
+ let(name, &block)
+ before { __send__(name) }
+end
+</code></pre>
+
+<h3>Testing sort order</h3>
+
+If the ordering is done in non-trivial way let's <em>discover.with_exact_order</em>.
+<pre><code>describe "#most_commented named scope" do
+ let(:uncommented_post) { Factory.create(:post)}
+ let!(:less_commented_post) { Factory.create(:post, :comments => [Factory.build(:comment)])}
+ let!(:more_commented_post) {
+ Factory.create(:post, :comments => [Factory.build(:comment), Factory.build(:comment)])}
+ }
+
+ subject { described_class.most_commented }
+ it {should discover(more_commented_post, less_commented_post).with_exact_order }
+ it {should_not discover(uncommented_post) }
+end</code></pre>
+
+Be careful with default order. MySQL and Postgres sort objects as they were created by default.
+That is why generate objects in reverse order e.g. <em>less_commented_post</em> before <em>more_commented_post</em> is important to make sure that ordering is your code behavior rather than default db behavior.
+
+<h3> Summary </h3>
+I 've add this matcher to the <a href="http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/">previous one</a>. Both matchers are available here <a href="http://github.com/bogdan/accept_values_for">accept_values_for</a>. Let's start thinking of what else we can do.
45 _posts/2010-08-26-populate-db-pattern-fake-data.html
@@ -0,0 +1,45 @@
+---
+layout: post
+title: Populate database pattern - why is it so cool?
+tags:
+- database
+- ruby
+- pattern
+- populate
+- fake
+- data
+---
+Once my co-worker propose an idea to fill database with some fake data because we didn't have a gui forms yet and we have to show something that works to customer. That was a start for great pattern - <strong>populator</strong>.
+<!--more-->
+
+<h3>Advantages</h3>
+Later we didn't drop that functionality because it was helpful for everyone to always see what's new appear in application. And we find more and more useful aspects of having populator. It was so easy to attach new people to project because we deliver a short set of data within a source code that demonstrates everything we have in our app. Now whole team has a full data set and see if any page doesn't work because of a side effect. Frontend people feel more comfortable with populator because they don't care of how to create many assets in order to see pagination and things like that . Also UI issues became easier to detect because every element present on a screen for every person letting him detect browser specific bugs.
+
+<h3> Implementation</h3>
+
+I won't recommend any specific library to populate the db except the one to generate fake(Lorem ipsum) content. We prefer <a href="http://github.com/stympy/faker">Faker</a> but that is up to personal choice.
+Important note is that inserting data directly into db is bad idea because all application logic is ignored in this case: validation will be ignored and counters cache might be broken. That is why Populate gem is not recommended.<br/><br/>
+One nice improvement we made is pass _SCALE_ parameter to populator in order to control how many objects should be generated. Use minimal amount if you need to test that populator works and regular amount to get working system.<br/>
+Another good idea is soft save(ignore if not valid) and output the number of created objects after at the end. This letting you if something went wrong during populate process.<br/>
+<br/>
+Here is an example of how it may look like:
+<pre><code>User.transaction do
+ # apply the SCALE parameter to the argument.
+ # Default SCALE is 10 so 10 * 1 = 10.
+ # Generate 10 users by default
+ scale(1).times do
+ user = User.new
+ user.email = Faker::Internet.email
+ user.first_name = Faker::Name.first_name
+ user.last_name = Faker::Name.last_name
+ user.password = user.password_confirmation = 'monkey'
+ user.save # this may be false in case of uniqueness restriction or other problems
+ end
+end
+
+
+users = User.all
+puts "Users: #{users.count}" # make sure we actually made some users </code></pre>
+
+<h3>At the end</h3>
+I beleive that Populator should be a part of the build of every project. Yes, it needs some support but in fact it saves lots and lots of time.
26 _posts/2010-09-30-good-passwords-theory.html
@@ -0,0 +1,26 @@
+---
+layout: post
+title: Good passwords theory
+tags:
+- usability
+- password
+- security
+- random
+---
+All of us are using passwords and most of us are typing them several times a day. And everyone knows the criteria to generate a good password. Random passwords are very strong from protection point of view but not from usability point of view.
+No body think about password unforgettable-ness and less-painful-to-type-ness. I saw many passwords that are very painful because they are just random.
+
+And I think it's nice to lose some randomness and make it easier to type and remember.
+There is still a lot of enough strong passwords that match this criteria as well.
+<!--more-->
+<br/>
+Try to type and remember something like:
+<pre><code>sudosuamigo1;
+s3host-large
+you&me2gether</code></pre>
+Instead of:
+<pre><code>1aWhuyZ
+!nzu?Us0
+n]1m!uaA</code></pre>
+
+And you feel much better.
62 _posts/2010-11-03-dynamic-context-in-rspec-dont-repeat-yourself.html
@@ -0,0 +1,62 @@
+---
+layout: post
+title: Dynamic context in Rspec - don't repeat yourself
+tags:
+- behavior
+- rspec
+- context
+- testing
+---
+Advanced rspec features allow to use very effective technique to organize tests. You are able to construct and define context in more flexible way than before.
+We use to have less problems with subject and behavior. And <strong>context</strong> is what testing is all about. Just because web apps manage data, behavior seriously depends on current state of the database.
+<!--more-->
+<br/><br/>
+
+Well organized contexts makes a real problem of testing. Unlike TestUnit, Rspec examples may have nested contexts and even dynamic contexts with the <em>let</em> feature. <br/>
+In spite of lazy initialization let blocks they are defined before <em>before each</em> hook. Understand by example. <br/> <br/>
+In this example orders should be delivered to confirmed customer account just after creation and should not be delivered if the account is not confirmed yet.
+<pre><code>describe Order do
+ context "after create" do #defining a partial context
+ before(:each) do
+ subject.customer.confirmed = confirmed
+ subject.save!
+ end
+
+ context "when customer is confirmed" do
+ let(:confirmed) { true }
+ it { should be_delivered }
+ end
+
+ context "when customer is not confirmed" do
+ let(:confirmed) { false }
+ it { should_not be_delivered }
+ end
+ end
+end</code></pre>
+
+Here you can see the partial context definition and custom behavior in two nested context.
+We can call not yet declared function and define it later and differently in different contexts.<br/> <br/>
+
+Another example that is kind of pattern matching(erlang term), designed to test utility functions.<br/>
+Suppose we have a boolean expression evaluation function:
+<pre><code>describe Expression
+ describe ".run" do
+
+ subject { Expression.run(arg) }
+
+ context "with '&' where both true" do
+ let(:arg) { "true & true" }
+ it {should be_true}
+ end
+
+ context "with '&' where one false" do
+ let(:arg) { "false & true" }
+ it {should be_false}
+ end
+ ........
+ end
+end</code></pre>
+
+Very good strategy to run same function with different arguments.
+<br/> <br/>
+Rspec is far ahead of all unit testing frameworks. Unlike most of Rspec clones (e.g. for other programming languages), Rspec authors got in deep to the testing problems and invent flexible and elegant syntax.
31 _posts/2011-03-18-ajax-jquery-debug-javascript.html
@@ -0,0 +1,31 @@
+---
+layout: post
+title: Debug ajax requests in more easy way
+tags:
+- javascript
+- jquery
+- debug
+- ajax
+---
+When I have to debug ajax requests, I always feel pain in the ass accessing the exception message and backtrace. It require at least 3 clicks to get them and only in the plain html format, that web framework use to generate. Is it better to see it at once in the browser popup?
+<!--more-->
+<br/><br/>
+This can be done with Ajax callbacks offered by javascript framework(if yours doesn't - get rid of it). We can catch errors there and display popup. JQuery example with #ajaxError callback that fires on every unsuccessful ajax call:
+<pre><code>(function() {
+ var popup = null;
+ $(document).ajaxError(function(event, xhr, settings, exception) {
+ if (popup) {
+ popup.close();
+ popup = null;
+ }
+ popup = window.open(null, "error", "width=800,height=600");
+ $(popup.document.documentElement).html(xhr.responseText);
+ return true;
+ });
+ }());</code></pre>
+
+Checked in FF and Chrome(IE is not a browser).
+<a href="http://img6.imagebanana.com/img/drl8wpd9/screenshot_014.png">Screenshot</a> with the result. Be aware of browser popup blocker. <br/>
+You always have a control when popup the error. I like it to be "in any case". But You can customize it with <em>xhr.status</em> and <em>if</em> statement on the server side.
+<br/><br/>
+In some cases it might be useful not only in the development but in production as well. But it should be an iframe inside of pretty html layout, so that designers won't blame programmers too much.
58 _posts/2011-03-28-do-git-commits-associated-to-hoptoad-errors.html
@@ -0,0 +1,58 @@
+---
+layout: post
+title: Do git commits associated to hoptoad errors
+tags:
+- ruby
+- git
+- hoptoad
+
+- commit
+---
+We are trying to build a better development workflow by connecting all our tools together.
+So, this time we tried to connect HopToad Application with git commits because sometimes it's better to just paste the link to hoptoad error rather than describe all steps to reproduce. This idea was resulted in the command line interface for hoptoad api with a little git integration - <a target="_blank" href="http://github.com/railsware/shelltoad">Shelltoad</a>.
+<!--more-->
+<br/><br/>
+Currently, in order to resolve hoptoad error we do the following.<br/>
+Check the list of errors:
+<pre><code>$ shelltoad
+[#3374331] production ActionController::MethodNotAllowed: Only put requests are allowed
+[#4023713] production ActiveRecord::StatementInvalid: PGError: ERROR:
+ duplicate key value violates unique constraint "index_companies_on_slug" :
+ INSERT INTO "companies" .....
+</code></pre>
+View the information on the required error.
+ '713' is automatically guess for 4023713
+<pre><code>
+$ shelltoad 713
+ActiveRecord::StatementInvalid: PGError: ERROR: duplicate key value violates unique constraint
+ "index_companies_on_slug" : INSERT INTO "companies"
+("slug", "created_at", "title", "updated_at", "external_url", "logo_id", "custom") VALUES('abbott-associates
+/var/data/www/apps/startwire/shared/bundle/ruby/1.8/gems/activerecord-
+2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:221
+/var/data/www/apps/startwire/releases/20110218113457/app/models/company.rb:50
+/var/data/www/apps/startwire/releases/20110218113457/app/utils/network_map/populate.rb:9
+/var/data/www/apps/startwire/releases/20110218113457/app/utils/network_map/populate.rb:74
+/var/data/www/apps/startwire/releases/20110218113457/app/utils/network_map/populate.rb:70
+....
+</code></pre>
+Fix the error in the code ...
+Prepare git commit:
+<pre><code>
+$ git add .
+</code></pre>
+Commit the fix to git with connection to hoptoad issue id
+<pre><code>
+$ shelltoad commit 713
+[dev 47f09ec] http://xxx.hoptoadapp.com//errors/4023713
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+</code></pre>
+
+Commit message will look like this:
+<code><pre>http://startdatelabs.hoptoadapp.com//errors/4023713
+
+ActiveRecord::StatementInvalid: PGError: ERROR: duplicate key value violates unique constraint
+ "index_companies_on_slug" : INSERT INTO "companies"
+("slug", "created_at", "title", "updated_at", "external_url", "logo_id", "custom") VALUES('abbott-associates</pre></code>
+
+
+This help us maintain the links between git and hoptoad automatically.
42 _posts/2011-04-06-javascript-injection-in-json-inserted-directly-into-script-tag.html
@@ -0,0 +1,42 @@
+---
+layout: post
+title: JavaScript injection in JSON inserted directly into script tag
+tags:
+- javascript
+- html
+- xss
+- escape
+- json
+---
+Pass data from backend to javascript is done in many different ways. One of the most simple is to inject(&lt;%= %&gt;) value as function argument inside of script tag. Unfortunately this pattern has well known XSS vulnerability but in a little different form than same injection in html template.
+<!--more-->
+<pre><code>&lt;script type="text/javascript"&gt;
+ App.initizalizeSomething(<%= data.to_json %>)
+&lt;/script&gt;</code></pre>
+
+The reason is that browser treat <strong>&lt;/script&gt;</strong> as close script tag no matter where is it inserted into script. So, the script tag can be closed unexpectedly and opened again with any code if the <em>data</em> argument will contain correctly formed sequence, like:
+<pre><code>&lt;/script&gt;&lt;script&gt;alert('hello')&lt;/script&gt;</code></pre>
+
+Use <em>#html_escape</em> helper is wrong here because it has different type of escaping.
+For example you don't need to escape double quote in this case.
+
+Rails core team is aware of that problem and implemented special helper:
+<pre><code># A utility method for escaping HTML entities in JSON strings
+# using \uXXXX JavaScript escape sequences for string literals:
+#
+# json_escape('is a &gt; 0 &amp; a < 10?')
+# # => is a \u003E 0 \u0026 a \u003C 10?
+#
+# Note that after this operation is performed the output is not
+# valid JSON. In particular double quotes are removed:
+#
+# json_escape('{&quot;name&quot;:&quot;john&quot;,&quot;created_at&quot;:&quot;2010-04-28T01:39:31Z&quot;,&quot;id&quot;:1}')
+# # => {name:john,created_at:2010-04-28T01:39:31Z,id:1}
+#
+# This method is also aliased as +j+, and available as a helper
+# in Rails templates:
+#
+# <%=j @person.to_json %>
+#
+def json_escape(s)</code></pre>
+Implementation can be found in <a href="https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/output_safety.rb#L53" target="_blank">Rails source code</a>.
44 _posts/2011-05-20-migrate-wordpress-jekyll-post-preview.md
@@ -0,0 +1,44 @@
+---
+layout: post
+title: "Finally get rid of WordPress and PHP"
+#published: false
+tags:
+- jekyll
+- wordpress
+- php
+- migration
+- liquid
+- criticism
+---
+
+After a few tries migrate to blog engine with programming language I know well, I finally found
+[jekyll](http://github.com/mojombo/jekyll) - lightweight static site generator. My main concerns in this choice was:
+
+* Edit posts in my favorite text editor with favorite markup
+* NO PHP
+* Syntax highlight out of the box
+
+<!--more-->
+
+### Migration from WordPress
+
+Three main migration points was:
+
+* Posts that was migrated with [several lines of ruby code](http://google.com/search?q=wordpress%20jekyll%20migrate)
+* Comments that imported to [disqus](http://wordpress.org/extend/plugins/disqus-comment-system/) as jekyll is static site engine so the comments should be hosted somewhere else
+* Generate [tag cloud and posts by tag pages](http://www.google.com.ua/search?sourceid=chrome&client=ubuntu&channel=cs&ie=UTF-8&q=jekyll+tag+cloud) that also have a lot of workarounds in the web
+
+One problem I am currently have is "post preview" feature that is currently unsupported in jekyll.
+My current approach for this looks like this:
+
+ post.content | replace_first:'<!--more-->','<!--' | append:'-->'
+
+### Problems
+
+Jekyll looks not very extensible. Some methods are not available in the API. Example: integrate SASS require more pain the ass than it should be. I am planning to fix that in a few days. Another problem I ran into is that github native support don't allow you any extension. My suggestion is to generate static content locally with your own code on top of jekyll and upload static content to git repository.
+
+
+### Result
+
+About 12 hours of work to transfer 30 posts and their comments.
+Reworked site design to be more clean.
27 atom.xml
@@ -0,0 +1,27 @@
+---
+layout: nil
+---
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+ <title>Bogdan Gusiev's blog</title>
+ <link href="{{ site.url }}atom.xml" rel="self"/>
+ <link href="{{ site.url }}"/>
+ <updated>{{ site.time | date_to_xmlschema }}</updated>
+ <id>{{ site.url }}</id>
+ <author>
+ <name>GitHub</name>
+ <email>support@github.com</email>
+ </author>
+
+ {% for post in site.posts %}
+ <entry>
+ <title>{{ post.title }}</title>
+ <link href="{{ site.url }}{{ post.url }}"/>
+ <updated>{{ post.date | date_to_xmlschema }}</updated>
+ <id>{{ site.url }}{{ post.id }}</id>
+ <content type="html">{{ post.content | xml_escape }}</content>
+ </entry>
+ {% endfor %}
+
+</feed>
1  build
@@ -0,0 +1 @@
+Subproject commit 7b167928e15f47131ab5d32ea8a05f9e8a0e2caf
178 css/default.css
@@ -0,0 +1,178 @@
+/* line 6, css/default.sass */
+body {
+ width: 100%;
+ font-family: "Times New Roman";
+ font-size: 16px;
+}
+
+/* line 10, css/default.sass */
+.clear {
+ clear: both;
+}
+
+/* line 13, css/default.sass */
+h1, h4, p, ul, ol, h5, pre, code {
+ margin: 10px 0px;
+}
+
+/* line 16, css/default.sass */
+pre, code {
+ white-space: pre-wrap;
+ display: block;
+ font-family: monospace;
+ margin-left: 20px;
+}
+/* line 21, css/default.sass */
+pre code, code code {
+ margin: 0;
+}
+
+/* line 24, css/default.sass */
+h2 a {
+ font-size: 26px;
+}
+
+/* line 27, css/default.sass */
+h5 {
+ font-size: 18px;
+ margin-top: 15px;
+}
+
+/* line 31, css/default.sass */
+hr {
+ border-style: inset;
+ border-width: 1px;
+ border-color: #dddddd;
+}
+
+/* line 35, css/default.sass */
+h1 a, h2 a, h3 a, h4 a, h5 a {
+ text-decoration: none;
+}
+
+/* line 38, css/default.sass */
+.date {
+ font-size: 16px;
+}
+
+/* line 42, css/default.sass */
+#wrapper {
+ width: 920px;
+ margin: 0 auto;
+}
+/* line 46, css/default.sass */
+#wrapper #content {
+ width: 600px;
+ float: left;
+}
+/* line 50, css/default.sass */
+#wrapper #sidebar {
+ width: 280px;
+ float: right;
+}
+/* line 54, css/default.sass */
+#wrapper .vsplit {
+ float: left;
+ height: 800px;
+ margin: 0 15px;
+ border-style: inset;
+ border-width: 1px;
+ border-color: #dddddd;
+}
+
+/* line 64, css/default.sass */
+ul li {
+ list-style: disc;
+}
+/* line 66, css/default.sass */
+ul li ul li {
+ list-style: circle;
+}
+
+/* line 70, css/default.sass */
+.recent-posts {
+ width: 100%;
+}
+/* line 72, css/default.sass */
+.recent-posts ul {
+ padding-left: 25px;
+}
+/* line 74, css/default.sass */
+.recent-posts ul li {
+ margin-left: 0px;
+}
+/* line 76, css/default.sass */
+.recent-posts h2 {
+ display: inline-block;
+ float: left;
+}
+/* line 79, css/default.sass */
+.recent-posts .rss {
+ margin-top: 10px;
+ display: inline-block;
+ float: right;
+}
+
+/* line 87, css/default.sass */
+.tags {
+ margin: 10px 0;
+ float: right;
+}
+/* line 90, css/default.sass */
+.tags a {
+ margin: 0 10px;
+}
+
+/* line 94, css/default.sass */
+.header .title {
+ float: left;
+}
+/* line 96, css/default.sass */
+.header .pages {
+ margin: 35px 0 35px 120px;
+ float: left;
+}
+/* line 99, css/default.sass */
+.header .pages a {
+ padding: 0 20px;
+}
+/* line 101, css/default.sass */
+.header .avatar {
+ margin-top: 15px;
+ float: right;
+}
+/* line 102, css/default.sass */
+.header .avatar img {
+ width: 64px;
+ height: 64px;
+}
+/* line 107, css/default.sass */
+.header hr {
+ margin: 5px 0 10px 0;
+}
+
+/* line 112, css/default.sass */
+.tag-cloud a {
+ margin: 0 2px;
+}
+
+/* line 115, css/default.sass */
+.footer {
+ padding: 10px 0;
+ margin: 0 auto;
+ width: 100%;
+}
+
+/* line 121, css/default.sass */
+.post hr {
+ margin: 15px 0 25px 0;
+}
+
+/* line 125, css/default.sass */
+.paginator .next {
+ float: right;
+}
+/* line 127, css/default.sass */
+.paginator .prev {
+ float: left;
+}
129 css/default.sass
@@ -0,0 +1,129 @@
+=borderer
+ border-style: inset
+ border-width: 1px
+ border-color: #DDD
+
+body
+ width: 100%
+ font-family: 'Times New Roman'
+ font-size: 16px
+.clear
+ clear: both
+
+h1, h4, p, ul, ol, h5, pre, code
+ margin: 10px 0px
+
+pre, code
+ white-space: pre-wrap
+ display: block
+ font-family: monospace
+ margin-left: 20px
+ code
+ margin: 0
+
+h2 a
+ font-size: 26px
+
+h5
+ font-size: 18px
+ margin-top: 15px
+