<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-360329120074358364</id><updated>2012-01-21T14:57:28.508+02:00</updated><category term='contest'/><category term='Shoes'/><category term='solution'/><category term='gdm'/><category term='wifi'/><category term='Javascript'/><category term='C'/><category term='jenkins'/><category term='Rails'/><category term='AJAX'/><category term='why?'/><category term='MsSql'/><category term='Eee'/><category term='Windows'/><category term='conference'/><category term='algorithm'/><category term='game'/><category term='Java'/><category term='blog'/><category term='book'/><category term='Lisp'/><category term='IDE'/><category term='Mercurial'/><category term='Google'/><category term='Moles'/><category term='MongoDB'/><category term='C++'/><category term='C#'/><category term='regex'/><category term='Code Jam'/><category term='audio'/><category term='gem'/><category term='AI'/><category term='Ruby'/><category term='Linq'/><category term='course'/><category term='wav'/><category term='makefile'/><category term='MySql'/><category term='Fourier'/><category term='Ubuntu'/><category term='fun'/><category term='geekout'/><category term='myself'/><category term='PostgreSql'/><category term='Silverlight'/><category term='Excel'/><category term='Fibonacci'/><title type='text'>Minimal</title><subtitle type='html'>Less is more</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>68</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6772249890172634092</id><published>2011-12-22T12:57:00.001+02:00</published><updated>2011-12-22T12:57:42.871+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AI'/><category scheme='http://www.blogger.com/atom/ns#' term='course'/><title type='text'>Stanford AI Class Finished</title><content type='html'>&lt;p&gt;Stanford AI class is over. I was very interesting and I learned a lot new things. Unfortunately I sucked at the first 2 questions of final exam and my score is not so high as I would like it to be. But there will be new interesting courses in spring - I will take my "revenge" there. So far I have signed up to Machine Learning, Game Theory and Design and Analysis of Algorithms courses and I hope I will have enough time for that. :)&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-g5duzA-oq0c/TvMMbvXLRRI/AAAAAAAADLs/LVDJCT0Pqpw/s1600/AI-Score.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-g5duzA-oq0c/TvMMbvXLRRI/AAAAAAAADLs/LVDJCT0Pqpw/s320/AI-Score.png" width="247" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6772249890172634092?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6772249890172634092/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/12/stanford-ai-class-finished.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6772249890172634092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6772249890172634092'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/12/stanford-ai-class-finished.html' title='Stanford AI Class Finished'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-g5duzA-oq0c/TvMMbvXLRRI/AAAAAAAADLs/LVDJCT0Pqpw/s72-c/AI-Score.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8217883902575003198</id><published>2011-11-14T12:15:00.001+02:00</published><updated>2011-11-14T12:44:25.701+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Java: Save InputStream Into File</title><content type='html'>Imagine we need to save an InputStream into file. That can happen when requesting some url, or when just copying the file from one place to another on hard disk. There are a lot of answers provided by google on request &lt;i&gt;java save inputstream to file&lt;/i&gt;. I have  checked the first result page and everywhere almost 1 and the same solution is provided, which includes the following loop:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code class="java"&gt;int read = 0;
byte[] bytes = new byte[1024];
 
while ((read = inputStream.read(bytes)) != -1) {
 out.write(bytes, 0, read);
}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Seriously, guys, don't you think there is something wrong here? Even in C++ people do not copy streams by operating bytes anymore! There should be a lot better way :) (I am not considering now usage of any additional libraries that require some additional jar files).&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code class="java"&gt;import sun.misc.IOUtils;

new FileOutputStream("tmp.txt").write(IOUtils.readFully(inputStream, -1, false));&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8217883902575003198?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8217883902575003198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/11/java-save-inputstream-into-file.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8217883902575003198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8217883902575003198'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/11/java-save-inputstream-into-file.html' title='Java: Save InputStream Into File'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4001091266288678934</id><published>2011-08-24T13:03:00.000+03:00</published><updated>2011-08-24T13:04:42.920+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jenkins'/><title type='text'>Top 10 Jenkins Must-Have Plugins</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;We at ZeroTurnaround have been using Jenkins for a long time already, and at last decided to create a &lt;a class="external" href="http://www.zeroturnaround.com/blog/top-10-jenkins-featuresplugins/"&gt;small review of plugins and features&lt;/a&gt; we use.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4001091266288678934?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4001091266288678934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/08/top-10-jenkins-must-have-plugins.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4001091266288678934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4001091266288678934'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/08/top-10-jenkins-must-have-plugins.html' title='Top 10 Jenkins Must-Have Plugins'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6047181679978846735</id><published>2011-06-10T22:02:00.002+03:00</published><updated>2011-06-29T17:32:51.281+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><title type='text'>Ruby Pack/Unpack</title><content type='html'>&lt;p&gt;Having a party in ZeroTurnaround new office in Tartu. There is a mat on the floor near the entrance door that says:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;01010111011001010110110001100011011011110110110101100101&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using ruby, we can quickly figure out, what that actually means:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;["01010111011001010110110001100011011011110110110101100101"].pack('B*') #==&gt; Welcome&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a class="external" href="http://www.codeweblog.com/ruby-string-pack-unpack-detailed-usage/"&gt;Ruby string pack unpack detailed usage.&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6047181679978846735?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6047181679978846735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/06/ruby-packunpack.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6047181679978846735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6047181679978846735'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/06/ruby-packunpack.html' title='Ruby Pack/Unpack'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3510414207362609089</id><published>2011-06-09T23:01:00.005+03:00</published><updated>2011-06-13T17:36:44.019+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conference'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='geekout'/><title type='text'>GeekOut: The First Java Conference In Estonia</title><content type='html'>&lt;p&gt;Today I have attended the first Java conference in Estonia: &lt;a class="external" href="http://geekout.ee/"&gt;GeekOut&lt;/a&gt;. That is also my first conference  at all, as I have never participated earlier in such an event. Nipping on ahead I could say, that the activity was a success. It was good organized, informative, interesting, with great food and beer (although I do not drink alcohol :) ).&lt;/p&gt;
&lt;p&gt;The day started with small introduction from &lt;a class="external" href="http://www.ekabanov.net/"&gt;Jevgeni Kabanov&lt;/a&gt;, the founder and CTO of &lt;a class="external"  href="http://www.zeroturnaround.com/"&gt;ZeroTurnaround&lt;/a&gt;, the organizers of the GeekOut. After that the main part began.&lt;/p&gt;
&lt;p&gt;The first talk was about Java 7 by &lt;a class="external" href="http://martijnverburg.blogspot.com/"&gt;Martijn Verburg&lt;/a&gt;. It was about the new features that are coming in JDK 7. &lt;a class="external" href="http://openjdk.java.net/projects/coin/"&gt;Project Coin&lt;/a&gt; announced: 
&lt;ul&gt;&lt;li&gt;&lt;a class="external" href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000001.html"&gt;Strings in switch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="external" href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000011.html"&gt;Automatic Resource Management&lt;/a&gt; (such as c# &lt;code&gt;using&lt;/code&gt; construction)&lt;/li&gt;
&lt;li&gt;Numeric literals with underscores. (Like in ruby: 3_456_789)&lt;/li&gt;
&lt;li&gt;&lt;a class="external" href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000009.html"&gt;Improved Type Inference for Generic Instance Creation&lt;/a&gt;&lt;br/&gt;We can skip generics on the right side: &lt;pre&gt;&lt;code&gt;Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; anagrams = new HashMap&amp;lt;&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;New file handling mechanism, which "is finally done right, I hope" (M.V.)&lt;/li&gt; 
&lt;li&gt;Nonblocking I/O for sockets and files, new Files and Paths classes that provide some util functions to work with filelike objects, that are quicker than in JDK 6, multicatch and some others...&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Next speech was about "Riding the data tsunami and coming out on top" by &lt;a class="external" href="http://www.codespot.net/blog/"&gt;Alex Snaps&lt;/a&gt;. He introduced &lt;a class="external" href="http://www.terracotta.org/company/?src=/products"&gt;Terracotta&lt;/a&gt; - an open source solution for application scalability, availability and performance.&lt;/p&gt;
&lt;p&gt;After a coffee break &lt;a class="external" href="http://www.jole.fi/"&gt;Joonas Lehtinen&lt;/a&gt; told us about &lt;a class="external" href="http://vaadin.com/home"&gt;Vaadin}&amp;gt;&lt;/a&gt; - the web framework for java, that allows creating rich internet applications fast and without a line in javascript.  Interesting fact is that Vaadin is actually "10 years old, but 21 months young" - as the framework exists already for a long time, but only recently it became popular. You can write everything in java, no javascript debugging, no html, and if you are writing in some other jvm language, then you don't need java too! Scala, Groovy, Jruby ... are all good. Also a nice coding session, where Joonas wrote a nice web application in 15 minutes! I liked it, very impressive.&lt;/p&gt;
&lt;p&gt;&lt;a class="external" href="http://john-davies.blogspot.com/"&gt;John Davies&lt;/a&gt; talked about integration of applications. Banking realities: FpML, 100-100000 messages/sec, latency critical - 10ms, xml is evil - no time for &amp;lt;&amp;gt;, network cards process the messages, not cpu - how the time is critical, 30PB of cache?! We also learned, why common message mapping is bad, when you have huge amount of data. That is converting to common message format and from it, when we can actually convert straight. What we need actually is to know how to convert each field of the message between POJO and particular format. XPath using in objects... and so on.&lt;/p&gt; 
&lt;p&gt;After the lunch noSql databases, particularly GraphDB called &lt;a class="external" href="http://neo4j.org/"&gt;Neo4j&lt;/a&gt; was covered by &lt;a class="external" href="http://twitter.com/#!/peterneubauer"&gt;Peter Neubauer&lt;/a&gt;. It was a kind of introductory presentation, showing the concepts of the database, with examples of searching and storing the data and also conditions in which GraphDBs can and should be used instead of Sql databases.&lt;/p&gt;  
&lt;p&gt;Jevgeni Kabanov showed problems that one may face doing the update of web application. For instance, the out of memory error problem arises because of previous version of application not being garbage collected, if there is a not matter how small leak, because it has the link to the classloader and it has the link to the previous version of application.&lt;/p&gt;
&lt;p&gt;The last talk, presented once again by Martijn Verburg, was a relaxing one. Very funny, but at the same time serious. Have to figure out yourself, what qualities of a Diabolic Programmer are good, what not, and what good to some extent.&lt;/p&gt;
&lt;p&gt;The closing of the GeekOut conference was in cafe in the same building. Free pizza and some drinks - nice ending of the good day. Next time I definitely will attend GeekOut again!&lt;/p&gt;

&lt;p&gt;The Slides:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class="external" href="http://www.slideshare.net/martijnverburg/back-to-thefuturewithjava-7geekout"&gt;Back To The Future With Java 7 ~ Martijn Verburg&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="external" href="http://www.slideshare.net/jojule/vaadin-rich-web-apps-in-serverside-java-without-plugins-or-javascript"&gt;Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript ~ Joonas Lehtinen&lt;/a&gt;
&lt;li&gt;&lt;a class="external" href="http://www.infoq.com/presentations/Large-Scale-Integration-in-Financial-Services"&gt;Architecting For Enterprise Scale ~ John T. Davies&lt;/a&gt; (Filmed on QCon)&lt;/li&gt;
&lt;li&gt;&lt;a class="external" href="http://www.slideshare.net/peterneubauer/geekout-tallinn-neo4j-for-the-rescue"&gt;Neo4j For the Rescue ~ Peter Neubauer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;PS. I will list all the slides of the presentations here as soon as they appear.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3510414207362609089?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3510414207362609089/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/06/geekout-first-java-conference-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3510414207362609089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3510414207362609089'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/06/geekout-first-java-conference-in.html' title='GeekOut: The First Java Conference In Estonia'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2003976714454440501</id><published>2011-05-11T11:16:00.000+03:00</published><updated>2011-05-11T11:16:39.212+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Code Jam'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Google Code Jam 2011 Qualification Round</title><content type='html'>&lt;p&gt;This Saturday &lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=975485#"&gt;Google Code Jam 2011 Qualification Round&lt;/a&gt; took place. I didn't have much time to spend on the problems, but still have solved a couple and proceeded to Round 1.&lt;/p&gt;
&lt;p&gt;The ones that I solved are &lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=975485#s=p1"&gt;Magicka&lt;/a&gt; and &lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=975485#s=p2"&gt;Candy Splitting&lt;/a&gt;.
&lt;h3&gt;Magicka&lt;/h3&gt;
&lt;p&gt;First I tried to solve it with some cunning string substitution involving regular expressions. But in the end the simple simulation did the trick. I actually was a little bit disappointed after the official solutions were announced, because I thought that there should be some trick in here.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;#!/usr/bin/ruby

lines = ARGF.readlines

t = lines.first.to_i
(1..t).each do |test_id|
  arr = lines[test_id].split " "
  c = arr[0].to_i
  combines = arr[1..c].inject({}){|memo, e| memo[e[0..1]]=e[2]; memo[e[1]+e[0]]=e[2]; memo }
  d = arr[c+1].to_i
  opposed = arr[c+2..c+1+d]
  n = arr[c+2+d].to_i
  elems = arr[c+3+d] #.split("").collect {|i| i.to_sym }

  result = []
  elems.split("").each do |elem|
    result &amp;lt;&amp;lt; elem
    if result.length &amp;gt; 1
      last2 = result[-2..-1].join
      if combines.key?(last2)
        result.pop(2)
        result = result &amp;lt;&amp;lt; combines[last2]
      end
      opposed.each do |o|
        if result.include?(o[0]) &amp;&amp; result.include?(o[1])
          result = []
          break
        end
      end
    end
  end

  puts "Case ##{test_id}: [#{result.join(", ")}]"
end&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Candy Splitting&lt;/h3&gt;
&lt;p&gt;This one was a little bit more tricky and the author's solution is much more simpler and clear than mine. I made it using old school brute force, just like &lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=975485#s=p3&amp;a=2"&gt;Goro&lt;/a&gt; (strength is my strength :) )&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;#!/usr/bin/ruby

def s( candies, pile1, pile2 )
 #p "c:#{candies}, 1:#{pile1}, 2:#{pile2}"
 if candies.empty?
  if !pile1.empty? &amp;&amp; !pile2.empty? &amp;&amp; pile1.inject(0){|memo, i| memo ^ i} == pile2.inject(0){|memo, i| memo ^ i}
   return pile1
  else
   return false
  end
 end
 x = candies.shift
 p1 = pile1.clone
 return s( candies, p1 &lt;&lt; x, pile2) || s( candies, pile1, pile2 &lt;&lt; x)
end

lines = ARGF.readlines

t = lines.first.to_i
(1..t).each do |test_id|
 n_candies = lines[test_id*2-1]
 candies = lines[test_id*2].split(" ").collect{|i| i.to_i }

 r = s( candies.sort.reverse, [], [] )
 r = !r ? "NO" : r.inject(:+)

 puts "Case ##{test_id}: #{r}"
end&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2003976714454440501?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2003976714454440501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/05/google-code-jam-2011-qualification.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2003976714454440501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2003976714454440501'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/05/google-code-jam-2011-qualification.html' title='Google Code Jam 2011 Qualification Round'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4482799105975146622</id><published>2011-04-21T17:03:00.000+03:00</published><updated>2011-04-21T17:03:39.229+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Mercurial'/><title type='text'>Mercurial In Ubuntu</title><content type='html'>&lt;p&gt;Since I have moved to &lt;a href="http://www.zeroturnaround.com/" class="external"&gt;ZeroTurnaround&lt;/a&gt; I had to learn a lot of new and interesting things. Most of them are very simple to write about, but as time passes I finally thought up the things, I could share with you.&lt;/p&gt;
&lt;p&gt;We use &lt;a class="external" href="http://mercurial.selenic.com/"&gt;Mercurial&lt;/a&gt; as SCM. So here is a small tip for ubuntu users how to configure hg.&lt;/p&gt;
&lt;p&gt;Mercurial is available to install through repository&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ sudo aptitude install mercurial&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So now as it is installed, we can configure it. Mercurial reads configuration data from several files, if they exist. To list them use:&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ hg help config&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we will edit the &lt;code&gt;$HOME/.hgrc&lt;/code&gt; file to add there some user information, authentication and enable plugins. A &lt;a class="external" href="http://www.selenic.com/mercurial/hgrc.5.html"&gt;configuration file consists of sections&lt;/a&gt;, led by a &lt;code&gt;[section]&lt;/code&gt; header and followed by &lt;code&gt;name = value&lt;/code&gt; entries (sometimes called &lt;i&gt;configuration keys&lt;/i&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code class="ini"&gt;[ui]
username = Firstname Lastname &amp;lt;firstname.lastname@example.net&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we introduced ourselves. The section is &lt;code&gt;&lt;a class="external" href="http://www.selenic.com/mercurial/hgrc.5.html#ui"&gt;[ui]&lt;/a&gt;&lt;/code&gt; and ui.username is typically a person's name and email address. If this field is not declared in hgrc, you will have to enter it manually every time you commit.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ini"&gt;[auth]
foo.prefix=*
foo.username=firstname.lastname@example.net
foo.password=SecretPassword123&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;&lt;a class="external" href="http://www.selenic.com/mercurial/hgrc.5.html#auth"&gt;[auth]&lt;/a&gt;&lt;/code&gt; section allows you to store credentials for http authentication, I hate entering username and password every time I pull or push. You can store several different credentials for different servers here. They will be grouped by the part before the . (full stop, &lt;i&gt;foo&lt;/i&gt; - in my example). And the auth.prefix will determine, which credentials should be used for what http address. It should be either * or a URI with or without the scheme part. In my example 1 and the same credentials are used for all addresses.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ini"&gt;[extensions]
fetch = 
color =
#this extension will get loaded from the file specified
myfeature = ~/.hgext/myfeature.py&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mercurial has an extension mechanism for adding new features. To enable an extension, create an entry for it in &lt;code&gt;&lt;a class="external" href="http://www.selenic.com/mercurial/hgrc.5.html#extensions"&gt;[extensions]&lt;/a&gt;&lt;/code&gt; section. There is a &lt;a class="external" href="http://mercurial.selenic.com/wiki/UsingExtensions"&gt;list of extensions&lt;/a&gt; for Mercurial and you can &lt;a class="external" href="http://mercurial.selenic.com/wiki/WritingExtensions"&gt;write one yourself&lt;/a&gt;. Extensions bundled with Mercurial does not need anything after the &lt;i&gt;equals&lt;/i&gt; sign, but you need to provide the full path to others.&lt;/p&gt;
&lt;p&gt;Now that we have configured it a little bit, we can start using. &lt;a class="external" href="http://hginit.com/"&gt;Mercurial tutorial&lt;/a&gt; by &lt;a class="external" href="http://www.joelonsoftware.com/"&gt;Joel Spolsky&lt;/a&gt; will teach you, how.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4482799105975146622?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4482799105975146622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/04/mercurial-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4482799105975146622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4482799105975146622'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/04/mercurial-in-ubuntu.html' title='Mercurial In Ubuntu'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6971771143279955593</id><published>2011-01-14T16:38:00.001+02:00</published><updated>2011-01-15T17:29:19.953+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='myself'/><title type='text'>Hello, ZeroTurnaround!</title><content type='html'>&lt;p&gt;A week ago I have left Axinom. Now I work in &lt;a class="external" href="http://www.zeroturnaround.com/"&gt;ZeroTurnaround&lt;/a&gt; - the famous home of &lt;a class="external" href="http://www.zeroturnaround.com/jrebel/"&gt;JRebel&lt;/a&gt;. I don't want to write about the causes that made me to do it. (Those who interested may ask in private.) The only thing I can say, that I am definitely glad :) I did it.&lt;/p&gt;
&lt;p&gt;This job switch also means change of technologies I will be working with. During this week I recalled a little bit of Java and got acquainted with Maven, Ant, Hudson and Selenium (not java specific, but still something new). So look for Java related posts in the near future.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6971771143279955593?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6971771143279955593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2011/01/hello-zeroturnaround.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6971771143279955593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6971771143279955593'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2011/01/hello-zeroturnaround.html' title='Hello, ZeroTurnaround!'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-971923957613696184</id><published>2010-12-31T10:44:00.000+02:00</published><updated>2010-12-31T10:44:00.940+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fun'/><title type='text'>Happy New Year!</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/_13GxZrI8up4/TR2XXkrPWqI/AAAAAAAAC_g/c5MnrwSyn6Y/s1600/tree.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="290" width="400" src="http://1.bp.blogspot.com/_13GxZrI8up4/TR2XXkrPWqI/AAAAAAAAC_g/c5MnrwSyn6Y/s400/tree.png" /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;The &lt;a href="http://xkcd.com/835/"&gt;image is not mine&lt;/a&gt;, but I really liked it. Happy New Year to All of you!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-971923957613696184?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/971923957613696184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/12/happy-new-year.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/971923957613696184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/971923957613696184'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/12/happy-new-year.html' title='Happy New Year!'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_13GxZrI8up4/TR2XXkrPWqI/AAAAAAAAC_g/c5MnrwSyn6Y/s72-c/tree.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8948787555333333020</id><published>2010-12-20T15:50:00.000+02:00</published><updated>2010-12-20T15:50:16.006+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Moles'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Automatic Update Of Moles References To Other Solution Projects</title><content type='html'>&lt;p&gt;The situation: I have a solution with several projects in it. One of them is UnitTest project, that uses Moles for mocking. And it has referenses to other projecs in solution as well as to their moled dlls. Every time I change code in my projects and rebuild them, the UnitTest project loses the references to moled dlls, as they allready have other versions. I see that Moles builds new versions of projects' dlls, but it does not update references. Why?&lt;/p&gt;
&lt;p&gt;RTFM, Juri.&lt;/p&gt;
&lt;p&gt;From the &lt;a class="external" href="http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf"&gt;Microsoft Moles Reference Manual (page 12)&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;The Moles framework for Visual Studio monitors build events and automatically forces the regeneration of stub types for projects that have been updated. For efficiency 
reasons, this automatic update only works for &lt;code&gt;.moles&lt;/code&gt; files that are in the &lt;b&gt;top level 
folder of the project&lt;/b&gt;, to avoid walking large nested project structures. This automatic 
update creates a smooth experience when writing code in a test-driven development 
style.&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;So the automatic update of references works only for &lt;code&gt;.moles&lt;/code&gt; files that are in the same folder with the project file. But I have moved all the &lt;code&gt;.moles&lt;/code&gt; files into separate folder.&lt;/p&gt;
&lt;p&gt;Now that I moved all the &lt;code&gt;.moles&lt;/code&gt; files back, it is working.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8948787555333333020?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8948787555333333020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/12/automatic-update-of-moles-references-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8948787555333333020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8948787555333333020'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/12/automatic-update-of-moles-references-to.html' title='Automatic Update Of Moles References To Other Solution Projects'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2079075576852994514</id><published>2010-12-17T23:10:00.001+02:00</published><updated>2010-12-17T23:13:54.732+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='solution'/><category scheme='http://www.blogger.com/atom/ns#' term='wifi'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Solution: Eee Pc Ubuntu 10.10 Wireless Connection Fail After Resume From Hibernate</title><content type='html'>&lt;p&gt;After upgrading your Ubuntu to Maverick, you may have experienced some problems using wireless networks. That is when your computer resumes from hibernate, it is no longer able to connect to any wireless network and only a restart will make it do it again. Also some random disconnects from wireless occur. That concerns not only Eee Pc (I have a 1000h), but I believe every computer that uses RaLink network controller. First, check if it is you :)&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ lspci -k|grep -i network --after-context 3
03:00.0 Network controller: RaLink RT2860
Subsystem: Foxconn International, Inc. Device e002
Kernel driver in use: rt2800pci
Kernel modules: rt2800pci, rt2860sta&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With Ubuntu 10.10 some hardware that was previously driven by the rt2860sta driver is now driven by default by the rt2800pci driver. Sometimes the new rt2800pci does not work as well as the rt2860sta. In that case it is often possible to switch back by blacklisting. As we already saw, we have both drivers installed and the pci one in use. Now we will create a text file that will allow us to easily switch between the drivers.&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;sudo gedit /etc/modprobe.d/blacklist-wlan.conf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Copy these 2 lines into the newly created file.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;blacklist rt2800pci
#install rt2860sta /bin/false&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And save. After the reboot your computer will use the rt2860sta driver. If you want to switch back to the rt2800pci driver, just comment the first line, uncomment the second and reboot.&lt;/p&gt;
&lt;p&gt;PS. Solution was found &lt;a href="https://answers.launchpad.net/ubuntu/+question/132350" class="external"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2079075576852994514?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2079075576852994514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/12/solution-eee-pc-ubuntu-1010-wireless.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2079075576852994514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2079075576852994514'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/12/solution-eee-pc-ubuntu-1010-wireless.html' title='Solution: Eee Pc Ubuntu 10.10 Wireless Connection Fail After Resume From Hibernate'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>2</thr:total><georss:featurename>Tallinn, Estonia</georss:featurename><georss:point>59.4388619 24.7544715</georss:point><georss:box>59.2642994 24.2875525 59.6134244 25.221390500000002</georss:box></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3805340855288549511</id><published>2010-12-14T22:59:00.000+02:00</published><updated>2010-12-14T22:59:03.579+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Lisp'/><category scheme='http://www.blogger.com/atom/ns#' term='book'/><title type='text'>SICP: The 8 queens puzzle</title><content type='html'>&lt;p&gt;The Google AI Contest is over and now I continue to read the SICP book. Now we are solving the famous &lt;a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle" class="external"&gt;8 queens puzzle&lt;/a&gt;. One way to solve the puzzle is to work across the board, placing a queen in each column. Once we have placed k - 1 queens, we must place the k&lt;sup&gt;th&lt;/sup&gt; queen in a position where it does not check any of the queens already on the board. We can formulate this approach recursively: Assume that we have already generated the sequence of all possible ways to place k - 1 queens in the first k - 1 columns of the board. For each of these ways, generate an extended set of positions by placing a queen in each row of the kth column. Now filter these, keeping only the positions for which the queen in the kth column is safe with respect to the other queens. This produces the sequence of all ways to place k queens in the first k columns. By continuing this process, we will produce not only one solution, but all solutions to the puzzle. We implement this solution as a procedure queens, which returns a sequence of all solutions to the problem of placing n queens on an n×n chessboard.&lt;/p&gt;
&lt;p&gt;In the beginning we are given this procedure.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (queens board-size)
  (define (queen-cols k)
    (if (= k 0)
        (list empty-board)
        (filter
         (lambda (positions) (safe? k positions))
         (flatmap
          (lambda (rest-of-queens)
            (map (lambda (new-row)
                   (adjoin-position new-row k rest-of-queens))
                 (enumerate-interval 1 board-size)))
          (queen-cols (- k 1))))))
  (queen-cols board-size))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and we need to write all the sub-procedures that are used by the main one. Let's start from the simplest one.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define empty-board '())&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next task is to write the &lt;code&gt;safe?&lt;/code&gt; function. This should determine for a set of positions, whether the queen in the k&lt;sup&gt;th&lt;/sup&gt; column is safe with respect to the others. I decided to split it into three procedures. 1 checks the horizontal line, one diagonal up and the other diagonal down. We don't actually need the k argument, as we should always check the last queen only. I use reversed-positions as we are starting from the last queen and going to the first one.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (safe? k positions)
  (let ((reversed-positions (reverse positions))
        (last (car (reverse positions))))
  (and (horizontal-safe? last (cdr reversed-positions))
       (diagonal-up-safe? last (cdr reversed-positions))
       (diagonal-down-safe? last (cdr reversed-positions)))))

(define (horizontal-safe? q positions)
  (if (null? positions)
      true
      (and (not (= (car positions) q))
           (horizontal-safe? q (cdr positions)))))

(define (diagonal-up-safe? q reversed-positions)
  (if (null? reversed-positions)
      true
      (and (not(= (car reversed-positions) (+ q 1)))
           (diagonal-up-safe? (+ q 1) (cdr reversed-positions)))))

(define (diagonal-down-safe? q reversed-positions)
  (if (null? reversed-positions)
      true
      (and (not(= (car reversed-positions) (- q 1)))
           (diagonal-down-safe? (- q 1) (cdr reversed-positions)))))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The remaining procedures are much easier to write. &lt;code&gt;flatmap&lt;/code&gt; should join all the lists, that represent queens on board, into one big list. &lt;code&gt;enumerate-interval&lt;/code&gt; just returns a list with values between &lt;code&gt;low&lt;/code&gt; and &lt;code&gt;high&lt;/code&gt;. &lt;code&gt;adjoin-position&lt;/code&gt; just adds new queen to the existing ones.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (flatmap proc lst)
  (foldr append '() (map proc lst)))

(define (enumerate-interval low high)
  (if (&gt; low high)
      '()
      (append (list low) (enumerate-interval (+ low 1) high))))

(define (adjoin-position new-row k rest-of-queens)
  (append rest-of-queens (list new-row)))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, there are some parameters in procedures that are not used. They can be safely removed.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(queens 8)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Returns 92 solutions - which is right.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3805340855288549511?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3805340855288549511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/12/sicp-8-queens-puzzle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3805340855288549511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3805340855288549511'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/12/sicp-8-queens-puzzle.html' title='SICP: The 8 queens puzzle'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1907887732469241823</id><published>2010-12-05T11:55:00.000+02:00</published><updated>2010-12-05T11:55:48.601+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AI'/><category scheme='http://www.blogger.com/atom/ns#' term='game'/><title type='text'>Understanding Pac-Man Ghost Behavior</title><content type='html'>&lt;p&gt;A very &lt;a href="http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior" class="external"&gt;interesting article&lt;/a&gt; about the ghost AI in the world famous game.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1907887732469241823?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1907887732469241823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/12/understanding-pac-man-ghost-behavior.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1907887732469241823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1907887732469241823'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/12/understanding-pac-man-ghost-behavior.html' title='Understanding Pac-Man Ghost Behavior'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4193188841004973293</id><published>2010-12-04T12:08:00.002+02:00</published><updated>2011-11-22T15:51:42.840+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AI'/><category scheme='http://www.blogger.com/atom/ns#' term='contest'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Google AI Challenge. Final.</title><content type='html'>&lt;p&gt;So the &lt;a href="http://planetwars.aichallenge.org" class="external"&gt;Google AI Contest&lt;/a&gt; is over. I have finished in &lt;a href="http://planetwars.aichallenge.org/profile.php?user_id=10047" class="external"&gt;150 place&lt;/a&gt;, which is good, but could be better :).&lt;/p&gt;&lt;p&gt;The winner - &lt;a href="http://planetwars.aichallenge.org/profile.php?user_id=8565" class="external"&gt;bocsimacko&lt;/a&gt; - has &lt;a href="http://quotenil.com/Planet-Wars-Post-Mortem.html" class="external"&gt;shared his algorithm and source code in his blog.&lt;/a&gt; The same was done by the runner up - &lt;a href="http://planetwars.aichallenge.org/profile.php?user_id=7026" class="external"&gt;_iouri_&lt;/a&gt; - &lt;a href="http://iouri-khramtsov.blogspot.com/2010/11/google-ai-challenge-planet-wars-entry.html" class="external"&gt;here&lt;/a&gt;. As the two best algorithms are revealed, I will not bother with revealing my :) and start with homework - now the task is to go through at least one of them and understand all the ideas discovered and implemented.&lt;/p&gt;&lt;p&gt;I am looking forward to the next Google AI Challenge and this time I will prepare thoroughly to get the high place in it.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4193188841004973293?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4193188841004973293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/12/google-ai-challenge-final.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4193188841004973293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4193188841004973293'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/12/google-ai-challenge-final.html' title='Google AI Challenge. Final.'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1155287133691482276</id><published>2010-09-27T15:10:00.001+03:00</published><updated>2010-09-27T16:01:16.234+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AI'/><category scheme='http://www.blogger.com/atom/ns#' term='contest'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Google AI Challenge. Continued.</title><content type='html'>&lt;p&gt;Yesterday's 6 hours of coding and implementing the new version of my bot, that killed the previous one on every of 100 testing maps, are not wasted - I am on the 14&lt;sup&gt;th&lt;/sup&gt; place with ELO 3335.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1155287133691482276?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1155287133691482276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/09/google-ai-challenge-continued.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1155287133691482276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1155287133691482276'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/09/google-ai-challenge-continued.html' title='Google AI Challenge. Continued.'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6491856752922808082</id><published>2010-09-24T13:37:00.000+03:00</published><updated>2010-09-24T13:37:47.614+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AI'/><category scheme='http://www.blogger.com/atom/ns#' term='contest'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Google AI Challenge</title><content type='html'>&lt;p&gt;University of Waterloo Computer Science Club organized &lt;a href="http://ai-contest.com/"&gt;AI Contest&lt;/a&gt;, sponsored by Google. Contestants are asked to create a bot that plays PlanetWars game, which is based on &lt;a href="http://www.galcon.com/"&gt;GalCon&lt;/a&gt;. The game field consists of several planets, that are occupied by one of the players or neutral. Planets produce ships (bigger planets do it quicker) players use to conquer new planets. The goal is to beat the other player.&lt;/p&gt;
&lt;center&gt;&lt;a href="http://1.bp.blogspot.com/_13GxZrI8up4/TJx9pOjzPuI/AAAAAAAAC_A/LtR9Xi00h3E/s1600/PlanetWars.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/_13GxZrI8up4/TJx9pOjzPuI/AAAAAAAAC_A/LtR9Xi00h3E/s640/PlanetWars.png" width="616" /&gt;&lt;/a&gt;&lt;/center&gt;
&lt;p&gt;I am also taking part in the tournament and, francly speaking, doing well. Currently I am around 200th place (username: &lt;a href="http://ai-contest.com/profile.php?user_id=8308"&gt;2stupidogs&lt;/a&gt;) in total ranking and one of the best in Estonia. Here are some strategy thoughts I can share with you as the starting point. These were used by my first 2 bots. (Now I have implemented a more deeper algorithm.) The organisers provide everyone with default strategy bot, that can we further improved. And by making the following small improvements you can make top 500 easily.&lt;/p&gt;
&lt;p&gt;Default bot finds his strongest planet and sends half of the fleet from it to the near planet, that it considers to be weak.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First change is to send as many ships as needed to conquer the planet, not just the half.&lt;/li&gt;
&lt;li&gt;Then change the planet score formula (Determines how weak enemy planet is). It should depend on distanse, growth rate and current fleet on the planet. For example, count in how many days the new planet will regenerate the fleet you had to use to conquer it. The less it takes, the better the planet for you.&lt;/li&gt;
&lt;li&gt;Don't send fleet to the planet where is was sent already. (Well, this is doubtable, but you can try.)&lt;/li&gt;
&lt;li&gt;Make a list of weakest planets for your strongest planet (not just the one weakest planet), and send a fleet to all of them as soon as you have enough ships.&lt;/li&gt;
&lt;li&gt;Make a list of your strongest planets and look for weakest planets for every of them.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Just implementing this strategy I managed to make into top 350 list, but it was less contestants then.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6491856752922808082?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6491856752922808082/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/09/google-ai-challenge.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6491856752922808082'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6491856752922808082'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/09/google-ai-challenge.html' title='Google AI Challenge'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_13GxZrI8up4/TJx9pOjzPuI/AAAAAAAAC_A/LtR9Xi00h3E/s72-c/PlanetWars.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8141136556534441573</id><published>2010-08-25T17:05:00.002+03:00</published><updated>2010-08-26T10:59:48.521+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MongoDB'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>MongoDB With C++ In Ubuntu</title><content type='html'>&lt;p&gt;Install standard repository package.&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ sudo aptitude install mongodb&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create data directory. By default mongo uses &lt;code&gt;/data/db&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ sudo mkdir -p /data/db/
$ sudo chown `id -u` /data/db&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Try to run the server. (If you decided to use another path for data run &lt;code&gt;mongod&lt;/code&gt; with &lt;code&gt;--dbpath&lt;/code&gt; option)&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ mongod&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If it runs, the you are ok. But if it throws an error&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;mongo: error while loading shared libraries: libmozjs.so: cannot open shared object file: No such file or directory&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we will have to find that missing library.&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ find /usr/lib/* -name libmozjs.so
/usr/lib/firefox-3.6.8/libmozjs.so
/usr/lib/xulrunner-1.9.2.8/libmozjs.so
/usr/lib/xulrunner-devel-1.9.2.8/sdk/lib/libmozjs.so&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now create a symbolic link&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ cd /usr/lib
$ sudo ln -s xulrunner-devel-1.9.2.8/sdk/lib/libmozjs.so libmozjs.so&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now try to start the server again. It should be working. Start the client and run some queries:&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ mongo
&amp;gt; db.foo.save( { a : 1 } )
&amp;gt; db.foo.find()&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Installing Libraries For C++&lt;/h3&gt;
&lt;p&gt;So the database is up and running, now we need some C++ libs to be able to connect to it.&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ sudo aptitude install libboost-all-dev libpcre++-dev&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we should be able to run this code, to test the connection.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;//tutorial.cpp
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;mongo/client/dbclient.h&amp;gt;

using namespace std;

void run() {
  mongo::DBClientConnection c;
  c.connect("localhost");
}

int main() {
  try {
    run();
    cout &lt;&lt; "connected ok" &lt;&lt; endl;
  } catch( mongo::DBException &amp;e ) {
    cout &lt;&lt; "caught " &lt;&lt; e.what() &lt;&lt; endl;
  }
  return 0;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Build and run this code using:&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;$ g++ tutorial.cpp -lmongoclient -lboost_thread-mt -lboost_filesystem-mt -lboost_program_options-mt tutorial
$ ./tutorial
connected ok
&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8141136556534441573?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8141136556534441573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/08/mongodb-with-c-in-ubuntu.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8141136556534441573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8141136556534441573'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/08/mongodb-with-c-in-ubuntu.html' title='MongoDB With C++ In Ubuntu'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-7817686641859526717</id><published>2010-08-18T22:27:00.007+03:00</published><updated>2010-08-19T14:12:41.476+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Lisp'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='book'/><title type='text'>Determine If Number Is Prime</title><content type='html'>&lt;p&gt;The SICP book is still being read...&lt;/p&gt;
&lt;p&gt;Now I am going to introduce some algorithms that allow us to say whether the number is prime or not. Again we will start from the simplest one.&lt;/p&gt;
&lt;p&gt;Take numbers 1 by 1 starting from 2 to √n and check, if it divides n. The complexity of the algorithm is Θ(√n).&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (prime? n)
  (define (divides? k)
    (= (remainder n k) 0))
  (define (find-divisor n test)
    (cond ((&amp;gt; (sqr test) n) n)
          ((divides? test) test)
          (else (find-divisor n (+ test 1)))))

  (= n (find-divisor n 2)))
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Fermat Primality Test&lt;/h3&gt;
&lt;p&gt;There is a test for primality with Θ(log(n)) complexity. It is based on &lt;a class="external" href="http://en.wikipedia.org/wiki/Fermat%27s_little_theorem"&gt;Fermat little theorem&lt;/a&gt;.&lt;/p&gt;
&lt;center&gt;&lt;pre&gt;a&lt;sup&gt;n&lt;/sup&gt; ≡ a (mod n), where 1 ≤ a &amp;lt; n&lt;/pre&gt;&lt;/center&gt;
&lt;p&gt;Which means, that if n is prime, then for any integer &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;a&lt;sup&gt;n&lt;/sup&gt; − a&lt;/code&gt; will be evenly divisible by n.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;;this procedure calculates base&lt;sup&gt;exp&lt;/sup&gt; mod m without using big numbers
(define (expmod base exp m)
  (cond ((= exp 0) 1)
        ((even? exp) (remainder (sqr (expmod base (/ exp 2) m)) m))
        (else (remainder (* base (expmod base (- exp 1) m)) m))))

(define (fermat-test n)
  (define (try-it a)
    (= (expmod a n n) a))
  (try-it (+ 1 (random (- n 1)))))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunately there are some issues with this test - it is probabilistic. If the test fails, n is certainly composite. But if it passes, it does not guarantee that n is prime, although it shows high probability for n to be. So we can run as many tests as we need to make the mistake probability as low as possible.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (fermat-prime? n times)
  (cond ((= times 0) true)
        ((fermat-test n) (fermat-prime? n (- times 1)))
        (else false)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunately that is not all. There are some numbers that pass the test (for every &lt;code&gt;a&lt;/code&gt;!), without being prime. These are called &lt;a class="external" href="http://en.wikipedia.org/wiki/Carmichael_number"&gt;Carmichael numbers&lt;/a&gt;. So to determine, if &lt;code&gt;n&lt;/code&gt; is prime, we need to check if it passes the Fermat test and is not a Carmichael number, or use a similar &lt;a class="external" href="http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test"&gt;Miller–Rabin primality test&lt;/a&gt;, that cannot be tricked.&lt;/p&gt;
&lt;h3&gt;Miller–Rabin Primality Test&lt;/h3&gt;
It starts from an alternate form of Fermat's Little Theorem:&lt;/p&gt;
&lt;center&gt;&lt;pre&gt;a&lt;sup&gt;n-1&lt;/sup&gt; ≡ 1 (mod n), where 1 ≤ a &amp;lt; n&lt;/pre&gt;&lt;/center&gt;
&lt;p&gt;The difference is that whenever we perform the squaring step in &lt;code&gt;expmod&lt;/code&gt;, we check to see if we have discovered a "nontrivial square root of 1 modulo p", that is, a number not equal to &lt;code&gt;1&lt;/code&gt; or &lt;code&gt;n - 1&lt;/code&gt; whose square is equal to &lt;code&gt;1 mod n&lt;/code&gt;. It is possible to prove that if such a nontrivial square root of &lt;code&gt;1&lt;/code&gt; exists, then &lt;code&gt;n&lt;/code&gt; is not prime. It is also possible to prove that if &lt;code&gt;n&lt;/code&gt; is an odd number that is not prime, then, for at least half the numbers &lt;code&gt;a &amp;lt; n&lt;/code&gt;, computing &lt;code&gt;a&lt;sup&gt;n-1&lt;/sup&gt;&lt;/code&gt; in this way will reveal a nontrivial square root of &lt;code&gt;1 mod n&lt;/code&gt;.
&lt;pre&gt;&lt;code class="lisp"&gt;(define (miller-rabin-prime? n times)
  (cond ((= times 0) true)
        ((miller-rabin-test n) (miller-rabin-prime? n (- times 1)))
        (else false)))

(define (miller-rabin-test n)
  (define (try-it a)
    (= (expmod a (- n 1) n) 1))
  (try-it (+ 1 (random (- n 1)))))

(define (expmod base exp m)
  (define (!= x y) (not (= x y)))

  (cond ((= exp 0) 1)
        ((and (!= base 1) 
              (!= base (- m 1)) 
              (= (remainder( sqr base) m) 1)) 0)
        ((even? exp) (remainder (sqr (expmod base (/ exp 2) m)) m))
        (else (remainder (* base (expmod base (- exp 1) m)) m))))&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-7817686641859526717?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/7817686641859526717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/07/determine-if-number-is-prime.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7817686641859526717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7817686641859526717'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/07/determine-if-number-is-prime.html' title='Determine If Number Is Prime'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-158805180155425404</id><published>2010-07-20T17:40:00.007+03:00</published><updated>2010-07-30T14:41:13.660+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Lisp'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='Fibonacci'/><category scheme='http://www.blogger.com/atom/ns#' term='book'/><title type='text'>Fibonacci Numbers</title><content type='html'>&lt;p&gt;
Continuing reading the SICP book...&lt;/p&gt;
&lt;p&gt;
In every book about algorithms I have read there is always a chapter about the Fibonacci numbers. Mainly on the different algorithms of calculating the n-th Fibonacci number and comparing their order of growth. First comes the algorithm, based on definition:&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (fib n)
  (cond ((= n 0) 0)
        ((= n 1) 1)
        (else (+ (fib (- n 1))
                 (fib (- n 2))))))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
This function is good at explaining tree recursion, but is awful for calculating Fibonacci numbers, as it makes too many unnecessary calculations. The order of growth is &amp;Theta;(Fib(n)), which means exponential. The next comes iterative funcion, which solves the task much better, using less resources and time. Its order of growth is &amp;Theta;(n) - linear.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (fib n)
  (fib-iter 1 0 n))

(define (fib-iter a b count)
  (if (= count 0)
     b
     (fib-iter (+ a b) a (- count 1))))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
But there is also an algorithm that calculates Fibonacci number with &amp;Theta;(log n) complexity. There, in the book they give you the function with gaps and some pointers ( no C here :) ), how to fill them.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lisp"&gt;(define (fib n)
  (fib-iter 1 0 0 1 n))

(define (fib-iter a b p q count)
  (cond ((= count 0) b)
        ((even? count)
         (fib-iter a
                   b
                   [??] calculate p'
                   [??] calculate q'
                   (/ count 2)))
        (else (fib-iter (+ (* b q) (* a q) (* a p))
                        (+ (* b p) (* a q))
                        p
                        q
                        (- count 1)))))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The authors remind us of the transformation of the state variables a and b in the previous (iterative) fib-iter procedure: a ← a + b and b ← a. Provided these state changes are labeled transformation T, applying T repeatedly for n iterations starting with a = 1 and b = 0 will produce the pair a = Fib(n + 1) and b = Fib(n). So the Fibonacci numbers are produced by the n&lt;sup&gt;th&lt;/sup&gt; power of the transformation T (T&lt;sup&gt;n&lt;/sup&gt;), starting with the pair (1, 0).&lt;/p&gt;
&lt;p&gt;
Now consider the family of transformations T&lt;sub&gt;pq&lt;/sub&gt; which transforms the pair (a, b) according to the following rules:&lt;/p&gt;
&lt;center&gt;&lt;pre&gt;a ← bq + aq + ap
b ← bp + aq&lt;/pre&gt;
&lt;/center&gt;
&lt;p&gt;
Where transformation T is just a special case of T&lt;sub&gt;pq&lt;/sub&gt;, where p = 0 and q = 1. Now it's up to you to find the transformation T&lt;sub&gt;p'q'&lt;/sub&gt; such so, if we apply T&lt;sub&gt;pq&lt;/sub&gt; twice, the effect is the same as using a single transformation T&lt;sub&gt;p'q'&lt;/sub&gt; of the same form. Compute p' and q' in terms of p and q and put into the function.&lt;/p&gt;
&lt;p&gt;
I will not provide the solution here, in case you want to handle it yourself. But if you are eager to see the result, visit &lt;a class="external" href="http://www.billthelizard.com/2010/01/sicp-exercise-119-computing-fibonacci.html"&gt;some other blog that has the solution&lt;/a&gt;. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-158805180155425404?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/158805180155425404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/07/fibonacci-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/158805180155425404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/158805180155425404'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/07/fibonacci-numbers.html' title='Fibonacci Numbers'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-5749324626134415228</id><published>2010-07-19T10:52:00.001+03:00</published><updated>2011-11-09T16:13:04.918+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Lisp'/><category scheme='http://www.blogger.com/atom/ns#' term='book'/><title type='text'>Structure and Interpretation of Computer Programs</title><content type='html'>&lt;p&gt;Recently we decided to read the "Structure and Interpretation of Computer Programs" book through. And not just read it, but also to complete the exercises, given after each chapter. On Friday we had a first meeting, concerning the first chapters we read.&lt;/p&gt;&lt;p&gt;As a working environment the &lt;a href="http://www.racket-lang.org/"&gt;Racket&lt;/a&gt; was chosen. It turned out to be a very powerful instrument: not just the language and it's interpretor, but almost a complete IDE with autocomplete, unit tests and even debugging.&lt;/p&gt;&lt;center&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-wd_Z2kejSA4/TrqKRYBLY7I/AAAAAAAADIs/oRKNhLfC0pU/s1600/racketError.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="241" width="400" src="http://1.bp.blogspot.com/-wd_Z2kejSA4/TrqKRYBLY7I/AAAAAAAADIs/oRKNhLfC0pU/s400/racketError.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;i&gt;That is how errors are shown in Racket. Yes, these arrows are cute.&lt;/i&gt;&lt;/p&gt;&lt;/center&gt; &lt;p&gt;The meeting was nice and quite productive. We shared some solutions to exercises, and also some were solved just in place. We learned that&lt;/p&gt;&lt;pre&gt;&lt;code class="scheme"&gt;(A 2 6)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;is a very big number :), where&lt;/p&gt;&lt;pre&gt;&lt;code class="scheme"&gt;(define (A x y)
  (cond ((= y 0) 0)
        ((= x 0) (* 2 y))
        ((= y 1) 2)
        (else (A (- x 1)
                 (A x (- y 1))))))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;P.S. Thanks &lt;a class="external" href="http://anton-arhipov.livejournal.com/151134.html"&gt;Anton&lt;/a&gt; for the picture :)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-5749324626134415228?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/5749324626134415228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/07/structure-and-interpretation-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5749324626134415228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5749324626134415228'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/07/structure-and-interpretation-of.html' title='Structure and Interpretation of Computer Programs'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-wd_Z2kejSA4/TrqKRYBLY7I/AAAAAAAADIs/oRKNhLfC0pU/s72-c/racketError.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1963313926516272654</id><published>2010-07-14T17:32:00.001+03:00</published><updated>2010-07-14T17:36:31.668+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>C# Function That Mimics SQL IN-operator</title><content type='html'>&lt;p&gt;A &lt;a href="http://stackoverflow.com/questions/3244333/c-do-if-a-b-or-c-or-d-is-it-possible" class="external"&gt;good question&lt;/a&gt; was asked on stackoverflow, and an even better answer received.&lt;/p&gt;
&lt;p&gt;How can we rewrite the condition&lt;/p&gt;
&lt;pre&gt;&lt;code class="cs"&gt;if (a == x || a == y || a == z)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to make it more readable?&lt;/p&gt;
&lt;p&gt;The answer is&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public static bool IsIn&amp;lt;T&amp;gt;(this T obj, params T[] collection) {
   return collection.Contains(obj);
}

if (a.IsIn(x, y, z))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;PS. Sorry for such a long period with no posting. You know, summer, Sun, beach, sea, +30 and vacation.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1963313926516272654?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1963313926516272654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/07/c-function-that-mimics-sql-in-operator.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1963313926516272654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1963313926516272654'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/07/c-function-that-mimics-sql-in-operator.html' title='C# Function That Mimics SQL IN-operator'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3506745905838599240</id><published>2010-05-24T20:12:00.003+03:00</published><updated>2010-05-25T21:20:15.157+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Code Jam'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Google Code Jam 2010 - Round 1</title><content type='html'>&lt;p&gt;Sadly I didn't qualify into Round 2. But actually didn't have any chance, because at the time I posted my first solution to the A problem, the top scorers board  was already full of 100s (That is maximum one could get for solving all 3 problems.) So as the qualifying round this one had 3 problems: A, B and C, with A being the simplest one and C the hardest one. As I participated in Round 1B, here are the thoughts on problems that I met there.&lt;/p&gt;
&lt;h3&gt;File Fix-It&lt;/h3&gt;
&lt;p&gt;(&lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=635101#"&gt;Problem Text&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;This one is about creating the tree of folders and counting how many folders you have to create. The solution algorithm is simple.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We create a root node.&lt;/li&gt;
&lt;li&gt;Read the next folder, we must create (with path).&lt;/li&gt;
&lt;li&gt;Split the path.&lt;/li&gt;
&lt;li&gt;Add folders one by one to the root node, counting how many of them we had to create.&lt;/li&gt;
&lt;li&gt;Goto 2&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is my c++ code.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;map&amp;gt;

using namespace std;

class Node{
public:
  string name;
  map&amp;lt;string, Node&amp;gt; children;

  Node(){}
  Node( string n ):name(n){}
};

vector&amp;lt;string&amp;gt; split( const string&amp;amp; s, const string&amp;amp; delimiter ){
  vector&amp;lt;string&amp;gt; result;
  string::size_type from = 0;
  string::size_type to = 0;

  while ( to != string::npos ){
    to = s.find( delimiter, from );
    if ( from &amp;lt; s.size() &amp;amp;&amp;amp; from != to ){
      result.push_back( s.substr( from, to - from ) );
    }
    from = to + delimiter.size();
  }
  return result;
}

int add_to_node( Node* current, vector&amp;lt;string&amp;gt;&amp;amp; path ){
  int r = 0;
  for (int i=0; i&amp;lt;path.size(); i++){
    if (current-&amp;gt;children.find(path[i]) == current-&amp;gt;children.end()){
      r++;
      Node child(path[i]);
      current-&amp;gt;children[path[i]] = child;
    }
    current = &amp;amp;( current-&amp;gt;children[path[i]] );
  }
  return r;
}

int main(){
  int t;
  cin &amp;gt;&amp;gt; t;
  for (int i=1; i&amp;lt;=t; i++){
    int n, m;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;
    Node root(&amp;quot;&amp;quot;);
    for (int j=0; j&amp;lt;n; j++){
      string s;
      cin &amp;gt;&amp;gt; s;
      vector&amp;lt;string&amp;gt; path = split( s, &amp;quot;/&amp;quot; );
      //cout &amp;lt;&amp;lt; root.children.size();
      add_to_node( &amp;amp;root, path );
    }
    int total = 0;
    for (int j=0; j&amp;lt;m; j++){
      string s;
      cin &amp;gt;&amp;gt; s;
      vector&amp;lt;string&amp;gt; path = split( s, &amp;quot;/&amp;quot; );
      total += add_to_node( &amp;amp;root, path );
    }
    cout &amp;lt;&amp;lt; &amp;quot;Case #&amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;: &amp;quot; &amp;lt;&amp;lt; total &amp;lt;&amp;lt;endl;
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Picking Up Chicks&lt;/h3&gt;
&lt;p&gt;(&lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=635101#s=p1"&gt;Problem Text&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;This problem is about finding out how many (slow) chicks prevent one particular (fast) chick to get to the barn in time. (This solution is in ruby). My solution actually is not optimal, but it is still solving the problem.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;#!/usr/bin/env ruby

c = ARGF.readline.to_i
(1..c).each do |i|
  n, k, b, t = ARGF.readline.split(&amp;quot; &amp;quot;).collect{|x| x.to_i }
  x = ARGF.readline.split(&amp;quot; &amp;quot;).collect{|y| y.to_i }
  v = ARGF.readline.split(&amp;quot; &amp;quot;).collect{|y| y.to_i }

  times = []
  x.each_index do |j|
    d = b-x[j]
    times &amp;lt;&amp;lt; ( d % v[j] == 0 ? d / v[j] : d / v[j] + 1 )
  end

  chicks = 0
  max = 0
  swaps = 0

  times.reverse!
  times.each_index do |ti|
    max = times[ti] &amp;gt; max ? times[ti] : max
    if t &amp;gt;= max
      chicks += 1
    elsif t &amp;gt;= times[ti]
      chicks += 1
      #we need to swap only with those chicks that will arrive later and won't get in time
      swaps += times[0...ti].collect{|one| one &amp;gt; times[ti] &amp;amp;&amp;amp; one &amp;gt; t ? one : nil }.compact.count
    end
    break if chicks &amp;gt;= k
  end

  print( &amp;quot;Case #&amp;quot;, i,&amp;quot;: &amp;quot;, (chicks &amp;gt;= k ? swaps : &amp;quot;IMPOSSIBLE&amp;quot;), &amp;quot;\n&amp;quot; )
end&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Your Rank is Pure&lt;/h3&gt;
&lt;p&gt;(&lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=635101#s=p2&amp;a=2"&gt;Problem Text&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;I ran out of time before I even could understand what this problem was all about. So i cannot tell anything about it. I will try to solve it later though.&lt;/p&gt;
&lt;p&gt;I have also checked out the &lt;a class="external" href="http://code.google.com/codejam/contest/dashboard?c=635101#s=a&amp;a=0"&gt;official solutions&lt;/a&gt; for the first 2 problems, and they appear to be much cleaner and simpler than mine. My approach is too straightforward. Have to practice more...&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3506745905838599240?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3506745905838599240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/05/google-code-jam-round-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3506745905838599240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3506745905838599240'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/05/google-code-jam-round-1.html' title='Google Code Jam 2010 - Round 1'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8180480451207596233</id><published>2010-05-20T12:53:00.001+03:00</published><updated>2010-05-20T12:54:35.927+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='regex'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Replacing Text In Html (Outside Html Tags)</title><content type='html'>&lt;pre&gt;&lt;code class="csharp"&gt;private const string OUTSIDE_TAG_LOOKAHEAD = "(?![^&amp;lt;]+&amp;gt;)";

public static string HighlightWordsInHtmlText( string htmlText, params string[] words ){
  if (words == null || string.IsNullOrEmpty(htmlText) ) return htmlText;
  Regex regex = new Regex(OUTSIDE_TAG_LOOKAHEAD + "("+ string.Join("|", words) +")", RegexOptions.IgnoreCase);
  return regex.Replace(htmlText, "&amp;lt;span class=\"highlight\"&amp;gt;$&amp;amp;&amp;lt;/span&amp;gt;" );
}&lt;/code&gt;&lt;/pre&gt;
OUTSIDE_TAG_LOOKAHEAD - uses &lt;a class="external" href="http://www.regular-expressions.info/lookaround.html"&gt;regular expression magic&lt;/a&gt;, that matches text inside tags, but as it is negated, the text matched is really outside of html tags.&lt;br /&gt;
$&amp;amp; - &lt;a class="external" href="http://www.regular-expressions.info/dotnet.html"&gt;refers to the current match&lt;/a&gt;. We cannot put here any word as we don't precisely know what of them was found and in what case.&lt;br /&gt;
This example matches also &lt;i&gt;tron&lt;/i&gt; in &lt;i&gt;s&lt;b&gt;tron&lt;/b&gt;g&lt;/i&gt;, if you need an exact match add word boundaries like that:&lt;br /&gt;
&lt;pre&gt;&lt;code class="csharp"&gt;OUTSIDE_TAG_LOOKAHEAD + "\\b("+ string.Join("|", words) +")\\b"&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8180480451207596233?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8180480451207596233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/05/replacing-text-in-html-outside-html.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8180480451207596233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8180480451207596233'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/05/replacing-text-in-html-outside-html.html' title='Replacing Text In Html (Outside Html Tags)'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3747726916578152735</id><published>2010-05-17T11:37:00.000+03:00</published><updated>2010-05-17T11:37:38.141+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><title type='text'>Try Ruby Online</title><content type='html'>&lt;p&gt;Interactive ruby console is available at &lt;a href="http://tryruby.org/" class="external"&gt;http://tryruby.org/&lt;/a&gt;. It is not very convenient to delete wrong entered character there (you should put a cursor on it, not after it, and press backspace), but it works! :) &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3747726916578152735?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3747726916578152735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/05/try-ruby-online.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3747726916578152735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3747726916578152735'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/05/try-ruby-online.html' title='Try Ruby Online'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-5842363960466973211</id><published>2010-05-16T15:25:00.006+03:00</published><updated>2010-07-09T14:18:21.644+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='makefile'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>[Almost] Universal Makefile</title><content type='html'>&lt;pre&gt;&lt;code class="bash"&gt;#compiler
CC=g++
#compiler options
OPTS=-c -Wall
#source files
SOURCES=$(wildcard *.cc SomePath/*.cc )
#object files
OBJECTS=$(SOURCES:.cc=.o)
#sdl-config or any other library here. 
#``- ensures that the command between them is executed, and the result is put into LIBS
LIBS=`sdl-config --cflags --libs`
#executable filename
EXECUTABLE=Main.run
#Special symbols used:
#$^ - is all the dependencies (in this case =$(OBJECTS) )
#$@ - is the result name (in this case =$(EXECUTABLE) )

all: $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
 $(LINK.o) $^ -o $@ $(LIBS)

clean:
 rm $(EXECUTABLE) $(OBJECTS)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is hard to say why it works, but it works. "Make" uses hidden rules to compile object files from sources.&lt;/p&gt;
&lt;p&gt;See there for more (in Russian): &lt;a class="external" href="http://abuse.edu.ioffe.ru/cluster/makeman"&gt;http://abuse.edu.ioffe.ru/cluster/makeman&lt;/a&gt; or read the manual :)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-5842363960466973211?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/5842363960466973211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/05/almost-universal-makefile.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5842363960466973211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5842363960466973211'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/05/almost-universal-makefile.html' title='[Almost] Universal Makefile'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-704708980243229581</id><published>2010-05-14T10:57:00.000+03:00</published><updated>2010-05-14T10:57:26.732+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='fun'/><title type='text'>Clean Code</title><content type='html'>The &lt;a href="http://groups.google.com/group/comp.lang.c/msg/e105e5d339edec01?pli=1" class="external"&gt;"cleanest" code&lt;/a&gt; I have ever seen.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-704708980243229581?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/704708980243229581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/05/clean-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/704708980243229581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/704708980243229581'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/05/clean-code.html' title='Clean Code'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6308490826043772961</id><published>2010-05-09T10:22:00.004+03:00</published><updated>2010-07-09T13:17:31.263+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Code Jam'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Google Code Jam  2010 - Qualification round</title><content type='html'>&lt;p&gt;Qualification round of Google Code Jam is over, I have managed to get only 53 points of 99 possible. Not a very good start, but nevertheless I proceeded to Round 1. Here is some of my code, that I solved the problems with.&lt;/p&gt;
&lt;h3&gt;Snapper Chain&lt;/h3&gt;
&lt;p&gt;It was the easiest problem to solve. (&lt;a href="http://code.google.com/codejam/contest/dashboard?c=433101#s=p0" class="external"&gt;Problem Text&lt;/a&gt;) The key to the solution is that the chain shows number of snaps in binary (actually last n bits of it), and light is on when all snappers are in ON state (= the last n bits are all equal to 1).&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;math.h&amp;gt;

using namespace std;

int main(){
  unsigned int t, n, k;
  cin &amp;gt;&amp;gt; t;
  for (unsigned int i=1; i&amp;lt;=t; i++){
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k;
    unsigned int d = (1U &amp;lt;&amp;lt; n ) - 1;

    cout &amp;lt;&amp;lt; &amp;quot;Case #&amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;: &amp;quot; &amp;lt;&amp;lt;
          (  (k &amp;amp; d) == d ? &amp;quot;ON&amp;quot; : &amp;quot;OFF&amp;quot; ) &amp;lt;&amp;lt; endl;
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Provided code was successful with large input too.&lt;/p&gt;
&lt;h3&gt;Fair Warning&lt;/h3&gt;
&lt;p&gt;This one was a little bit harder. (&lt;a href="http://code.google.com/codejam/contest/dashboard?c=433101#s=p1" class="external"&gt;Problem Text&lt;/a&gt;) The key is that the difference is time between any 2 events stays the same, no matter how big/small number of starboseconds we add to all of them. So we need a greatest common divisor of the differences.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp" &gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;algorithm&amp;gt;

using namespace std;

typedef unsigned int uint;

uint gcd( uint a, uint b ){
  if ( b == 0 ) return a;
  return gcd( b, a % b );
}

uint op_minus( uint a, uint b){
  return a &amp;gt; b ? a - b : b - a;
}

int main(){
  uint c, n, tmp;
  cin &amp;gt;&amp;gt; c;
  for (uint i=1; i&amp;lt;=c; i++){
    cin &amp;gt;&amp;gt; n;
    vector&amp;lt;uint&amp;gt; t;
    for (uint j=0; j&amp;lt;n; j++){
      cin &amp;gt;&amp;gt; tmp;
      t.push_back( tmp );
    }
    //after first transformation t[i] will have the difference 
    //between former t[i] and t[i+1]. 
    //The last member t[n-1] remains - it will be needed at the end 
    //to find the required amount of seconds to add 
    transform( t.begin(), t.end()-1, t.begin()+1, t.begin(), op_minus );
    //after second transformation t[i] will have the gcd of t[i-1] and t[i]
    //I use the following feature of gcd: gcd(a,b,c) == gcd(gcd(a,b), c)
    //every time we are at t[i] there is alreaady a gcd(t[i-2], t[i-1]) in t[i-1]
    transform( t.begin(), t.end()-2, t.begin()+1, t.begin()+1, gcd );
    
    uint remainder =  t.back() % *(t.end()-2);
    cout &amp;lt;&amp;lt; &amp;quot;Case #&amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;: &amp;quot; &amp;lt;&amp;lt;
            (remainder &amp;gt; 0 ?  *(t.end()-2) - remainder : 0 )&amp;lt;&amp;lt; endl;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This code does not solve the large input as there are integers up to 10&lt;sup&gt;50&lt;/sup&gt;, and we need to use a bigint class, which I didn't find/write myself.&lt;/p&gt;
&lt;h3&gt;Theme Park&lt;/h3&gt;
&lt;p&gt;This is the hardest one to solve, because small input can be solved with straight approach, but the large one needs some different. And I couldn't figure it out. (&lt;a href="http://code.google.com/codejam/contest/dashboard?c=433101#s=p2" class="external"&gt;Problem Text&lt;/a&gt;) The code that solves the small input is pretty straightforward. We take the group at the beginning of the queue as soon as it can fit in roller coaster. And don't forget that 1 and the same group cannot be taken twice in 1 run (that may happen if number of seats in roller coaster is more than all the number of people in queue)&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;

using namespace std;

typedef unsigned int uint;

int main(){
  uint t, r, k, n, tmp, sum, total;
  cin &amp;gt;&amp;gt; t;
  for (uint i=1; i&amp;lt;=t; i++){
    cin &amp;gt;&amp;gt; r &amp;gt;&amp;gt; k &amp;gt;&amp;gt; n;
    vector&amp;lt;uint&amp;gt; g;
    total = 0;
    for (uint j=0; j&amp;lt;n; j++){
      cin &amp;gt;&amp;gt; tmp;
      g.push_back( tmp );
    }
    uint a=0;
    for (uint j=0; j&amp;lt;r; j++){
      uint sum = 0;
      for (uint b=0;  b&amp;lt;n &amp;amp;&amp;amp; sum + g[a] &amp;lt;= k; a=(a+1)%n, b++ ){
        sum += g[a];
      }
      //cout &amp;lt;&amp;lt; &amp;quot;sum: &amp;quot; &amp;lt;&amp;lt; sum &amp;lt;&amp;lt; &amp;quot; &amp;quot;;
      total += sum;
    }
    cout &amp;lt;&amp;lt; &amp;quot;Case #&amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;: &amp;quot; &amp;lt;&amp;lt; total &amp;lt;&amp;lt; endl;
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Pity, the same approach is too slow for large input.&lt;/p&gt;
&lt;p&gt;The "official" solutions can be found &lt;a href="http://code.google.com/codejam/contest/dashboard?c=433101#s=a" class="external"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6308490826043772961?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6308490826043772961/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/05/google-code-jam-2010-qualification.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6308490826043772961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6308490826043772961'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/05/google-code-jam-2010-qualification.html' title='Google Code Jam  2010 - Qualification round'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4842202066833284966</id><published>2010-05-04T16:43:00.006+03:00</published><updated>2010-07-09T14:17:38.988+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Escaping Curly Bracket in String.Format()</title><content type='html'>&lt;p&gt;If you need to print a curly bracket in string, when using string format, just put it twice in a row.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cs"&gt;string.Format("{{ hello world }}")//{ hello world };
string.Format("{{0}}", 45);//{0}
string.Format("{{{0}}}", 45);//{45}
string.Format("{0:N}", 45);//45.00
string.Format("{{{0:N}}}", 45);//{N}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The last one is not `{45.00}`, because the parser when reading `}}}` first prints the escaped `}`, and only then closes the formatting section. And as `N}` number format does not mean anything to it, it just prints it out.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4842202066833284966?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4842202066833284966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/05/escaping-curly-bracket-in-stringformat.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4842202066833284966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4842202066833284966'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/05/escaping-curly-bracket-in-stringformat.html' title='Escaping Curly Bracket in String.Format()'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8523906795025417242</id><published>2010-04-13T21:58:00.002+03:00</published><updated>2010-07-09T14:12:26.040+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Pointers and Memory Handling In C++</title><content type='html'>&lt;p&gt;Handling memory resources doesn't need any special knowledge in C++, the memory is freed as soon as the variable is out of scope. Unless you are dealing with pointers. Memory that is addressed by pointer is not freed automatically, even if you are out the scope already. It should be done manually, using &lt;i&gt;delete&lt;/i&gt; or some provided special function (If it's some library).&lt;/p&gt;
&lt;p&gt;Let's take the following function as an example.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;void use_file( const char* fn ){
  FILE* f = fopen( fn, "w" );
  //using f;
  fclose( f );
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At first sight nothing seems to be wrong here. The memory allocated by &lt;i&gt;fopen&lt;/i&gt; is freed at the end of the function with &lt;i&gt;fclose&lt;/i&gt;. But what if some exception occurs between those two? Yes, the memory will not be freed. The first attempt to fix this is to add exception handling.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;void use_file( const char* fn ){
  FILE* f = fopen( fn, "w" );
  try {
    //using f;
  }
  catch(...){
    fclose( f );
    throw;
  }
  fclose( f );
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem of this solution is that it is too diffusive. Anybody wants to write everywhere try-catch blocks, just to make sure the memory is freed? I am too lazy to do that. There should be a more elegant solution. We can define a class File_ptr, that will behave just like FILE*, but will free resources automatically.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;class File_ptr{
  FILE* fp;
public:

  //Constructor that creates File_ptr from FILE*
  File_ptr( FILE* pp ){ fp = pp; }
  
  //Destructor, that closes the file and frees memory
  ~File_ptr(){ if (fp) fclose( fp ) };
  
  //Type conversion operator. It is called every time an object 
  //of File_ptr type needs to be converted to FILE*;
  operator FILE* (){ return fp; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a minimum amount of functions that needed for this wrapper class to work. The &lt;i&gt;use_file&lt;/i&gt; function then will look like that.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;void use_file( const char* fn ){
  File_ptr f = fopen( fn, "w" );
  //using f;
  //file will be closed automatically as soon as f is out of scope
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But actually it is not all yet. You will also need to define a copy constructor and an assign operator in &lt;i&gt;File_ptr&lt;/i&gt;. &lt;a href="http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/CLASSES-PTRS.html" class="external" &gt;Here&lt;/a&gt; is the good explanation, why.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8523906795025417242?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8523906795025417242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/03/pointers-and-memory-handling-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8523906795025417242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8523906795025417242'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/03/pointers-and-memory-handling-in-c.html' title='Pointers and Memory Handling In C++'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6760163685100139</id><published>2010-03-11T11:10:00.018+02:00</published><updated>2010-07-09T14:14:05.094+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Joining a Vector And Splitting String In C++</title><content type='html'>&lt;p&gt;We need these two opposite operations more or less often. As C++ stl does not provide us these functions, we need to write them ourselves.&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;template &amp;lt;class T&amp;gt;
string vector_join( const vector&amp;lt;T&amp;gt;&amp;amp; v, const string&amp;amp; token ){
  ostringstream result;
  for (typename vector&amp;lt;T&amp;gt;::const_iterator i = v.begin(); i != v.end(); i++){
    if (i != v.begin()) result &amp;lt;&amp;lt; token;
    result &amp;lt;&amp;lt; *i;
  }
  return result.str();
}

vector&amp;lt;string&amp;gt; string_split( const string&amp;amp; s, const string&amp;amp; delimiter ){
  vector&amp;lt;string&amp;gt; result;
  string::size_type from = 0;
  string::size_type to = 0;

  while ( to != string::npos ){
    to = s.find( delimiter, from );
    if ( from &amp;lt; s.size() &amp;amp;&amp;amp; from != to ){
      result.push_back( s.substr( from, to - from ) );
    }
    from = to + delimiter.size();
  }
  return result;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The functions produce the following results:&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;string ss[] = { "qwerty", "hello", "world" };
vector&amp;lt;string&amp;gt; v( ss, ss+3 );
vector_join( v, ", ") );//"qwerty, hello, world"

int ii[] = { 111, 222, 333 };
vector&amp;lt;int&amp;gt; vi( ii, ii+3 );
vector_join( vi, "; ") );//"111; 222; 333"

string_split( "qwerty, hello, world", ", " );
//results in [ "qwerty", "hello", "world" ]
string_split( ", , wow, , qwerty, hello, world, ", ", " );
//results in [ "wow", "qwerty", "hello", "world" ]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If we have a &lt;i&gt;space&lt;/i&gt; as delimiter, we can split string more efficient way and even make use of templates too&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;template &amp;lt;class T&amp;gt;
vector&amp;lt;T&amp;gt; string_split( const string&amp; s ){
  vector&amp;lt;T&amp;gt; result;
  istringstream ss(s);
  copy( istream_iterator&amp;lt;T&amp;gt;(ss), istream_iterator&amp;lt;T&amp;gt;(), 
        back_inserter( result ) );
  return result;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the tests:&lt;/p&gt;
&lt;pre&gt;&lt;code class="cpp"&gt;string_split&amp;lt;float&amp;gt;( "11.1 22.2 33.3" );//[ 11.1, 22.2, 33.3 ]
string_split&amp;lt;int&amp;gt;( "111 222 333" );//[ 111, 222, 333 ]&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6760163685100139?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6760163685100139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/03/joining-vector-and-splitting-string-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6760163685100139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6760163685100139'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/03/joining-vector-and-splitting-string-in.html' title='Joining a Vector And Splitting String In C++'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6893112300857452073</id><published>2010-03-02T10:28:00.003+02:00</published><updated>2010-07-09T14:16:49.322+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MsSql'/><title type='text'>Restoring the MSSQL Database</title><content type='html'>&lt;p&gt;Restoring of the database can be done through the database menu, or [I prefer] like that.&lt;/p&gt;
&lt;pre&gt;&lt;code class="sql"&gt;RESTORE DATABASE DatabaseName
FROM DISK = 'C:\Path\To\Backup\File\DatabaseName.bak'
WITH REPLACE&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you get the following error: "Exclusive access could not be obtained  because the database is in use", try to get the list of connected users:&lt;/p&gt;
&lt;pre&gt;&lt;code class="sql"&gt;EXEC SP_WHO2&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Find ones that are connected to DatabaseName and kill them&lt;/p&gt;
&lt;pre&gt;&lt;code class="sql"&gt;KILL [SPID]&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6893112300857452073?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6893112300857452073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/03/restoring-mssql-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6893112300857452073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6893112300857452073'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/03/restoring-mssql-database.html' title='Restoring the MSSQL Database'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2609518826705609730</id><published>2010-02-06T21:26:00.003+02:00</published><updated>2010-07-09T14:20:54.610+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PostgreSql'/><title type='text'>How To Get Last Inserted Row ID In PostgreSQL</title><content type='html'>&lt;p&gt;Imagine we have a test table.&lt;/p&gt;
&lt;pre&gt;&lt;code class="sql"&gt;CREATE TABLE test (id SERIAL, name TEXT);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use the RETURNING statement in the INSERT statement.&lt;/p&gt;
&lt;pre&gt;&lt;code class="sql"&gt;INSERT INTO test (name) VALUES ('My Name') RETURNING id;

 id 
----
  1 

INSERT INTO test (name) VALUES ('My Name 1') RETURNING id;

 id 
----
  2 &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;More info in &lt;a href="http://www.postgresql.org/docs/8.2/static/sql-insert.html" class="external"&gt;Postgres manual.&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2609518826705609730?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2609518826705609730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/02/how-to-get-last-inserted-row-id-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2609518826705609730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2609518826705609730'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/02/how-to-get-last-inserted-row-id-in.html' title='How To Get Last Inserted Row ID In PostgreSQL'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2664457924788312268</id><published>2010-01-23T18:09:00.005+02:00</published><updated>2010-07-09T14:21:19.662+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Remove User List From Ubuntu Karmic Login</title><content type='html'>&lt;p&gt;As I use Ubuntu on my eeePC, I like better typing than using touchpad.&lt;/p&gt;
&lt;p&gt;That would remove user list from login screen and will make you type your username instead of selecting it.&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;sudo -u gdm gconftool-2 --type bool --set /apps/gdm/simple-greeter/disable_user_list 'true'&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2664457924788312268?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2664457924788312268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/01/remove-user-list-from-ubuntu-karmic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2664457924788312268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2664457924788312268'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/01/remove-user-list-from-ubuntu-karmic.html' title='Remove User List From Ubuntu Karmic Login'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8419396793983783410</id><published>2010-01-15T12:21:00.004+02:00</published><updated>2010-07-26T16:11:23.163+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><title type='text'>Silverlight Cross-Domain Http Request Results Into Security Exception</title><content type='html'>&lt;p&gt;That is because cross-domain http requests are restricted in Silverlight. One has to add a crossdomain.xml into web service provider root folder with the following lines.&lt;/p&gt;&lt;pre&gt;&lt;code class="xml"&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"&amp;gt;
&amp;lt;cross-domain-policy&amp;gt;
 &amp;lt;allow-access-from domain="*" /&amp;gt;
&amp;lt;/cross-domain-policy&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For more info see &lt;a class="external" href="http://msdn.microsoft.com/en-us/library/cc645032%28VS.95%29.aspx" &gt;Network Security Access Restrictions in Silverlight&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8419396793983783410?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8419396793983783410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/01/silverlight-cross-domain-http-request.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8419396793983783410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8419396793983783410'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/01/silverlight-cross-domain-http-request.html' title='Silverlight Cross-Domain Http Request Results Into Security Exception'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3536782240755002669</id><published>2010-01-11T13:04:00.003+02:00</published><updated>2010-07-09T14:23:06.721+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MsSql'/><title type='text'>Date (Without Time) In MsSql</title><content type='html'>&lt;p&gt;Should be something like that:&lt;/p&gt;
&lt;pre&gt;&lt;code class="sql"&gt;SELECT dateadd(day, datediff(day, 0, getdate()), 0)&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3536782240755002669?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3536782240755002669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/01/date-without-time-in-mssql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3536782240755002669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3536782240755002669'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/01/date-without-time-in-mssql.html' title='Date (Without Time) In MsSql'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8743455883845714440</id><published>2010-01-07T21:52:00.003+02:00</published><updated>2010-03-11T13:34:53.790+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>C++ Header Files With Classes and Makefile</title><content type='html'>&lt;p&gt;2 good tutorials:&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;a class="external" href="http://www.learncpp.com/cpp-tutorial/89-class-code-and-header-files/"&gt;Class code and header files.&lt;/a&gt;&lt;dt&gt;
&lt;dt&gt;&lt;a class="external" href="http://mrbook.org/tutorials/make/"&gt;Makefile&lt;/a&gt;&lt;/dt&gt;
&lt;/dl&gt;
&lt;p&gt;&lt;b&gt;Updated:&lt;/b&gt; And 1 more &lt;a class="external" href="http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle"&gt;article&lt;/a&gt; about c++ unit test frameworks.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8743455883845714440?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8743455883845714440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2010/01/c-header-files-with-classes-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8743455883845714440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8743455883845714440'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2010/01/c-header-files-with-classes-and.html' title='C++ Header Files With Classes and Makefile'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3673591722949973809</id><published>2009-12-20T11:08:00.004+02:00</published><updated>2010-07-09T14:23:30.742+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='why?'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Date Parsing In C#</title><content type='html'>&lt;pre&gt;&lt;code class="cs"&gt;DateTime.Parse("Dec 13 18:06");//Results in {06.12.2009 13:18:00}&lt;/code&gt;&lt;/pre&gt;
Why?!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3673591722949973809?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3673591722949973809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/12/date-parsing-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3673591722949973809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3673591722949973809'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/12/date-parsing-in-c.html' title='Date Parsing In C#'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8088961610404552789</id><published>2009-12-03T12:21:00.003+02:00</published><updated>2010-03-11T13:39:33.961+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Virtual Desktop Manager For Windows</title><content type='html'>&lt;p&gt;I got too accustomed to multiple desktops on my home Ubuntu computer, that working under Windows with many open programs without ability to share them among several desktops made me too uncomfortable. &lt;a href="http://virtuawin.sourceforge.net/" class="external"&gt;VirtuaWin&lt;/a&gt; - The Virtual Desktop Manager was the solution :). Now I am happy again.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8088961610404552789?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8088961610404552789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/12/virtual-desktop-manager-for-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8088961610404552789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8088961610404552789'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/12/virtual-desktop-manager-for-windows.html' title='Virtual Desktop Manager For Windows'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8550259797637911103</id><published>2009-11-15T00:54:00.008+02:00</published><updated>2010-07-09T14:37:25.862+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Add List To App.Config</title><content type='html'>&lt;p&gt;One can add list and not only a list to App.Config file of the .Net project. That can be done by declaring your own configuration element, say a ProductElement&lt;/p&gt;
&lt;pre&gt;&lt;code class="cs"&gt;class ProductElement : ConfigurationElement
{
  [ConfigurationProperty("name", IsKey=true, IsRequired=true)]
  public string Name
  {
    get { return this["name"]; }
  }

  [ConfigurationProperty("price")]
  public int Price
  {
    get { return Convert.ToInt32(this["price"]); }
  }
}

class ProductElementCollection : ConfigurationElementCollection
{
  protected override ConfigurationElement CreateNewElement()
  {
    return new ProductElement();
  }

  protected override object GetElementKey(ConfigurationElement element)
  {
    return ((ProductElement)element).Name;
  }
}

class ProductConfigurationSection : ConfigurationSection
{
   [ConfigurationProperty("products")]
   public ProductElementCollection Products
   {
      get { return (ProductElementCollection)this["products"]; }
   }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use it in your app.config like that:&lt;/p&gt;
&lt;pre&gt;&lt;code class="xml"&gt;&amp;lt;configuration&amp;gt;
   &amp;lt;configSections&amp;gt;
      &amp;lt;section name="productConfigurationSection"
        type="MyNamespace.ProductConfigurationSection, MyAssembly" 
        requirePermission="false" /&amp;gt;
   &amp;lt;/configSections&amp;gt;
   &amp;lt;productConfigurationSection&amp;gt;
      &amp;lt;products&amp;gt;
         &amp;lt;add name="car" price="750000" /&amp;gt;
         &amp;lt;add name="milk" price="13" /&amp;gt;
      &amp;lt;/products&amp;gt;
   &amp;lt;/productConfigurationSection&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that Name is used as a key, so you cannot create 2 Products with the same name. But you can add more fields to the Product, just mark them accordingly. And from code you can access this section with:&lt;/p&gt;
&lt;pre&gt;&lt;code class="cs"&gt;ProductConfigurationSection section = (ProductConfigurationSection) ConfigurationManager.GetSection("productConfigurationSection");&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8550259797637911103?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8550259797637911103/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/11/add-list-to-appconfig.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8550259797637911103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8550259797637911103'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/11/add-list-to-appconfig.html' title='Add List To App.Config'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1631124968966630803</id><published>2009-10-20T12:05:00.003+03:00</published><updated>2010-03-11T13:48:39.407+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IDE'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>The Most Intelligent Java IDE — Now Free and Open Source</title><content type='html'>&lt;p&gt;Hardly anyone will argue, that IntelliJ IDEA is one of the best IDE for Java and Ruby(Rails). And now it is going to be free! Yes, this title is taken from &lt;a href="http://www.jetbrains.com/idea/nextversion/free_java_ide.html" class="external" target="_blank"&gt;IntelliJ Site&lt;/a&gt;. Next version of the product will be free, and it can already be downloaded from the coerced link.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1631124968966630803?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1631124968966630803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/10/most-intelligent-java-ide-now-free-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1631124968966630803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1631124968966630803'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/10/most-intelligent-java-ide-now-free-and.html' title='The Most Intelligent Java IDE — Now Free and Open Source'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-7636763162392778005</id><published>2009-09-16T11:15:00.002+03:00</published><updated>2010-07-09T14:38:21.137+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='audio'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Convert Different Audio In Command Line in Ubuntu</title><content type='html'>&lt;p&gt;Converting different audio formats in Ubuntu is quite an easy task. Just start Soundconverter, or first install it, if you don't have.&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;sudo apt-get install soundconverter&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But I needed to do it in command line. Soundconverter can do it either. (What a good boy!) But you just need to know the mime-type of the output file (simply adding the desired suffix doesn't work). For example, to convert "my_favourite mp3" to wav you can use:&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;soundconverter -b -m audio/x-wav -s .wav my_favourite.mp3&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See the &lt;a href="http://www.feedforall.com/mime-types.htm" class="external"&gt;full list of mime types&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For the available options see&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;soundconverter -h&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;man soundconverter&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-7636763162392778005?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/7636763162392778005/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/09/convert-different-audio-in-command-line.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7636763162392778005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7636763162392778005'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/09/convert-different-audio-in-command-line.html' title='Convert Different Audio In Command Line in Ubuntu'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-7015190723637130870</id><published>2009-08-02T13:15:00.000+03:00</published><updated>2010-08-02T13:30:11.800+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Shoes'/><title type='text'>Ruby Shoes</title><content type='html'>&lt;p&gt;I wanted to try ruby Shoes already long ago, but just didn't know what to start with. Until I found a &lt;a class="external" href="http://quiteuseful.co.uk"&gt;quiteuseful&lt;/a&gt; article about &lt;a class="external" href="http://quiteuseful.co.uk/post/94473551/lets-make-a-game-wrap-up"&gt;making a game&lt;/a&gt; on ruby shoes. I tried it and it was unexpectedly easy. Here are some my subjective thoughts about it.&lt;/p&gt;
&lt;p&gt;Good things:&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;It is very easy to study.&lt;/dt&gt;
&lt;dd&gt;One can begin writing using shoes quite quickly and straightforward. No big manuals or hardly understandable api and howtos.&lt;/dd&gt;
&lt;dt&gt;It is cute. :)&lt;/dt&gt;
&lt;dd&gt;Yes, I really liked it. Different objects are created very easy, such as:
&lt;pre&gt;&lt;code class="ruby"&gt;Shoes.app { button("Click me!") { alert("Good job.") } }&lt;/code&gt;&lt;/pre&gt;
You also can draw with provided &lt;i&gt;rect&lt;/i&gt;, &lt;i&gt;oval&lt;/i&gt; or even &lt;i&gt;arrow&lt;/i&gt; methods or import an image as a background. Motion ability is also provided:
&lt;pre&gt;&lt;code class="ruby"&gt;Shoes.app do #A star that moves after the mouse pointer.
  @shape = star :points =&gt; 5
  motion do |left, top|
    @shape.move left, top
  end
end&lt;/code&gt;&lt;/pre&gt;
&lt;/dd&gt;
&lt;/dl&gt;
Unfortunately there were also some disadvantages:
&lt;dl&gt;
&lt;dt&gt;The whole Shoes application should be in Shoes.app block.&lt;/dt&gt;
&lt;dd&gt;Seem to me to be a little bit uncomfortable.&lt;/dd&gt;
&lt;dt&gt;You have to pass everywhere app variable that denotes the Shoes application.&lt;/dt&gt;
&lt;dd&gt;Well, not just everywhere... But if you create your own class, which objects have to be drawn you also have to pass the application variable, or make it global, which is not really good pattern.
&lt;pre&gt;&lt;code class="ruby"&gt;class RedRect

  def initialize( app )
    app.fill red
    app.rect :left =&gt; 10, :top =&gt; 10, :width =&gt; 40 
  end
end

Shoes.app do
  RedRect.new( self )
end
&lt;/code&gt;&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;Pity, but it is slow.&lt;/dt&gt;
&lt;dd&gt;The resulting snake in the game responds in about 2 seconds. It is a long period of time, especially on higher levels with higher speed.&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;In conclusion the authors' words about Shoes are right:"Shoes is a tiny graphics toolkit, designed for beginners". It can be used to create quickly a small application, where speed is not essential.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-7015190723637130870?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/7015190723637130870/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/05/ruby-shoes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7015190723637130870'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7015190723637130870'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/05/ruby-shoes.html' title='Ruby Shoes'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-5771189587561646860</id><published>2009-07-31T10:42:00.006+03:00</published><updated>2010-07-09T14:39:35.130+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><title type='text'>Access DOM Element Within IFrame</title><content type='html'>&lt;p&gt;Suppose we have a html page with frame or iframe in it and we need to get an element in it. Simple&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;document.getElementById("myElement");&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;will not find it, as it is searched only in the main page, where the frame is set.
What we should do, is to find the frame first and then look for needed element in the right frame.&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;frame = document.getElementById("myFrame"); 
frame.contentWindow.getElementById("myElement");&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-5771189587561646860?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/5771189587561646860/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/07/access-dom-element-within-iframe.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5771189587561646860'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5771189587561646860'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/07/access-dom-element-within-iframe.html' title='Access DOM Element Within IFrame'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4562566573058521701</id><published>2009-07-09T14:41:00.000+03:00</published><updated>2010-07-09T14:43:08.316+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySql'/><category scheme='http://www.blogger.com/atom/ns#' term='MsSql'/><category scheme='http://www.blogger.com/atom/ns#' term='PostgreSql'/><title type='text'>Concatenate Strings On Group By In Sql</title><content type='html'>&lt;p&gt;Imagine we have the following table.&lt;/p&gt;
&lt;pre&gt;&lt;code class="sql"&gt;CREATE TABLE MyTable (id int, name varchar, value int);

INSERT INTO MyTable (id,name,value) VALUES (1, 'Hello', 4);
INSERT INTO MyTable (id,name,value) VALUES (1, 'World', 8);
INSERT INTO MyTable (id,name,value) VALUES (5, 'Great!', 9);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result we would like to acquire is:&lt;/p&gt;
&lt;pre&gt;| id |   name_values    |
+----+------------------+
|  1 | Hello:4; World:8 |
|  5 | Great!:9         |&lt;/pre&gt;
&lt;p&gt;Names and values are concatenated into strings and grouped by id. We need an aggregate function, that concatenates strings for that. Here are some solutions for different sql databases.&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;MySql&lt;/dt&gt;&lt;dd&gt;This case is most easy one. Lucky users already have the &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat" class="external"&gt;GROUP_CONCAT(expr)&lt;/a&gt; function. This query should give the answer.
&lt;pre&gt;&lt;code class="sql"&gt;SELECT id, GROUP_CONCAT(name + ':' + value SEPARATOR '; ') AS name_values FROM MyTable GROUP BY id;&lt;/code&gt;&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;PostgreSql&lt;/dt&gt;&lt;dd&gt;The solution here is a bit more difficult, but nevertheless easy enough. We need to create our own aggregate function and use it in our query.
&lt;pre&gt;&lt;code class="sql"&gt;CREATE AGGREGATE aggr_textcat(
  basetype    = text,
  sfunc       = textcat,
  stype       = text,
  initcond    = ''
);

SELECT id, substring(aggr_textcat(', ' || name || ':' || value) from 2) AS name_values FROM MyTable GROUP BY id;&lt;/code&gt;&lt;/pre&gt;
Here we used already existing function to concatenate text fields &lt;a href="http://www.postgresql.org/docs/8.3/static/functions-string.html" class="external"&gt;textcat&lt;/a&gt;, but we could write our own.
&lt;/dd&gt;
&lt;dt&gt;MsSql&lt;/dt&gt;
&lt;dd&gt;Since version 2005 it became also possible to write your own aggregate function in MsSql, but here I provide another solution using inner select and xml path.
&lt;pre&gt;&lt;code class="sql"&gt;SELECT id, SUBSTRING(SELECT '; ' + name + ':' + CAST(value AS varchar(MAX)) 
FROM MyTable WHERE (id = Results.id) FOR XML PATH ('')),3,9999) AS name_values
FROM MyTable Results
GROUP BY id&lt;/code&gt;&lt;/pre&gt;
&lt;/dd&gt;
&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4562566573058521701?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4562566573058521701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/06/concatenate-strings-on-group-by-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4562566573058521701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4562566573058521701'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/06/concatenate-strings-on-group-by-in-sql.html' title='Concatenate Strings On Group By In Sql'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-7373920241474464287</id><published>2009-06-24T20:48:00.004+03:00</published><updated>2010-08-02T13:09:27.536+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PostgreSql'/><title type='text'>Insert Large Amount Of Rows Into PostgreSQL</title><content type='html'>Inserting large amount of data into postgres database may take a lot of time, if you use &lt;a href="http://www.postgresql.org/docs/8.3/static/dml-insert.html" class="external"&gt;INSERT&lt;/a&gt; command. Consider better &lt;a href="http://www.postgresql.org/docs/8.3/static/sql-copy.html" class="external"&gt;COPY&lt;/a&gt; command, though it is not so flexible.
&lt;pre&gt;&lt;code class="sql"&gt;COPY my_table_name(int_column, string_column, bytea_column) from stdin;
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;THISisSTRING&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;\\001\\017\\044
2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;THISisSTRING2&amp;nbsp;&amp;nbsp;&amp;nbsp;\\001\\017\\062
3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;THISisSTRING3&amp;nbsp;&amp;nbsp;&amp;nbsp;\\001\\017\\102&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The default delimiter is tab (\t).&lt;/p&gt;
&lt;p&gt;To acquire the right format in 1 particular case, you can fill database with some values using INSERT command and dump database with pg_dump. The resulting file will contain the right COPY syntax.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-7373920241474464287?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/7373920241474464287/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/06/insert-large-amount-of-rows-into.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7373920241474464287'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7373920241474464287'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/06/insert-large-amount-of-rows-into.html' title='Insert Large Amount Of Rows Into PostgreSQL'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2182155434875251869</id><published>2009-06-22T12:50:00.004+03:00</published><updated>2010-08-02T13:11:11.965+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><title type='text'>Ajax With InnerHTML()</title><content type='html'>&lt;p&gt;InnerHTML is not a standard, but it is more useful comparing to working with DOM with such functions as createElement and/or appendChild. But there is a problem with it: if you need further to handle the new added data (to refer new elements, to change/add their attributes), innerHTML is not good at all, as innerHTML simply visually adds new elements, but it does not really insert them in the DOM structure of the document. Attempting to do a document.getElementById() on a tag inside of code that was added using innerHTML just doesn't work. At least it didn't work for me in Firefox 3.&lt;/p&gt;
&lt;p&gt;The folowing code can be accepted as the workaround.&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;var newDiv = document.createElement("div");//create new div
newDiv.innerHTML = xhr.responseText;//add response into new div
var container = document.getElementById("container");//find place where the response should be placed to
container.parentNode.insertBefore(newDiv, container);//add new div before the container
newDiv.parentNode.removeChild(container);//remove container&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This way we get the same resulting document, but we can further work with DOM.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2182155434875251869?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2182155434875251869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/06/ajax-with-innerhtml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2182155434875251869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2182155434875251869'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/06/ajax-with-innerhtml.html' title='Ajax With InnerHTML()'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-7458124234409219525</id><published>2009-06-12T17:25:00.000+03:00</published><updated>2009-06-12T17:25:09.797+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='myself'/><title type='text'>Master Degree Acquired</title><content type='html'>Yes, at last. Now I am the Master of the Information Technology :) Sounds good!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-7458124234409219525?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/7458124234409219525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/06/master-degree-acquired.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7458124234409219525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7458124234409219525'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/06/master-degree-acquired.html' title='Master Degree Acquired'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2193462496851076855</id><published>2009-06-10T17:16:00.001+03:00</published><updated>2010-03-11T13:49:15.564+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Excel'/><title type='text'>Microsoft Excel 2007 Problems</title><content type='html'>It is a must read, if you want to know what problems you may encounter, when exporting to excel 2007: "&lt;a class="external" href="http://www.codeproject.com/KB/XML/ooxml_is_defective.aspx?fid=453420&amp;df=90&amp;mpp=25&amp;noise=3&amp;sort=Position&amp;view=Quick&amp;fr=26"&gt;Microsoft Office XML formats ? Defective by design&lt;/a&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2193462496851076855?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2193462496851076855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/06/microsoft-excel-2007-problems.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2193462496851076855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2193462496851076855'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/06/microsoft-excel-2007-problems.html' title='Microsoft Excel 2007 Problems'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-5355788565992592633</id><published>2009-06-07T19:18:00.011+03:00</published><updated>2010-08-02T13:13:58.785+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Array To String</title><content type='html'>&lt;p&gt;Oh, how I hate &lt;a class="external" href="http://msdn.microsoft.com/en-us/library/57a79xd0.aspx"&gt;String.join(string, string[])&lt;/a&gt; in mscorlib. And it is because of string[] argument. Why couldn't they make it accept array of objects and, before joining, cast every object with ToString() method?&lt;/p&gt;
&lt;p&gt;Had to make it myself:&lt;/p&gt;
&lt;pre&gt;&lt;code class="c-sharp"&gt;public string ListJoin&amp;lt;T&amp;gt;(string separator, T[] objs)//C# v3
{
  return string.Join(separator, Array.ConvertAll(objs, item =&gt; item.ToString()));
}

public string ListJoin&amp;lt;T&amp;gt;(string separator, T[] objs)//C# v2
{
  return string.Join(separator, Array.ConvertAll&amp;lt;T,string&amp;gt;(value, new Converter&amp;lt;T,string&amp;gt;(delegate(T i){return i.ToString();})));
}
&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-5355788565992592633?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/5355788565992592633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/06/stringjoinstring-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5355788565992592633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5355788565992592633'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/06/stringjoinstring-string.html' title='Array To String'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8695368094362829554</id><published>2009-05-14T10:56:00.016+03:00</published><updated>2010-08-02T13:17:01.268+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Excel'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Export String Values To Excel 2007</title><content type='html'>&lt;p&gt;If you encounter a following error, while exporting to Excel 2007 (.xlsx)&lt;/p&gt;
&lt;code&gt;Errors were detected in file MyFileName.xlsx.
Repaired Records: Cell information from /xl/worksheets/sheet1.xml part&lt;/code&gt;
&lt;p&gt;then, probably, you are exporting string values in wrong format. The right structure in this case is
&lt;pre&gt;&lt;code class="xml"&gt;&amp;lt;sheetData&amp;gt;
  &amp;lt;row&amp;gt;
   &amp;lt;c&amp;gt;
     &amp;lt;v&amp;gt;99999&amp;lt;/v&amp;gt;
   &amp;lt;/c&amp;gt;
   &amp;lt;c t="inlineStr"&amp;gt;
     &amp;lt;is&amp;gt;
       &amp;lt;t&amp;gt;My Text&amp;lt;/t&amp;gt;
     &amp;lt;/is&amp;gt;
   &amp;lt;/c&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/sheetData&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note, that there is no &amp;lt;v&amp;gt; tag in &amp;lt;c&amp;gt; as it should be with numbers. Instead you have to make an &lt;i&gt;inline string&lt;/i&gt; (&amp;lt;is&amp;gt;) tag and put &lt;i&gt;text&lt;/i&gt; (&amp;lt;t&amp;gt;) tag with needed text in it. Do not forget to add the &lt;i&gt;t="inlineStr"&lt;/i&gt; attribute to &amp;lt;c&amp;gt; tag.&lt;/p&gt;
&lt;p&gt;More info can be found &lt;a class="external" href="http://developer.marklogic.com/columns/smallchanges/2007-12-04.xqy"&gt;developer:network&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8695368094362829554?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8695368094362829554/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/05/export-string-values-to-excel-2007.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8695368094362829554'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8695368094362829554'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/05/export-string-values-to-excel-2007.html' title='Export String Values To Excel 2007'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4764811418196105278</id><published>2009-04-27T16:51:00.006+03:00</published><updated>2010-08-02T13:18:04.158+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Method with arbitrary number of parameters in C#</title><content type='html'>&lt;p&gt;One can also create a method with variable number of parameters in C#. It is needed, for example, when you have such logic, where you need to take value from one place, if it is not null, or from the other, or from the third place, if the first two are nulls, and so on. This can help:&lt;/p&gt;

&lt;pre&gt;&lt;code class="c-sharp"&gt;public static T FirstNotNull&amp;lt;T&amp;gt;(params Nullable&amp;lt;T&amp;gt;[] objects) where T : struct
{
  foreach (Nullable&amp;lt;T&amp;gt; obj in objects)
    if (obj.HasValue) return obj.Value;
  return default(T);
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Reserved word &lt;i&gt;params&lt;/i&gt; shows, that we deal with an array of parameters. This parameter can only be the last one in a function. You can put other types of parameters before, but no after.&lt;/p&gt;
&lt;p&gt;The function can be called like that:&lt;/p&gt;
&lt;pre&gt;&lt;code class="c-sharp"&gt;HelperClass.FirstNotNull&amp;lt;int&amp;gt;(firstValue, secondValue, thirdValue, fourthValue);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first not null value of these four is returned, or default value of the type, if all are nulls.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4764811418196105278?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4764811418196105278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/04/method-with-arbitrary-number-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4764811418196105278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4764811418196105278'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/04/method-with-arbitrary-number-of.html' title='Method with arbitrary number of parameters in C#'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3441795589503472329</id><published>2009-03-31T12:43:00.005+03:00</published><updated>2010-08-02T13:18:39.377+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>System.Reflection To the Rescue</title><content type='html'>&lt;p&gt;Many people ask if there is a possibility to call a method, if we have its name as string. Actually, it is very useful feature. Imagine we have an Object with several properties which represent the same thing, but in different languages.&lt;/p&gt;
&lt;pre&gt;&lt;code class="c-sharp"&gt;class MyClass
{
    public string State_EN;
    public string State_DE;
    public string State_RU;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We want to show the state of MyClass object in proper language. We create a method for that&lt;/p&gt;
&lt;pre&gt;&lt;code class="c-sharp"&gt;public string State(string language)
{
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Language is the 2-letter code representation of language ("EN", "DE", "RU"...). So what should be inside the State method? Solutions with "if" and "switch" are not good - if you have to add more languages, you must rewrite the State method. But we are lazy and don't want to do that. What we need here is System.Reflection.
&lt;pre&gt;&lt;code class="c-sharp"&gt;using System.Reflection;
[...]
public string State(string language)
{
    PropertyInfo property = typeof(MyClass).GetProperty("State_" + language);//find the property
    if (property != null)
        return (string)property.GetValue(this, null);//get value of the property
    return null;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same way we can search for method, if we know the method's name (with GetMethod instead of GetProperty). And call it with "Invoke" and proper parameters.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3441795589503472329?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3441795589503472329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/03/systemreflection-to-rescue.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3441795589503472329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3441795589503472329'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/03/systemreflection-to-rescue.html' title='System.Reflection To the Rescue'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4352392089429377166</id><published>2009-03-18T12:41:00.009+02:00</published><updated>2010-08-02T13:24:59.784+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Using Generics With System.Nullable&lt;T&gt;</title><content type='html'>&lt;p&gt;When we have a Nullable type value and we want to assign it to some control, then we need to check if is not null first.&lt;/p&gt;

&lt;pre&gt;&lt;code class="c-sharp"&gt;SomeLabel.Text = object.MyProperty.HasValue ? object.MyProperty.Value : String.Empty;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But if we have many nullable properties? I don't want to copy/paste this check on every line. So we need a method, that checks for nulls. But I also don't want several methods for every type. So we need to use generics.&lt;/p&gt;

&lt;p&gt;I created some methods for myself&lt;/p&gt;

&lt;pre&gt;&lt;code class="c-sharp"&gt;public static string ValueOrEmptyString&amp;lt;T&amp;gt;(Nullable&amp;lt;T&amp;gt; obj) where T : struct
{
  return obj.HasValue ? obj.Value.ToString() : "";
}

public static T ValueOrDefault&amp;lt;T&amp;gt;(Nullable&amp;lt;T&amp;gt; obj, T defaultValue) where T : struct
{
  return obj.HasValue ? obj.Value : defaultValue;
}

public static T ValueOrDefault&amp;lt;T&amp;gt;(Nullable&amp;lt;T&amp;gt; obj) where T : struct
{
  return obj.HasValue ? obj.Value : default(T);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;"where T : struct" - is needed for compiler to understand that this method is allowed only for types that belong to System.ValueType.&lt;/p&gt;

&lt;p&gt;I can use these methods like that&lt;/p&gt;
&lt;pre&gt;&lt;code class="c-sharp"&gt;SomeLabel.Text = ValueOrEmptyString&amp;lt;int&amp;gt;( object.MyIntProperty );
SomeDateTimeControl.Date = ValueOrDefault&amp;lt;DateTime&amp;gt;( object.MyDateTimeProperty );
SomeReferenceControl.SelectedObjecId = ValueOrDefault&amp;lt;int&amp;gt;( object.MyIntProperty, -1 );
&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4352392089429377166?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4352392089429377166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/03/using-generics-with-systemnullable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4352392089429377166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4352392089429377166'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/03/using-generics-with-systemnullable.html' title='Using Generics With System.Nullable&amp;lt;T&amp;gt;'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1082424743774753007</id><published>2009-02-18T12:12:00.009+02:00</published><updated>2011-04-21T09:54:16.522+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='audio'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>How To Split Audio CD Image (.flac) Into Several Tracs In Ubuntu</title><content type='html'>&lt;pre&gt;&lt;code class="bash"&gt;$ sudo apt-get install cuetools shntool flac #install needed tools
$ cuebreakpoints sample.cue | shnsplit -o flac sample.flac #read breakpoints from cue and give them to splitter
$ cuetag sample.cue split-track*.flac #add tags to newly created files
&lt;/code&gt;&lt;/pre&gt;
More info is &lt;a class="external" target="_blank" href="http://stillstup.blogspot.com/2008/07/split-lossless-audio-ape-flac-wv-wav-by.html"&gt;there&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1082424743774753007?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1082424743774753007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/02/how-to-split-audio-cd-image-flac-into.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1082424743774753007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1082424743774753007'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/02/how-to-split-audio-cd-image-flac-into.html' title='How To Split Audio CD Image (.flac) Into Several Tracs In Ubuntu'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8433489887869185565</id><published>2009-02-13T15:29:00.009+02:00</published><updated>2010-03-11T13:49:45.588+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Eee'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Eee Control Tray For Ubuntu</title><content type='html'>&lt;a class="external" href="http://greg.geekmind.org/eee-control"&gt;eee-control-tray&lt;/a&gt; is a package that one can &lt;a class="external" href="http://greg.geekmind.org/eee-control/#install"&gt;install&lt;/a&gt; on Ubuntu (or other Debian system) to obtain an easy interface to configure Fn shortcuts and other useful options.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8433489887869185565?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8433489887869185565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2009/02/eee-control-tray-for-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8433489887869185565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8433489887869185565'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2009/02/eee-control-tray-for-ubuntu.html' title='Eee Control Tray For Ubuntu'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2860805971339346673</id><published>2008-11-12T11:44:00.136+02:00</published><updated>2009-08-02T22:10:22.439+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Fourier'/><category scheme='http://www.blogger.com/atom/ns#' term='audio'/><title type='text'>Comparing 2 Audio (*.wav) Files</title><content type='html'>&lt;p&gt;We already know &lt;a href="http://dracoater.blogspot.com/2008/11/comparing-2-audio-wav-files.html"&gt;the structure of wave file&lt;/a&gt; and thus we are able to read it byte by byte (actually we need to read the data chunk sample by sample). Now the next move is to get "fingerprints" from our files.&lt;/p&gt;
&lt;h2&gt;Fingerprint&lt;/h2&gt;
&lt;p&gt;A fingerprint can uniquely and compactly represent an audio file. It consists of several points of local energy maximum in audio spectral density. How the spectral density varies in time can be shown by a &lt;a class="external" target="_blank" href="http://http://en.wikipedia.org/wiki/Spectrogram"&gt;spectrogram&lt;/a&gt;. The most common format is a graph with two geometric dimensions: the horizontal axis represents time, the vertical axis is frequency; a third dimension indicating the amplitude of a particular frequency at a particular time is represented by the intensity or colour of each point in the image, e.g., the brighter the shade, the more energy is contained in the time-frequency point. The only thing we need is a amount of acoustic energy in predefined frequency and time.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://lh5.ggpht.com/_13GxZrI8up4/SZPZsMFhefI/AAAAAAAACwE/rw_2DOt4NZ8/s800/02%20-%20West%20End%20Girls.mp3.part.wav.png" style="margin:0 auto;display:block" /&gt;
&lt;h5 style="text-align:center;"&gt;A spectrogram of 30 seconds of the part of Pet Shop Boys "West End Girls" song starting from 1:00&lt;/h5&gt;
&lt;/p&gt;

&lt;p&gt;Spectrograms can be obtained by &lt;a class="external" target="_blank" href="http://en.wikipedia.org/wiki/Short-time_Fourier_transform"&gt;Short Time Fourier Transform&lt;/a&gt;. The audio samples are grouped into analysis time windows (preferably overlapping) w&lt;sub&gt;i&lt;/sub&gt; of equal length N, with w&lt;sub&gt;i&lt;/sub&gt; denoting the i-th window. For each window the Fourier transform is calculated, giving a complex vector v&lt;sub&gt;i&lt;/sub&gt; = STFT(w&lt;sub&gt;i&lt;/sub&gt;) of the same length as the window. Because in this case the input given to the Fourier transform always are vectors of real numbers, the output complex vectors obey the symmetry:&lt;/p&gt;
&lt;p&gt;v&lt;sub&gt;i&lt;/sub&gt;[q] == -v&lt;sub&gt;i&lt;/sub&gt;[N-q+1]&lt;/p&gt;
&lt;p&gt;So the complete information is contained in the first N/2 components of the complex vector v&lt;sub&gt;i&lt;/sub&gt;.&lt;/p&gt;
&lt;p&gt;The Fourier transform decomposes the signal given by the samples inside each input window in terms of sine waves of discrete frequencies. These frequencies are integer multiples of the fundamental frequency which is determined by the window length N and the sampling rate S of the waveform representation. The frequency F&lt;sub&gt;k&lt;/sub&gt; for a particular index k in the complex vector may be calculated by using the following formula:&lt;/p&gt;
&lt;p&gt;F&lt;sub&gt;k&lt;/sub&gt; = k * S / N , where k = 0, ... ,N/2&lt;/p&gt;
&lt;p&gt;The first frequency F&lt;sub&gt;0&lt;/sub&gt; is always zero. If we have a sampling rate of 44100 Hz and a window length of 1024 samples, the base frequency F&lt;sub&gt;1&lt;/sub&gt; is 43.0664 Hz and the maximum frequency F&lt;sub&gt;512&lt;/sub&gt; is the Nyquist rate 22050 Hz.&lt;/p&gt;
&lt;p&gt;Then we need the absolute value for each component of v&lt;sub&gt;k&lt;/sub&gt; to get a measure of how strongly a discrete frequency F&lt;sub&gt;k&lt;/sub&gt; is present in the decomposition of the i-th window of audio file. This data can then be used for plotting the spectrogram. When the spectrogram is plotted the fingerprint points are chosen to be points that are local maximum within regions of fixed size
surrounding the point. Larger region size leads to fewer but possibly more significant points. The resulting features are saved as pairs of integer numbers (i, k) with i being the window index and k being the frequency index.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2860805971339346673?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2860805971339346673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/11/comparing-2-audio-wav-files_12.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2860805971339346673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2860805971339346673'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/11/comparing-2-audio-wav-files_12.html' title='Comparing 2 Audio (*.wav) Files'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_13GxZrI8up4/SZPZsMFhefI/AAAAAAAACwE/rw_2DOt4NZ8/s72-c/02%20-%20West%20End%20Girls.mp3.part.wav.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-2251246862189473582</id><published>2008-11-07T10:43:00.038+02:00</published><updated>2009-08-02T22:09:26.848+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='wav'/><title type='text'>Structure Of *.wav Audio Files</title><content type='html'>&lt;p&gt;Wave file structure is very simple. The structure can be divided into 3 parts (chunks).&lt;/p&gt;&lt;p&gt;First chunk:
The first 4 bytes should be "RIFF". Then come 4 bytes, which indicate the size of file. Then comes "WAVE".&lt;/p&gt;&lt;p&gt;Second chunk:
It starts with "fmt ". Then come 4 bytes showing the length of "fmt " chunk. Then come audio format, number of channels, sample rate, Byterate, Block align and bits ber sample.&lt;/p&gt;&lt;p&gt;Third chunk:
It is the audio data itself. As always 4 first bytes - name of the chunk. 4 bytes after that - the length of the chunk in bytes. After that come samples itself. 2 * number_of_channels bytes each sample.&lt;/p&gt;&lt;p&gt;There can be also other chunks between the first and the third, but they are really not widely used. If you got interested in it, a very good article about &lt;a href="http://www.sonicspot.com/guide/wavefiles.html" target="_blank" class="external"&gt;"Wave file format" is on The Sonic Spot&lt;/a&gt;.&lt;/p&gt;
&lt;img style="margin:0 auto;display:block;" src="http://lh5.ggpht.com/_13GxZrI8up4/SRhdxAMo8iI/AAAAAAAACuc/A_7hUVsEDPg/s800/WAVE_file_sound_data.png" /&gt;
&lt;p&gt;So we have here an example. We see the first chunk (purple). It shows the length of the file - 0x(00 00 08 24) = 0x824 = 2084&lt;/p&gt;&lt;p class="warning"&gt;Bytes should be read in reverse direction. First read byte has the smallest rank!&lt;/p&gt;&lt;p&gt;You can check yourself: left channel sample #5 = 0xE734 and right one is 0xA623.&lt;/p&gt;&lt;br /&gt;
&lt;a href="http://dracoater.blogspot.com/2008/11/comparing-2-audio-wav-files_12.html"&gt;Continued there...&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-2251246862189473582?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/2251246862189473582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/11/comparing-2-audio-wav-files.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2251246862189473582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/2251246862189473582'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/11/comparing-2-audio-wav-files.html' title='Structure Of *.wav Audio Files'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_13GxZrI8up4/SRhdxAMo8iI/AAAAAAAACuc/A_7hUVsEDPg/s72-c/WAVE_file_sound_data.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1998714765239626549</id><published>2008-11-07T10:42:00.001+02:00</published><updated>2010-03-11T13:38:26.414+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='blog'/><title type='text'>Going to English</title><content type='html'>I decided to continue writing here in English. So I can be read by much more audience. I hope my English is as good as my native language. Will see if it works so. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1998714765239626549?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1998714765239626549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/11/going-to-english.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1998714765239626549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1998714765239626549'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/11/going-to-english.html' title='Going to English'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-5673373153943079007</id><published>2008-09-03T16:11:00.022+03:00</published><updated>2010-03-11T13:49:45.589+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Eee'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Install Ubuntu 8.04 on Asus Eee PC 1000h</title><content type='html'>Приобрёл себе Asus Eee Pc 1000H. Установленный там Xandros что-то не очень вдохновил, поэтому решил поставить туда свою любимую Ubuntu. Что для этого нужно было сделать...  &lt;h2&gt;Создание загрузочной USB и установка Ubuntu.&lt;/h2&gt;&lt;p&gt;Об &lt;a class="external" href="https://help.ubuntu.com/community/Installation/FromUSBStick"&gt;создании загрузочной флэшки&lt;/a&gt; очень хорошо написано на официальном сайте Ubuntu. Я выбрал вариант с UNetbootin.&lt;/p&gt;&lt;p&gt;Загрузка и установка проблем вызвать не должна, поэтому детальное описание опускаю.&lt;/p&gt;&lt;h2&gt;После установки&lt;/h2&gt;&lt;p&gt;Не работает сеть (ни ethernet, ни wifi), некоторые комбинации клавиш (Fn+F2, Fn+F7, Fn+F8, Fn+F10/F11/F12 ), вебкамера.&lt;/p&gt;&lt;h2&gt;Настройка сети&lt;/h2&gt;&lt;p&gt;Самый простой способ на мой взгляд - это &lt;a class="external" href="http://www.array.org/ubuntu/setup901.html"&gt;установка неофициального специального Ubuntu kernel&lt;/a&gt;, оптимизированного под Eee Pc.&lt;/p&gt;
&lt;h2&gt;Shortcuts&lt;/h2&gt;&lt;p&gt;Шорткаты устанавливаются благодаря &lt;a class="external" href="http://forum.eeeuser.com"&gt;http://forum.eeeuser.com&lt;/a&gt; и его пользователю &lt;a class="external" href="http://forum.eeeuser.com/profile.php?id=36434"&gt;elmurato&lt;/a&gt;. Нужно &lt;a class="external" href="http://forum.eeeuser.com/viewtopic.php?id=39341&amp;p=1"&gt;скачать его скрипты и установить&lt;/a&gt;. К сожалению шорткаты начинают работать только после логина. Так что если вам надо отключить звук во время загрузки, у вас это получится только вставив наушники.&lt;/p&gt;
&lt;h2&gt;WebCam&lt;/h2&gt;&lt;p&gt;BIOS. Onboard devices. WebCam Enabled.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-5673373153943079007?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/5673373153943079007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/09/install-ubuntu-804-on-asus-eee-pc-1000h.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5673373153943079007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5673373153943079007'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/09/install-ubuntu-804-on-asus-eee-pc-1000h.html' title='Install Ubuntu 8.04 on Asus Eee PC 1000h'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-3769007551629711428</id><published>2008-07-15T19:24:00.049+03:00</published><updated>2010-03-11T13:46:56.177+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Linq'/><title type='text'>Первые впечатления</title><content type='html'>&lt;p&gt;Итак, делюсь первыпи впечатлениями, как ощущения после перехода с Ruby на C#. Пока всё, с чем я столкнулся, это неудобства:&lt;/p&gt;

&lt;dl&gt;
&lt;dt&gt;Null class.&lt;/dt&gt;
&lt;dd&gt;Отсутствие null как объекта. Затрудняет жизнь многочисленными провернками на null. Паттерн introduce null object не особо спасает. Писать для каждого класса нулевой объект не радует. Можно ли реализовать 1 общий класс, от которого всё наследуется?&lt;/dd&gt;
&lt;dt&gt;System.Linq библиотека&lt;/dt&gt;
&lt;dd&gt;Вроде бы удобная вещь, но! Она была нагло &lt;del&gt;спи&lt;/del&gt;слизана с ruby, причём сделано это очень криво. Зачем-то нужно было менять названия методов. Плюс были портированы не 1 в 1. В результате имеем:&lt;br/&gt;
&lt;table border="1"&gt;
&lt;thead&gt;
  &lt;tr&gt;&lt;th colspan="2" align="center"&gt;Method alternatives&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;&lt;th align="center"&gt;Ruby&lt;/th&gt;&lt;th align="center"&gt;C#&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;array.collect&lt;/td&gt;&lt;td&gt;array.select&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;array.select&lt;/td&gt;&lt;td&gt;array.Where&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;array.detect ( = array.select.first )&lt;/td&gt;&lt;td&gt;array.first&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;array.join( token )&lt;/td&gt;&lt;td&gt;String.join(array, token)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
Как видим, join метод стал вдруг методом String класса.
&lt;/dd&gt;
&lt;dt&gt;Много лишних слов&lt;/dt&gt;
&lt;dd&gt;public overrride static void methodName() vs. def self.method_name&lt;/dd&gt;
&lt;dt&gt;Консоль&lt;/dt&gt;
&lt;dd&gt;Отсутствие консоли, где можно быстренько потестить какой-нибудь метод.&lt;/dd&gt;
&lt;/dl&gt;

&lt;p&gt;Или я просто предвзято отношусь к C# и Microsoft?&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-3769007551629711428?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/3769007551629711428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/07/blog-post_15.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3769007551629711428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/3769007551629711428'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/07/blog-post_15.html' title='Первые впечатления'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-7948221916538864700</id><published>2008-07-11T16:04:00.036+03:00</published><updated>2009-08-02T21:58:37.439+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='myself'/><title type='text'>Моё рабочее место</title><content type='html'>&lt;p&gt;Так как недавно только сменил работу, и в памяти ещё осталось прошлое рабочее место, то напишу про оба: прошлое и настоящее.&lt;/p&gt;

&lt;dl&gt;
 &lt;dt&gt;Прошлое:&lt;/dt&gt;
 &lt;dd&gt;Программировал на ruby on rails. Использовал:
   &lt;dl&gt;
     &lt;dt&gt;ОС: Ubuntu.&lt;/dt&gt;
     &lt;dd&gt;С тех пор, как я пересел на неё, прошло уже 4 года (4.10 была первая версия, выпущена соответственно в октябре 2004 года). Понравилась с первого взгляда. Теперь её использую повсюду.&lt;/dd&gt;
     &lt;dt&gt;Программы:&lt;/dt&gt;
     &lt;dd&gt;
       &lt;dl&gt;
         &lt;dt&gt;Jedit&lt;/dt&gt;&lt;dt&gt;
         &lt;/dt&gt;&lt;dd&gt;Просто лучший редактор для программирования. Главное уметь пользваться и правильно настроить плагины. И, конечно, abbreviations.
           &lt;dl&gt;
             &lt;dt&gt;Plugins:&lt;/dt&gt;
             &lt;dd&gt;
               &lt;dl&gt;
                 &lt;dt&gt;SideKick&lt;/dt&gt;
                 &lt;dd&gt;Позволяет создавать и работать с проектом, а не набором файлов.&lt;/dd&gt;
                 &lt;dt&gt;JDiff&lt;/dt&gt;
                 &lt;dd&gt;Очень удобный диффер, ищет различия посимвольно. Можно настроить игнорирование нескольких подряд идущих пробелов.&lt;/dd&gt;
                 &lt;dt&gt;RubyPlugin&lt;/dt&gt;
                 &lt;dd&gt;Незаменимая вешь для работы с руби&lt;/dd&gt;
                 &lt;dt&gt;RE Tester&lt;/dt&gt;
                 &lt;dd&gt;Удобно тестить регулярные выражения прежде чем их писать в код&lt;/dd&gt;
                 &lt;dt&gt;XSLT&lt;/dt&gt;
                 &lt;dd&gt;При работе с XML. Позволяет тестить xPath.&lt;/dd&gt;
               &lt;/dl&gt;
             &lt;/dd&gt;
           &lt;/dl&gt;
         &lt;/dd&gt;
         &lt;dt&gt;trac&lt;/dt&gt;
         &lt;dd&gt;Очень удобный багтракер. Имеет встроенный вики (например, для спецификации и/или документации). Интегрируется с svn.&lt;/dd&gt;
         &lt;dt&gt;svn&lt;/dt&gt;
         &lt;dd&gt;Контроль версий обязателен :). Пока пользовал только svn, интересно попробовать Git&lt;/dd&gt;
         &lt;dt&gt;Firefox&lt;/dt&gt;
         &lt;dd&gt;А как же без него-то программирование для веб?
           &lt;dl&gt;
             &lt;dt&gt;Plugins:&lt;/dt&gt;
             &lt;dd&gt;
               &lt;dl&gt;
                 &lt;dt&gt;Firebug&lt;/dt&gt;
                 &lt;dd&gt;Без него сейчас не обходится ни одна разработка под web&lt;/dd&gt;
                 &lt;dt&gt;YSlow&lt;/dt&gt;
                 &lt;dd&gt;Позволяет тестировать скорость загрузки страниц&lt;/dd&gt;
                 &lt;dt&gt;Web Developer&lt;/dt&gt;
                 &lt;dd&gt;Позволяет отключать некоторые элементы страницы. Опять же нужен для тестирования&lt;/dd&gt;
                 &lt;dt&gt;Console&lt;sup&gt;2&lt;/sup&gt;&lt;/dt&gt;
                 &lt;dd&gt;Этим пока не пользовался, но поставил на всякий случай. Изучаю...&lt;/dd&gt;
               &lt;/dl&gt;
             &lt;/dd&gt;
           &lt;/dl&gt;
         &lt;/dd&gt;
       &lt;/dl&gt;
     &lt;/dd&gt;
   &lt;/dl&gt;
 &lt;/dd&gt;
 &lt;dt&gt;Настоящее:&lt;/dt&gt;
 &lt;dd&gt;Программирую на C#, asp.Net. Использую всё те же Firefox, JEdit, плюс:
   &lt;dl&gt;
     &lt;dt&gt;ОС: Windows&lt;/dt&gt;
     &lt;dd&gt;Что и следовало ожидать :). Очень непривычно. Почему под убунту нельзя было? :)&lt;/dd&gt;
     &lt;dt&gt;Программы:&lt;/dt&gt;
     &lt;dd&gt;
       &lt;dl&gt;
         &lt;dt&gt;Visual Studio 2008&lt;/dt&gt;
         &lt;dd&gt;Вещь, конечно, на редкость глючная, но без неё никак.&lt;/dd&gt;
         &lt;dt&gt;ReSharper&lt;/dt&gt;
         &lt;dd&gt;Когда-то давно (в университете) использовал IntelliJIDEA для Java. Руки быстро вспомнили старые шорткаты :)&lt;/dd&gt;
         &lt;dt&gt;TotalCommander&lt;/dt&gt;
         &lt;dd&gt;Двупанельный файловый менеджер. Намного удобнее обычного эксплорера&lt;/dd&gt;
       &lt;/dl&gt;
     &lt;/dd&gt;
   &lt;/dl&gt;
 &lt;/dd&gt;
&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-7948221916538864700?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/7948221916538864700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/07/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7948221916538864700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/7948221916538864700'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/07/blog-post.html' title='Моё рабочее место'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1032256262655221028</id><published>2008-05-31T09:32:00.009+03:00</published><updated>2010-03-11T13:40:33.265+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gdm'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Проблемы с запуском графической части Ubuntu (gdm)</title><content type='html'>&lt;p&gt;Проблема была в кратце такова, что при нормальной загрузке Ubuntu моментально подвисала, как только показывалось графическое окно login. В то же время, если сначала загрузиться в recovery mode, а потом запустить графическую оболочку (startx), то всё работало нормально.&lt;/p&gt;

&lt;p&gt;Напрашивается вывод, что при recovery mode Ubuntu не загружает некоторые модули, которые возможно конфликтуют с gdm. Как это выяснить?&lt;/p&gt;

&lt;p&gt;Прежде всего загружаемся в recovery mode и из-под roota выполняем команду
&lt;code class="sh"&gt;sysvconfig&lt;/code&gt;
Там весь список загружаемых модулей. Убираем на время gdm. Сохраняем, выходим. Теперь при нормальной загрузке, компьютер не будет виснуть и мы сможем посмотреть какие модули им загружены.&lt;/p&gt;

&lt;p&gt;Теперь всё в той же root консоли набираем
&lt;code class="sh"&gt;dmesg &amp;gt; /home/[ваш username]/failsafe.log&lt;/code&gt;
что сохранит лог загрузки в файл.&lt;/p&gt;

&lt;p&gt;Также устанавливаем хороший diff'ер
&lt;code class="sh"&gt;apt-get install meld&lt;/code&gt;
Теперь можем спокойно перезагрузиться в нормальном режиме.&lt;/p&gt;

&lt;p&gt;Так как мы в самом начале отключили загрузку gdm, то после перезагрузки мы снова в консоли. Нужно залогиниться и выполнить аналогичную команду, чтоб записать лог загрузки. 
&lt;code class="sh"&gt;dmesg &amp;gt; /home/[ваш username]/normal.log&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Осталось только сравнить эти два лога. Я использовал удобство gdm,- загрузился туда через recovery mode, сравнил через meld эти 2 файла (!! meld сравнивает посимвольно а не построчно, поэтому различия в начале строк, которые являются временем загрузки не сильно волновали !!). В файлах явно читались названия модулей подгружаемых при обычном старте и игнорируемых в recovery mode. У меня это были bluetooth и powernowd. Поэтому, снова запустив sysvconfig, отключил bluetooth, powernowd и powernowd.early, не забыл включить gdm и перезагрузился в нормальном режиме.&lt;/p&gt;

&lt;p&gt;Теперь всё работает.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1032256262655221028?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1032256262655221028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/05/ubuntu-gdm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1032256262655221028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1032256262655221028'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/05/ubuntu-gdm.html' title='Проблемы с запуском графической части Ubuntu (gdm)'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-8683759141280947463</id><published>2008-05-30T16:11:00.006+03:00</published><updated>2008-07-15T19:17:22.230+03:00</updated><title type='text'>Вопросы, которые можно задать при устройстве на работу</title><content type='html'>&lt;p&gt;В скором времени собираюсь переходить на новое место работы. Посмотрим, что из этого выйдет. На новом месте обещают привязанность к Microsoft. Используют практически все их технологии: .Net, Silverlight итд.
Клепать сайты на Rails я уже научился :). Идём дальше...&lt;/p&gt;

&lt;p&gt;В связи с вышесказанным, предлагаю сабж. Мне ими воспользоваться не посчастливилось - наткнулся уже после проведения собеседования.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Сколько новых версий программ вы выпустили за последний год?&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;слишком мало = scope creep: wtf мэнеджмент&lt;/li&gt;
    &lt;li&gt;слишком много = или "супербыстрые" или количество &gt; качество&lt;/li&gt;
  &lt;/ul&gt;
  &lt;li&gt;Почему ушёл человек, работавший до вас на этой должности?&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;уходит от ответа = что-то скрывает&lt;/li&gt;
    &lt;li&gt;он "ушёл" = почему так неопределённо?&lt;/li&gt;
    &lt;li&gt;конкретный ответ = похоже, что всё ок&lt;/li&gt;
  &lt;/ul&gt;
  &lt;li&gt;Случались ли катастрофы и как они были решены (хотя бы последняя)&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;пахали 2 недели = недостаточное DR-планирование (Disaster Recovery) или код (или персонал) WTF&lt;/li&gt;
    &lt;li&gt;2 часа на поиск и устранение = полёт нормальный&lt;/li&gt;
  &lt;/ul&gt;
  &lt;li&gt;Как часто (в год) устраиваются тренинги для персонала?&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt; 1 недели = хотят использовать тебя, но не инвестировать в тебя&lt;/li&gt;
  &lt;/ul&gt;
  &lt;li&gt;Сколько обычно приходится перерабатывать?&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;редко = хорошо продуман проект и время / стабильный код&lt;/li&gt;
    &lt;li&gt;каждый день = плохое планирование, wtf код/персонал/управление&lt;/li&gt;
  &lt;/ul&gt;
  &lt;li&gt;Зависит от деятельности: Размер суппорта/менеджеров по продаже по отношению к программерам?&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;100:1 = много клиентов: стабильный код&lt;/li&gt;
    &lt;li&gt;1:10 - очень новый, может код нестабилен&lt;/li&gt;
    &lt;li&gt;вероятно, новый проект (вполне нормально)&lt;/li&gt;
  &lt;/ul&gt;
  &lt;li&gt;Как устроен DR?&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;"Колян из дома чинит всё" = никакого DR: валить!&lt;/li&gt;
    &lt;li&gt;"параллельные сервера, dbs, итд" = кто-то всё продумал и на это были выделены деньги&lt;/li&gt;
  &lt;/ul&gt;
  &lt;li&gt;Можно заглянуть в серверную?&lt;/li&gt;
  &lt;ul&gt;
    &lt;li&gt;как птичье гнездо = АХТУНГ!&lt;/li&gt;
    &lt;li&gt;компы на холодильнике с вентиляторами = валить!&lt;/li&gt;
    &lt;li&gt;чистенько и прилично = хорошая поддержка сети&lt;/li&gt;
  &lt;/ul&gt;
&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-8683759141280947463?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/8683759141280947463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/05/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8683759141280947463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/8683759141280947463'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/05/blog-post.html' title='Вопросы, которые можно задать при устройстве на работу'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-4676002235945461905</id><published>2008-05-12T16:50:00.004+03:00</published><updated>2010-03-11T13:45:09.390+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Hobo for Rails 2</title><content type='html'>Пока я собирался попробовать это Хобо на вкус, они уже выпустили &lt;a href="http://hobocentral.net/blog/2008/04/18/hobo-075-released/" class="external"&gt;следущую версию&lt;/a&gt;.

А пока времени на это нет вообще.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-4676002235945461905?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/4676002235945461905/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/05/hobo-for-rails-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4676002235945461905'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/4676002235945461905'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/05/hobo-for-rails-2.html' title='Hobo for Rails 2'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-5587402068229752110</id><published>2008-02-04T16:12:00.001+02:00</published><updated>2010-03-11T13:45:09.391+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Hobo for Rails</title><content type='html'>На днях был обнаружен плагин для Rails, который значительно расширяет возможности.
Скоро напишу конкретнее, а пока только &lt;a href="http://hobocentral.net/"&gt;сайт проекта&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-5587402068229752110?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/5587402068229752110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/02/hobo-for-rails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5587402068229752110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/5587402068229752110'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/02/hobo-for-rails.html' title='Hobo for Rails'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-105150718900181032</id><published>2008-02-01T00:06:00.008+02:00</published><updated>2010-08-02T13:28:23.642+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Rails database table names: singular Vs. plural</title><content type='html'>Rails &lt; 2.0 : You need to add into config/environment.rb file line
&lt;pre&gt;&lt;code class="ruby"&gt;# Include your application configuration below
ActiveRecord::Base.pluralize_table_names = false #added line&lt;/code&gt;&lt;/pre&gt;
Rails &gt;= 2.0 : You need to add into config/environment.rb file inside block 
&lt;pre&gt;&lt;code class="ruby"&gt;Rails::Initializer.run do |config|
  config.active_record.pluralize_table_names = false #added line
end&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-105150718900181032?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/105150718900181032/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/01/rails-database-table-names-singular-vs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/105150718900181032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/105150718900181032'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/01/rails-database-table-names-singular-vs.html' title='Rails database table names: singular Vs. plural'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-1051304711553377540</id><published>2008-01-31T22:42:00.013+02:00</published><updated>2010-08-02T13:07:34.953+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PostgreSql'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='gem'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Install Ruby Gem Postgres In Ubuntu Linux</title><content type='html'>Installing ruby gem postgres in Ubuntu linux
&lt;pre&gt;&lt;code class="bash"&gt;sudo gem install postgres&lt;/code&gt;&lt;/pre&gt;
gives the next error
&lt;pre&gt;&lt;code class="bash"&gt;ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
  ERROR: Failed to build gem native extension.

ruby extconf.rb ins postgres
extconf.rb:46: command not found: pg_config --includedir
extconf.rb:53: command not found: pg_config --libdir
checking for main() in -lpq... no&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Can be solved by:&lt;/p&gt;
&lt;pre&gt;&lt;code class="bash"&gt;sudo apt-get install libpq-dev
sudo gem install postgres-pr&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-1051304711553377540?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/1051304711553377540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/01/ruby-gem-postgres-ubuntu-linux.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1051304711553377540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/1051304711553377540'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/01/ruby-gem-postgres-ubuntu-linux.html' title='Install Ruby Gem Postgres In Ubuntu Linux'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-360329120074358364.post-6239139606497468421</id><published>2008-01-08T14:43:00.002+02:00</published><updated>2008-08-14T12:04:59.338+03:00</updated><title type='text'>Hello world!</title><content type='html'>Так уж повелось, что всё в этом мире начинается с Hello world!. Даже блоги.  Вообще, так сказать, это первая тестовая попытка создать блог, имеющий какую-то конкретную специализацию. Опыт работы пока ещё небольшой (пара лет), поэтому некоторым мои открытия могут показаться уже давно известными и проверенными истинами. Однако, блог и создаётся главным образом для того, чтобы быстрее вырасти и набрать знаний и опыта. Первое время скорее всего буду делиться мыслями о Ruby и Rails. Просто последний мой проект написан именно на этом языке с использованием фрэймворка.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/360329120074358364-6239139606497468421?l=dracoater.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dracoater.blogspot.com/feeds/6239139606497468421/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dracoater.blogspot.com/2008/01/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6239139606497468421'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/360329120074358364/posts/default/6239139606497468421'/><link rel='alternate' type='text/html' href='http://dracoater.blogspot.com/2008/01/blog-post.html' title='Hello world!'/><author><name>Juri Timošin</name><uri>https://profiles.google.com/102891934035801347808</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-8b10lquaDP8/AAAAAAAAAAI/AAAAAAAADLA/0b33bdGvVoI/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry></feed>
