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. :)
Thursday, 22 December 2011
Monday, 14 November 2011
Java: Save InputStream Into File
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
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).
import sun.misc.IOUtils;
new FileOutputStream("tmp.txt").write(IOUtils.readFully(inputStream, -1, false));
Wednesday, 24 August 2011
Top 10 Jenkins Must-Have Plugins
Friday, 10 June 2011
Ruby Pack/Unpack
Having a party in ZeroTurnaround new office in Tartu. There is a mat on the floor near the entrance door that says:
01010111011001010110110001100011011011110110110101100101
Using ruby, we can quickly figure out, what that actually means:
["01010111011001010110110001100011011011110110110101100101"].pack('B*') #==> Welcome
Thursday, 9 June 2011
GeekOut: The First Java Conference In Estonia
Today I have attended the first Java conference in Estonia: GeekOut. 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 :) ).
The day started with small introduction from Jevgeni Kabanov, the founder and CTO of ZeroTurnaround, the organizers of the GeekOut. After that the main part began.
The first talk was about Java 7 by Martijn Verburg. It was about the new features that are coming in JDK 7. Project Coin announced:
- Strings in switch
- Automatic Resource Management (such as c#
using
construction) - Numeric literals with underscores. (Like in ruby: 3_456_789)
- Improved Type Inference for Generic Instance Creation
We can skip generics on the right side:Map<String, List<String>> anagrams = new HashMap<>();
- New file handling mechanism, which "is finally done right, I hope" (M.V.)
- 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...
Next speech was about "Riding the data tsunami and coming out on top" by Alex Snaps. He introduced Terracotta - an open source solution for application scalability, availability and performance.
After a coffee break Joonas Lehtinen told us about Vaadin}> - 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.
John Davies talked about integration of applications. Banking realities: FpML, 100-100000 messages/sec, latency critical - 10ms, xml is evil - no time for <>, 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.
After the lunch noSql databases, particularly GraphDB called Neo4j was covered by Peter Neubauer. 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.
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.
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.
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!
The Slides:
- Back To The Future With Java 7 ~ Martijn Verburg
- Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript ~ Joonas Lehtinen
- Architecting For Enterprise Scale ~ John T. Davies (Filmed on QCon)
- Neo4j For the Rescue ~ Peter Neubauer
PS. I will list all the slides of the presentations here as soon as they appear.
Wednesday, 11 May 2011
Google Code Jam 2011 Qualification Round
This Saturday Google Code Jam 2011 Qualification Round took place. I didn't have much time to spend on the problems, but still have solved a couple and proceeded to Round 1.
The ones that I solved are Magicka and Candy Splitting.
Magicka
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.
#!/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 << elem
if result.length > 1
last2 = result[-2..-1].join
if combines.key?(last2)
result.pop(2)
result = result << combines[last2]
end
opposed.each do |o|
if result.include?(o[0]) && result.include?(o[1])
result = []
break
end
end
end
end
puts "Case ##{test_id}: [#{result.join(", ")}]"
end
Candy Splitting
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 Goro (strength is my strength :) )
#!/usr/bin/ruby
def s( candies, pile1, pile2 )
#p "c:#{candies}, 1:#{pile1}, 2:#{pile2}"
if candies.empty?
if !pile1.empty? && !pile2.empty? && 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 << x, pile2) || s( candies, pile1, pile2 << 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
Thursday, 21 April 2011
Mercurial In Ubuntu
Since I have moved to ZeroTurnaround 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.
We use Mercurial as SCM. So here is a small tip for ubuntu users how to configure hg.
Mercurial is available to install through repository
$ sudo aptitude install mercurial
So now as it is installed, we can configure it. Mercurial reads configuration data from several files, if they exist. To list them use:
$ hg help config
Now we will edit the $HOME/.hgrc
file to add there some user information, authentication and enable plugins. A configuration file consists of sections, led by a [section]
header and followed by name = value
entries (sometimes called configuration keys)
[ui]
username = Firstname Lastname <firstname.lastname@example.net>
Here we introduced ourselves. The section is [ui]
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.
[auth]
foo.prefix=*
foo.username=firstname.lastname@example.net
foo.password=SecretPassword123
The [auth]
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, foo - 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.
[extensions]
fetch =
color =
#this extension will get loaded from the file specified
myfeature = ~/.hgext/myfeature.py
Mercurial has an extension mechanism for adding new features. To enable an extension, create an entry for it in [extensions]
section. There is a list of extensions for Mercurial and you can write one yourself. Extensions bundled with Mercurial does not need anything after the equals sign, but you need to provide the full path to others.
Now that we have configured it a little bit, we can start using. Mercurial tutorial by Joel Spolsky will teach you, how.
Friday, 14 January 2011
Hello, ZeroTurnaround!
A week ago I have left Axinom. Now I work in ZeroTurnaround - the famous home of JRebel. 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.
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.