<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Marcin Świerczyński's Blog</title>
		<description>A personal blog about software engineering</description>
		<link>http://blog.swierczynski.net</link>
		
			<item>
				<title>Strong passwords hashing with Apache Shiro</title>
				<description>&lt;h2&gt;What is it all about?&lt;/h2&gt;

&lt;p&gt;Recently, I wanted to provide a strong password hashing in a plain Java application. I decided to use &lt;a href=&quot;http://shiro.apache.org&quot;&gt;Apache Shiro&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As Apache Shiro's website says:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Apache Shiro is a powerful and easy-to-use Java security framework that performs authentication, authorization, cryptography, and session management.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Shiro is very powerful and provides all-in-one security solution. For instance, it can communicate with a persistence layer directly, so you don't need to take care of a boilerplate code. However, my intention was only to provide a strong password hashing, nothing more or less.&lt;/p&gt;

&lt;p&gt;So, how to do that?&lt;/p&gt;

&lt;h2&gt;Hashing salted passwords&lt;/h2&gt;

&lt;p&gt;My implementation uses a separate salt for each user. Although, there are &lt;a href=&quot;http://stackoverflow.com/questions/2188507/help-with-salt-and-passwords&quot;&gt;different opinions about that&lt;/a&gt;, I've decided that salt will be stored in its own column in a database. Let's start coding then.&lt;/p&gt;

&lt;p&gt;First of all we should generate a salt:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getSalt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;SecureRandomNumberGenerator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;nextBytes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Given salt, we can hash plain text password:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;java&quot;&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Sha512Hash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashIterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toHex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Of course, we didn't want to store &lt;code&gt;ByteSource&lt;/code&gt; directly in a database, so I converted it to a hex-encoded string:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;java&quot;&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toHex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now we can store both hashed password and salt in a database. How about comparing a result with a plain text password?&lt;/p&gt;

&lt;h2&gt;Comparing clear text and hashed passwords&lt;/h2&gt;

&lt;p&gt;Obviously, to compare a user-provided password with its hashed version, we need to hash it again using the same salt and compare the result with what is stored in a database.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;java&quot;&gt;&lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;???&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashedPassword&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Sha512Hash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clearTextPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashIterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toHex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashedPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dbStoredHashedPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But how to get &lt;code&gt;ByteSource&lt;/code&gt; object from a string we saved? It's easy as well.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;java&quot;&gt; &lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;bytes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Hex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;h2&gt;Putting it all together&lt;/h2&gt;

&lt;p&gt;The complete example could look like:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;passwordsMatch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dbStoredHashedPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clearTextPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;bytes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Hex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashedPassword&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashAndSaltPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clearTextPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashedPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dbStoredHashedPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hashPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clearTextPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getSalt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashAndSaltPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clearTextPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// persist salt and hash or return them to delegate this task to other component&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hashAndSaltPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clearTextPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Sha512Hash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clearTextPassword&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashIterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toHex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ByteSource&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getSalt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;SecureRandomNumberGenerator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;nextBytes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;h2&gt;What is the hashIterations?&lt;/h2&gt;

&lt;p&gt;The hash iterations value indicates the number of times the clear password is hashed. The value larger, the hash algorithm applied more times, making the process slower and, as a result, making the password harder to break by a brute-force attack.&lt;/p&gt;

&lt;p&gt;What's the perfect value? It depends on you security requirements and your hardware performance. Too many iterations, means slower log-in process from users perspective. Too few, means easier to compromise passwords.&lt;/p&gt;

&lt;p&gt;I've decided to 200.000 iterations. More on that issue can be found on &lt;a href=&quot;http://www.stormpath.com/blog/strong-password-hashing-apache-shiro&quot;&gt;Stormpath's blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;That's all, folks&lt;/h2&gt;

&lt;p&gt;Passwords hashing appeared to be quite easy with Apache Shiro. The code I provided lacks of some null-checks and exceptions handling. I omitted them for the sake of clarity.&lt;/p&gt;

&lt;p&gt;And remember, never store plain text passwords in a database :-)&lt;/p&gt;
</description>
				<published>Fri Jan 25 22:30:12 -0800 2013</published>
				<link>http://blog.swierczynski.net/2013/01/strong-passwords-hashing-wtih-apache-shiro</link>
			</item>
		
			<item>
				<title>Schema Design in MongoDB</title>
				<description>&lt;p&gt;Recently, I started MongoDB for Developers course from &lt;a href=&quot;https://education.10gen.com&quot;&gt;10gen Education&lt;/a&gt;. The third week brought some very interesting information on schema design.&lt;/p&gt;

&lt;p&gt;I decided to write it down here for further reference but I hope it will also be useful for others.&lt;/p&gt;

&lt;h2&gt;MongoDB limitations&lt;/h2&gt;

&lt;p&gt;MongoDB &lt;strong&gt;do not provide foreign key constraints&lt;/strong&gt; known from relational databases. How can we deal with it? Well, one option is &lt;strong&gt;embedding&lt;/strong&gt;. If you don't separate documents into a few collections but embed one into other, you basically avoid using foreign key at all! It of course isn't a silver bullet - it depends on your data usage pattern or other MongoDB limitations (like max. 16MB per document), but it's definitely worth considering.&lt;/p&gt;

&lt;p&gt;Moreover, Mongo &lt;strong&gt;don't provide transactions&lt;/strong&gt;. It looks quite serious but it actually can be worked around easily, because of a few solutions.&lt;/p&gt;

&lt;p&gt;First of all, MongoDB supports &lt;strong&gt;atomic operations&lt;/strong&gt;. It means you have a guarantee that a single document will be persisted atomically, ie. saved all or nothing. How does it help the situation? Well, if you embed a document into another, you don't need to worry about transactions at all. You save one document (atomically!), instead of a few, which would need transactional approach.&lt;/p&gt;

&lt;p&gt;If you can't or don't want to embed documents, you still have some options. First of all, you can implement some sort of &lt;strong&gt;locking on the application level&lt;/strong&gt;. For example, it can be critical sections, semaphores, etc.&lt;/p&gt;

&lt;p&gt;The last option is to &lt;strong&gt;tolarate&lt;/strong&gt; a little bit of inconsistency. Sometimes, actually more often nowadays, it isn't crucial to provide the same data to all users at the same time. If you consider social networks, it makes sense to show the fact that you made a new friendship a bit later to some of your friends, than to others. In this case the goal is to achieve &lt;em&gt;eventual consistency&lt;/em&gt;, not the immediate consistency.&lt;/p&gt;

&lt;h2&gt;Relations&lt;/h2&gt;

&lt;p&gt;In MongoDB, you can achieve relations between documents on one of four ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;put a foreign key in one of these documents&lt;/li&gt;
&lt;li&gt;put foreign keys in both documents&lt;/li&gt;
&lt;li&gt;embed one document into another&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Which one to choose depends on a few factors, including relation type.&lt;/p&gt;

&lt;h3&gt;One to One&lt;/h3&gt;

&lt;p&gt;In one to one relation you can ask yourself three questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How often will I use the data?&lt;/strong&gt; If the data won't be used often as a single piece, you probably should separate it into two documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How big is the data?&lt;/strong&gt; If the data size exceeds 16 MB then it's a no brainer - you need to separate it. Also, when the data is big, however under 16 MB, but you constantly update only a part of it, it probably makes sense to separate it as well to avoid update overhead. Of course, it's also important here to think about how the data will grow up in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need to update the data atomically?&lt;/strong&gt; If the answer is yes and there are no other contraindications, then it makes sense to keep it together as mentioned above.&lt;/p&gt;

&lt;h3&gt;One to Many&lt;/h3&gt;

&lt;p&gt;The question here is: is it real one to many or maybe it's rather one to &lt;em&gt;few&lt;/em&gt;? So, if you have a people-city relation, it makes sense to use &lt;em&gt;true linking&lt;/em&gt; and two collections. However, if you have a blog post - comments relation, then you probably should decide to embedding.&lt;/p&gt;

&lt;h3&gt;Many to Many&lt;/h3&gt;

&lt;p&gt;As a rule of thumb, it makes the most sense to create two collections and link them using array fields. If you'd like to make this connection bidirectional, then the array should be in both collections. It becomes more powerful together with &lt;a href=&quot;http://www.mongodb.org/display/DOCS/Multikeys&quot;&gt;multikey indexes&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;To sum up, we can say that a rule of thumb is to embed. Beside the advantages mentioned above, there is one more - performance. Embedded documents lays near each other on the HDD, probably in the same sector, so reading them is much faster because of hard drives nature.&lt;/p&gt;

&lt;p&gt;However, it all depends on the data access patterns of your application. You need to consider potential duplication anomalies as well as performance. I hope the above recommendations will help with the decission.&lt;/p&gt;
</description>
				<published>Sun Nov 11 15:21:23 -0800 2012</published>
				<link>http://blog.swierczynski.net/2012/11/schema-design-in-mongodb</link>
			</item>
		
			<item>
				<title>Functional Programming Principles in Scala Course</title>
				<description>&lt;p&gt;A few days ago I finished Functional Programming Principles in Scala course by Martin Odersky and &lt;a href=&quot;http://www.coursera.com&quot;&gt;Coursera&lt;/a&gt;. I just wanted to share my thoughts on it, since it took quite a bit of my time during last seven weeks.&lt;/p&gt;

&lt;h2&gt;Goal&lt;/h2&gt;

&lt;p&gt;My goal was to get a taste of functional programming which I had a very little contact with before. Also, I wanted to polish my Scala skills, because I'm still learning it. Was the plan accomplished? Well, definitely! But it wasn't a piece of cake!&lt;/p&gt;

&lt;h2&gt;Challenges&lt;/h2&gt;

&lt;p&gt;It's quite challenging to change your mindset and start thinking in a functional way. But when you get the point, it's unbelievably rewarding!&lt;/p&gt;

&lt;p&gt;Also, the resulting code is very elegant and consistent. However, I got to the point where I think it needs more understanding (or maybe just experience) not to make it inefficient, mainly because of have usage of recursion. Scala helps the situation by introducing &lt;em&gt;tail recursion&lt;/em&gt;, but again, it takes time for a beginner's mind to wrap around it. Paradoxically, that's probably the biggest gain from the course - to &lt;strong&gt;change the way you think&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;Assignments&lt;/h2&gt;

&lt;p&gt;The most important part of the course were weekly assignments. I spent a lot of time on them and I really enjoyed every minute! They were challenging, but not in &quot;turning you off&quot; way.&lt;/p&gt;

&lt;p&gt;Each assignment was rated in 10 points scale - 8 points for code validity and 2 for style. The score was calculated using automated tests, which is actually fully understandable, considering participants number (~50k last time I checked it). However, it looks like the grading introduces a lot of misunderstanding. I've read many comments about how it's misleading and how a high (or low) rate doesn't proof anything. I agree, but I can't really imagine how it could work without grades. I, personally, was really excited when I got 10/10 after a few hours of exercising my mind. And while it doesn't proof anything, I was at least ensured that I was on a good path.&lt;/p&gt;

&lt;h2&gt;Lectures&lt;/h2&gt;

&lt;p&gt;Lectures were integral part of the course. I was watching them before each assignment and they were helping a lot. They were mainly focused on theoretical aspect. I could learn how the code is evaluated and how data structures work internally. That's good because most of tutorials and articles on the Internet focuses on a practical part, so a source of knowledge about what's going on under the hood is much appreciated. That wouldn't be so  easy, however, without Martin Odersky. He is a great teacher and it's quite obvious he's excited about what he is doing.&lt;/p&gt;

&lt;h2&gt;What's next?&lt;/h2&gt;

&lt;p&gt;Well, I think I'll get back to reading &lt;a href=&quot;http://www.artima.com/shop/programming_in_scala_2ed&quot;&gt;Programming in Scala&lt;/a&gt; (which I highly recommend, by the way) and learning &lt;a href=&quot;http://www.playframework.org&quot;&gt;Play! Framework&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To sum up, I need to say again that I really enjoyed the course. I feel I gained a lot from it. I'd like to thank you to both Martin Odersky and Coursera team!&lt;/p&gt;
</description>
				<published>Thu Nov 08 20:10:23 -0800 2012</published>
				<link>http://blog.swierczynski.net/2012/11/functional-programming-principles-in-scala</link>
			</item>
		
			<item>
				<title>Configuring IntelliJ IDEA for Play! Framework</title>
				<description>&lt;p&gt;Some time ago I recorded a short screencast describing how to configure Play! Framework 1.2.4 with IntelliJ IDEA 11. The point was to promote the framework and to get some experience in screencasts recording :)&lt;/p&gt;

&lt;p&gt;I'm aware it's a bit outdated now, since Play! 2 has been released. However, I decided to publish it. I hope somebody make a use of it!&lt;/p&gt;

&lt;iframe width=&quot;420&quot; height=&quot;315&quot; src=&quot;http://www.youtube.com/embed/D7Sh18beDLo&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;

</description>
				<published>Thu Jun 07 12:45:01 -0700 2012</published>
				<link>http://blog.swierczynski.net/2012/06/configuring-intellij-idea-for-play-framework</link>
			</item>
		
			<item>
				<title>Code Simplicity by Max Kanat-Alexander</title>
				<description>&lt;p&gt;&lt;img src=&quot;/img/posts/code-simplicity.gif&quot; alt=&quot;Code Simplicity&quot; /&gt;
Thanks to &lt;em&gt;O'Reilly Blogger Review Program&lt;/em&gt; I was recently able to read &lt;strong&gt;Code Simplicity by Max Kanat-Alexander&lt;/strong&gt;. First of all, I have to admit I was confused by the title. I thought that the book will be about, well, coding. But it isn't - in the whole text there is almost no code at all! Instead, on a first few pages, you can read that the book is about a design. But again, if you, like me, think about UML charts or design patterns, you will be fooled again. There is nothing about that either. Then, what the book is about?&lt;/p&gt;

&lt;p&gt;It's about good practices in software development. The author tries to create &lt;em&gt;the science of software development&lt;/em&gt;. Has he succeeded? In my opinion - unfortunately, not.&lt;/p&gt;

&lt;p&gt;He wrote that the ultimate goal of software is to help people. He wrote that the cost of software maintenance is much more important than the cost of its implementation. He wrote about &lt;em&gt;YAGNI&lt;/em&gt; and the fact that a code should be as simple as possible.&lt;/p&gt;

&lt;p&gt;That's all true. But these issues were mentioned in so many books that you probably already know them! At least, if you read any book by Robert Martin or Martin Fowler.&lt;/p&gt;

&lt;p&gt;But let's assume for a moment, that you haven't read any. Is &lt;em&gt;Code Simplicity&lt;/em&gt; worth buying then? I think it still isn't. Why? Because the biggest drawback of this book is that it tells &lt;em&gt;what&lt;/em&gt; but doesn't tell &lt;em&gt;how&lt;/em&gt;. You will read that simplicity is the most important factor of software design, but you won't get a practical example of how to achieve it. Nothing about refactoring, single responsibility principle and so on. The book says that each change introduces a possible bug, but it only gives two advices on how to build easy to change systems: DRY and &lt;em&gt;don't fix it if it isn't broken&lt;/em&gt;. That's fine, but does mentioning it really help you to build better software? You probably already know that you shouldn't copy-paste your code...&lt;/p&gt;

&lt;p&gt;Reading the above you could think that the book is a complete disaster. But it isn't the case. It just &lt;strong&gt;isn't a good book for a programmer&lt;/strong&gt;. Well, at least for a programmer who is interested in his craftsmanship. However, I'd say this &lt;strong&gt;is a good book for a non-technical manager&lt;/strong&gt; who would like to understand his engineering team better. After reading, he'll get a big picture of how software developers think and what is important for them. No details, but do they really need them?&lt;/p&gt;

&lt;p&gt;To sum up, I, as a software engineer, am disappointed by &lt;em&gt;Code Simplicity&lt;/em&gt;, so I wouldn't recommend it to my teammates. But I'd recommend it to my product manager to make our communication in the future easier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O’Reilly Product Page&lt;/strong&gt;: &lt;a href=&quot;http://shop.oreilly.com/product/0636920022251.do&quot;&gt;Code Simplicity&lt;/a&gt;&lt;/p&gt;
</description>
				<published>Sun Apr 15 12:04:23 -0700 2012</published>
				<link>http://blog.swierczynski.net/2012/04/code-simplicity-by-max-kanat-alexander</link>
			</item>
		
			<item>
				<title>Mastering Advanced Git by Matthew McCullough and Tim Berglund</title>
				<description>&lt;p&gt;&lt;img src=&quot;/img/posts/mastering-advanced-git.gif&quot; alt=&quot;Mastering Advanced Git&quot; /&gt; It was almost a year ago when I had a pleasure to &lt;a href=&quot;http://blog.swierczynski.net/2011/03/mastering-git-by-matthew-mccullough-and-tim-berglund/&quot;&gt;review Mastering Git by Matthew McCullough and Tim Berglund&lt;/a&gt;. Today, thanks to O’Reilly, I can take a look at its successor - Mastering Advanced Git.&lt;/p&gt;

&lt;p&gt;Just as a reminder: I really liked the first part. But I simply loved the new one! It covers Git details in very thorough way. And, what is perhaps even more important, it leads you through them in extremely straightforward manner.&lt;/p&gt;

&lt;p&gt;In all advanced topic discussions, there is always one important issue to solve. Considering a large number of possible topics, which should we choose? Matthew and Tim decided to talk about &lt;em&gt;pull&lt;/em&gt; and &lt;em&gt;push&lt;/em&gt; options, &lt;em&gt;rerere&lt;/em&gt;, methods of moving a code outside the repo, orphan branches and &lt;em&gt;refspecs&lt;/em&gt;. Some of them are just switches to configure and (almost) forget. Although, I personally found &lt;em&gt;patches&lt;/em&gt;, &lt;em&gt;bundles&lt;/em&gt; and &lt;em&gt;refspecs&lt;/em&gt; the most valuable, because these have a lot of possible use cases during the whole development and code management cycle. Nevertheless, all of the topics are well prepared. It obvious that both teachers are professionals in Git.&lt;/p&gt;

&lt;p&gt;In terms of technical quality, I haven’t found any differences. Both video and sound are still very high quality.&lt;/p&gt;

&lt;p&gt;Listening to Matthew and Tim is simply a pleasure. I strongly recommend it for everyone who wants to polish his or her Git skills.&lt;/p&gt;

&lt;p&gt;Just a short disclaimer at the end: Although I referenced to Mastering Git a few times, I need to mention that Mastering Advanced Git is a separate product. You do not need to watch the first part to benefit from the Mastering Advanced Git. If you feel comfortable with Git on intermediate level, do not hesitate and go straight to the most advanced one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O’Reilly Product Page&lt;/strong&gt;: &lt;a href=&quot;http://shop.oreilly.com/product/0636920024774.do&quot;&gt;McCullough and Berglund on Mastering Advanced Git&lt;/a&gt;&lt;/p&gt;
</description>
				<published>Sun Feb 12 16:01:23 -0800 2012</published>
				<link>http://blog.swierczynski.net/2012/02/mastering-advanced-git-by-matthew-mccullough-and-tim-berglund</link>
			</item>
		
			<item>
				<title>Cloud Foundry + Grails = lightning fast deployment</title>
				<description>&lt;p&gt;The purpose of this article is to show how quickly and easily deploy &lt;a href=&quot;http://www.grails.org&quot;&gt;Grails&lt;/a&gt; application to Cloud Foundry platform.&lt;/p&gt;

&lt;p&gt;What is Cloud Foundry?&lt;/p&gt;

&lt;p&gt;From &lt;a href=&quot;http://www.cloudfoundry.com/about&quot;&gt;cloudfoundry.com&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Cloud Foundry is an open platform as a service, providing a choice of clouds, developer frameworks and application services. Initiated by VMware, with broad industry support, Cloud Foundry makes it faster and easier to build, test, deploy and scale applications. It is an open source project and is available through a variety of private cloud distributions and public cloud instances, including CloudFoundry.com.&lt;/p&gt;&lt;/blockquote&gt;

&lt;h2&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;To make a use of this article you'll need to have Grails framework installed.&lt;/p&gt;

&lt;p&gt;To check if Grails is properly installed, use&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  grails -version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You should see something like&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  Grails version: 2.0.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If you haven't, just follow the &lt;a href=&quot;http://grails.org/doc/latest/guide/gettingStarted.html#requirements&quot;&gt;Grails Getting Started Guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Let's the fun begin&lt;/h2&gt;

&lt;p&gt;The whole process is extraordinary simple! Just do the following steps.&lt;/p&gt;

&lt;p&gt;  1. Create Grails app&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  grails create-app cloud_foundry_example
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;  2. Change your working directory to a new application directory&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  cd cloud_foundry_example
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;  3. Install Cloud Foundry plug-in&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  grails install-plugin cloud-foundry
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;  4. Configure your Cloud Foundry credentials&lt;/p&gt;

&lt;p&gt;You can configure it in both &lt;em&gt;grails-app/conf/Config.groovy&lt;/em&gt; and in &lt;em&gt;~/.grails/settings.groovy&lt;/em&gt;. Since the file will contain sensitive, it's not recommended to put it in source control. That's why the second option is considered the best practice.&lt;/p&gt;

&lt;p&gt;So, configure your credentials using&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  grails.plugin.cloudfoundry.username = &amp;quot;&amp;lt;your_username&amp;gt;&amp;quot;
  grails.plugin.cloudfoundry.password = &amp;quot;&amp;lt;pass&amp;gt;&amp;quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;  5. Test your config&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  grails cf-info
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The output should look like&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  VMware&amp;#39;s Cloud Application Platform
  For support visit http://support.cloudfoundry.com
  Target:   http://api.cloudfoundry.com (v0.999)
  
  User:     &amp;lt;your_username&amp;gt;
  Usage:    Memory   (0B of 2.0G total)
            Services (0 of 16 total)
            Apps     (0 of 20 total)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;  6. Deploy your app!&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  grails prod cf-push
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You'll be asked about the application URL, and also about some persistence services (in the time of writing: MySQL and PostgreSQL). I advise to accept default address and chose one of these services.&lt;/p&gt;

&lt;p&gt;If you want to re-deploy after some changes, just do&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text&quot;&gt;  grails prod cf-update
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;h2&gt;That's it!&lt;/h2&gt;

&lt;p&gt;The app is deployed and ready to work. A proof? &lt;a href=&quot;http://partyplanner.cloudfoundry.com/&quot;&gt;PartyPlanner app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In next part I'll describe how to configure different services in Cloud Foundry.&lt;/p&gt;
</description>
				<published>Sat Jan 07 17:45:50 -0800 2012</published>
				<link>http://blog.swierczynski.net/2012/01/cloud-foundry-grails-lightning-fast-deployment</link>
			</item>
		
			<item>
				<title>Mastering Git by Matthew McCullough and Tim Berglund</title>
				<description>&lt;p&gt;&lt;img src=&quot;/img/posts/mastering-git.gif&quot; alt=&quot;Mastering Git by Matthew McCullough and Tim Berglund Video cover&quot; /&gt;&lt;/p&gt;

&lt;p&gt;On the beginning, I just want to say one thing - McCullough and Berglund on Mastering Git is a perfect way to learn Git! The only requirement is an ability to learn in a classroom-type environment. An impression of class or conference is maximized by the fact that “students” are asking questions. If you're able to learn from a lecture, keep reading!&lt;/p&gt;

&lt;p&gt;This video provide you with step-by-step instructions on how to efficiently use Git in a production environment. You'll begin from the very beginning: installing and configuring Git on different platforms.&lt;/p&gt;

&lt;p&gt;Then you'll go to basics like managing repositories, three-stage approach, committing, creating local branches and tracking the remote ones and so on.&lt;/p&gt;

&lt;p&gt;What I especially like about this training is the fact that it also covers more sophisticated topics. You'll learn what DAG is and how this structure influences a whole Git. You'll become a best friend of tags (both light- and heavyweight) and know how to use rebasing, amend, stashing and others. I've to mention that it's quite easy to get lost during these topics discussion, but you can always rewind the video and repeat a complex part.&lt;/p&gt;

&lt;p&gt;A few words about technical details. The whole training is recorded in high-resolution, so it was a pleasure to watch it. The sound was also very high-quality. The only things missing are subtitles. It'd be a great help for foreigners and the disabled.&lt;/p&gt;

&lt;p&gt;The verdict is simple. I would recommend this video to a friend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O'Reilly Product Page&lt;/strong&gt;: &lt;a href=&quot;http://oreilly.com/catalog/0636920017479/&quot;&gt;Mastering Git by Matthew McCullough and Tim Berglund&lt;/a&gt;&lt;/p&gt;
</description>
				<published>Sat Mar 05 11:00:58 -0800 2011</published>
				<link>http://blog.swierczynski.net/2011/03/mastering-git-by-matthew-mccullough-and-tim-berglund</link>
			</item>
		
			<item>
				<title>2010 summary and 2011 resolutions</title>
				<description>&lt;p&gt;I've never done summary of the past year before. As well as I've never make huge resolutions for the upcoming year. But, come on, this year was so great it deserve this! We often forget about our past successes so I think that just thinking about them is a great way to start the New Year with good attitude. On the other hand, the next year resolutions list can be a guide for what to do in every single day to get closer to our aims. And, after all, I've never got a blog to post the summary ;)&lt;/p&gt;

&lt;p&gt;So, first things first. This year was good, very good. What I've done?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I've graduated from Polish-Japanese Institue of Information Technology with honours degree in Computer Science.&lt;/li&gt;
&lt;li&gt;I've found a new, great job that I really enjoy. It helps in my skills development and, what is the most important, I do what I love to do!&lt;/li&gt;
&lt;li&gt;I've learned quite many new technologies and programming languages:

&lt;ul&gt;
&lt;li&gt;Android SDK. The result is visible in Android Market and it's called &lt;a href=&quot;http://autoresponder.swierczynski.net/&quot;&gt;AutoResponder&lt;/a&gt; ;)&lt;/li&gt;
&lt;li&gt;Python / Django&lt;/li&gt;
&lt;li&gt;Objective C / iOS SDK&lt;/li&gt;
&lt;li&gt;Groovy / Grails&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;I've been on my first Java conference, GeeCON in Poznan.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;What do I plan to do in 2011?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First of all, as usual I want to improve my development/programming skills, especially in iOS, Android and Python. I also want to polish my &quot;soft&quot; development abilities. How to do that? More books, conferences, and, first of all, practice - both in work and in open-source projects.&lt;/li&gt;
&lt;li&gt;I want to learn Scala and Lift framework.&lt;/li&gt;
&lt;li&gt;There are other languages than programming ones, aren't there? ;) I want to polish my English skills. This blog is one of the steps toward it. Moreover, I plan to start the new course on the beginning of the year.&lt;/li&gt;
&lt;li&gt;There is also one huge project I plan to start in 2011, but for now I can't say much more.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;That's all for now. One year is quite a lot of time so I will probably add more items to the above list, if I only have enough time.&lt;/p&gt;

&lt;p&gt;Happy New Year, Everone! :)&lt;/p&gt;
</description>
				<published>Fri Dec 31 15:38:18 -0800 2010</published>
				<link>http://blog.swierczynski.net/2010/12/2010-summary-and-2011-resolutions</link>
			</item>
		
			<item>
				<title>How to create UIPickerView with toolbar above it in iOS</title>
				<description>&lt;p&gt;A few days ago, I had to implement a UIPickerView based select list with toolbar above it. The toolbar had to have a button to close the picker. The whole solution had to be very similar to the one used in a mobile version of Safari browser. How to do that?&lt;/p&gt;

&lt;p&gt;The clue of the problem is contained in just two properties of &lt;a href=&quot;http://developer.apple.com/library/ios/#documentation/uikit/reference/UIResponder_Class/Reference/Reference.html&quot;&gt;UIResponder&lt;/a&gt; class: &lt;em&gt;inputView&lt;/em&gt; and &lt;em&gt;inputAccessoryView&lt;/em&gt;. The first one contains a view which will be displayed if its owner will become a first responder. For example, for UITextFields it's a keyboard by default. The second one in turn, represents a view which will be displayed before (ie. above) the view pointed by &lt;em&gt;inputView&lt;/em&gt; property.&lt;/p&gt;

&lt;p&gt;So now it should be quite easy:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;objectivec&quot;&gt;    &lt;span class=&quot;n&quot;&gt;UIResponder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;firstResponder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// use your future first responder&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;UIPickerView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pickerView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UIPickerView&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;pickerView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;showsSelectionIndicator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;YES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;firstResponder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pickerView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pickerView&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;UIToolbar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toolbar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UIToolbar&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;initWithFrame:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CGRectMake&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;320&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;toolbar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;barStyle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UIBarStyleBlackTranslucent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;firstResponder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputAccessoryView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;toolbar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toolbar&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Unfortunately, it isn't. Both inputView and inputAccessoryView are readonly properties, so we've to redeclare them in a subclass:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;objectivec&quot;&gt;    &lt;span class=&quot;k&quot;&gt;@property&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readwrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;retain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UIView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;@property&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readwrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;retain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UIView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputAccessoryView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;What is the best, we aren't limited to use this feature on UITextFields only. Because of fact that &lt;em&gt;UIView&lt;/em&gt; inherits from &lt;em&gt;UIResponder&lt;/em&gt;, we can attach this behaviour to all views, for example to a button or a table cell. To do that we have to override &lt;code&gt;canBecomeFirstResponder&lt;/code&gt; method in our subclass. For example, the UIButton subclass implementation can look like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;objectivec&quot;&gt;    &lt;span class=&quot;n&quot;&gt;implementation&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CustomButton&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//it is UIButton subclass&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;@synthesize&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inputView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inputAccessoryView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;BOOL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;canBecomeFirstResponder&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;YES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dealloc&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputView&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputAccessoryView&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;super&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dealloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;@end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
				<published>Mon Dec 06 20:07:24 -0800 2010</published>
				<link>http://blog.swierczynski.net/2010/12/how-to-create-uipickerview-with-toolbar-above-it-in-ios</link>
			</item>
		
	</channel>
</rss>