Včelí medvídci a (ne)vyměnitelné baterky

Baterky ve Včelích medvídcích oficiálně nejdou vyměnit. Výrobce (prý z bezpečnostních důvodů) baterii zašil dovnitř do hračky. Nám baterie vydrželi zhruba půl roku, pak začal čmelda zkuhrat hlady 🙂 Sice se ještě snažil zpívat, ale znělo to skoro strašidelně 🙂 Naštěstí se dá na zádech rozpárat a baterie vyměnit. V jednom místě je na zádech trochu jiný šef, stačí nit přestřihnout a vyndat malou krabičku, ve které je zároveň mikrofon i baterky. Baterie jsou typu LR44 a jsou potřeba 3ks. Můžete je koupit například v DatArtu, mají je tam za 10 Kč (psáno 7.2011). Pozor: nekupujte je v hodinářství, tam je mají 5x dražší.

Včelí medvídek – Výměna baterek

Pokud se vám článek líbil, nezapomeňte ho sdílet na Facebooku, Twitteru či jinak 🙂

On pair programming

Several times I programmed in pair and I want to share my experience with it.  What are the main benefits of pair programming?

  • The code is of better quality, because there is always the other person watching over your shoulder and seeing what you have overlooked. Wikipedia says that defect rates are about 15% to 50% lower.
  • There is a synergy of ideas. When you work on your own, you might get stuck easily. This rarely happens when working in pair. When you don’t know how to do something, the other probably knows it. Or you start talking about it and one idea leads to another, and soon enough you will come up with a solution.
  • Increased team morale. By working closely with someone, you get to know him. And you share responsibility. The code is no longer yours, it belongs to both of you.
  • Learning from each other. Chances are that each of you is more experienced in some area than the other one. By working together on a problem, you share that knowleadge. There is always something you can learn from your colleague. Be it high usage of keyboard shortcuts to increase productivity, or different way of thinking, better coding techniques, different set of tools.
  • Maintaining focus. When you work with someone you just can’t browse the internet or pretend that you are working 🙂 There is always something happening, either on the screen or between you when you talk about the problem at hand. It naturally helps you to maintain focus.
  • Time management. Set alarm clock to 20 minutes and then change places. 20-25 minutes is recommended time to maintain concentration. (But of course you don’t have to work in pair to use it.) See Pomodoro technique for more info.

These were the main positive points. What is the downside?

  • Pair programming is noisy. Unless you decide not to talk (I have never tried that), there is no way how to avoid being noisy, which might be distracting for your colleagues. It’s also easy to get excited over some idea or to get into a kind of friendly argument (which is OK 🙂 )
  • It might be more exhausting, simply because there is more things to pay attention to. Beside your usual IDE there is that other person. He talks, he takes “your” keyboard, he disturbs you by pointing out possible future bugs. He will almost certainly spot weak points in your code. And you might start rather a heated discussion quite easily.
  • Less code. But that might is actually a good thing :). Quality of software doesn’t count in lines of code, does it?
  • Sometimes you get stuck when working in pair too. Then two people are stuck instead of one. But it is not very often and usually for significantly shorter time then when the both of you work individually.

Some people love pair programming, some hate it. Someone is even scared of it. Let me quote Michael Dowling in cafe.elharo.com comment section:

That’s NOT the reason I *really* hated it, though. The reason I hated it is because – are you ready for this? – I might be wrong. Yes, there is a slim chance I could be wrong – dead wrong, stupid wrong, or better yet, absolutely completely “WTF were you thinking of implementing it this way you dumbass!” wrong – and my pair would find it and point it out to me. In other words, I was afraid of being naked.

The fear was being critiqued. But then I did it. And sure enough, I may – MAY – have done a few things in a less efficient manner. But something amazing happened – I learned. I learned a lot faster with someone at my side than I could ever have learned alone or during/after a formal code review. My pair helped me organize my thoughts – and funny enough, I helped my pair as well. My pair helped me get up to speed QUICKLY on the new system being developed. Faster than I could ever have done it alone.

I learned new development techniques that have stuck with me, even today. Things I’m not sure I could have learned on my own.

It’s not practise what makes perfect. It’s perfect practise. I believe that pair programming fits into the perfect practise category. It helps me to write better code.



Why to write a blog

This is rather a quotation than a regular blog post. It is a paragraph from book Getting Real by 37Signals. I could not say it better.

Hire good writers

If you are trying to decide between a few people to fill a position, always hire the better writer. It doesn’t matter if that person is a designer, programmer, marketer, salesperson, or whatever, the writing skills will pay off. Effective, concise writing and editing leads to effective, concise code, design, emails, instant messages, and more.

That’s because being a good writer is about more than words. Good writers know how to communicate. They make things easy to understand. They can put themselves in someone else’s shoes. They know what to omit. They think clearly. And those are the qualities you need.

An Organized Mind

Good writing skills are an indicator of an organized mind which is capable of arranging information and argument in a systematic fashion and also helping (not making) other people understand things. It spills over into code, personal communications, instant messaging (for those long-distance collaborations), and even such esoteric concepts as professionalism and reliability.

—Dustin J. Mitchell, developer (from Signal vs. Noise)

Clear Writing Leads To Clear Thinking

Clear writing leads to clear thinking. You don’t know what you know until you try to express it. Good writing is partly a matter of character. Instead of doing what’s easy for you, do what’s easy for your reader.

—Michael A. Covington, Professor of Computer Science at The University of Georgia
(from How to Write More Clearly, Think More Clearly, and Learn Complex Material More Easily)


Simple inheritance via jQuery.extend

Spoiler warning:

This is not true inheritance as we are used have to in static languages. It is not even prototypal inheritance. It is merely an experiment to find out if it is possible to achieve (mock) inheritance using jQuery.extend() method. And yes, it is kind of possible.

JQuery.extend basically copies properties from one object onto another. So in order to mock inheritance you have to extend instance (or instances) of ‘parent class’ with properties of another objects.

Here is how I did it:

$(function() {
  var Parent = function() {
    var that = this;
    this.name = 'david';
    this.getName = function() {
       return 'name is: ' + that.name;	 };
  var AnotherParent = function() {
     this.doSomething = function() {
       return 'I am a test...';	 }
  var SomeStaticClass = {
     staticVariable: 'I am static'
     , staticFunction: function() {	return 'some static value or whatever' }

  var result = $.extend(
    //read properties from instance not from function definition
    , new Parent()
    , new AnotherParent()
    , SomeStaticClass
    //read properties from some anonymous object -> overwrite properties from Parent
    , {tryIt: 'try it', getName: function() {return 'Name also is: ' + this.name}}


This is only simple case. If you are building a complex project and need inheritance, then it is probably better to use Dojo framework.

Inspiration from books

Recently I started to read a lot (thanks to Kindle text-to-speech feature) and I can see how books are broadening my mind. There is a lot of inspiration in (good) books, ideas and concepts you would not otherwise think about.  I want to share some of these great books. They are:

There is no need to comment on Rich Dad Poor Dad, as there was already written a lot. Even thou I don’t agree with everything Kiyosaki says, I recommend everyone to read it. And if possible to play the CashFlow game.

Moonwalking with Einstein is about memory and it’s history. It is very well written and raises few questions about quality of our current educational system. Most of what we have to learn in schools is shortly forgotten afterwards. We don’t know how to use our brain and it’s memory capacity. Nobody teaches us that. Is it really possible to remember everything? After I read this book I believe it is. Question is if it really worths the effort 🙂

Road to Serfdom. To put it in one sentence:  How the nice idea of equality and socialism turns into dictatorship. There is probably no other way. Once there is one central authority which plans what will be produced, in what quantity and for what price, then it necessarily leads to oppression. It is book about economics, but economics has actually its roots in psychology too.

Lucid Dreaming. Well… this one is very interesting. This is the only book I write about even before I have finished it. I added it to the list because it is really fascinating, but I will write about it later. I haven’t got any lucid dream yet, so I can’t really write about it. Anyone experience it?


Little jQuery.extend gotcha

jQuery.extend() is a very powerful function for merging two objects or for extending jQuery with custom plugins.

There is but one little gotcha to think about: as in most function calls the order of parameters matters 🙂

Following two fragments of code yields different objects

var a = {
  aa : '1'
  , bb : '2'
  , cc : '3'

var b = {
  aa : '11'
  , bb : '22'
  , dd: 3

var result_a = $.extend({}, true, a, b);
var result_b = $.extend({}, true, b, a);

The result will be this:

Notice that I use $.extend({}, true, a, b) instead of $.extend(a, b). The first parameter (which is optional) is the target which should receive merged properties. If none is given than the first object is extended automatically.

Criticism of AmWay, HerbaLife and Kiyosaki’s followers in general

Motto “Man speaks about what he doesn’t live”

I am reading Kiyosaki’s famous book Rich Dad, Poor Dad and I find it very inspiring. Kiyosaki is also the author of board game Cashflow. Both book and game are very good. But to play the game I had to find someone who has it. I met a group of people studying Kiyosaky’s books. They were members of some company but I did not find the actual name. I was told that the name is changing quite often, and that there is no single company but whole family of companies. They claim not to be AmWay or HerbaLife, because of the bad name these two companies gained in the past, but the principle behind this one is very similar.  For simplicity’s sake I will call these people Kiyosaky’s followers.

These people have one thing in common: They all dream about getting rich effortlessly. They promise you that your income will double in a few years for just one or two hours work a day. They promise it will not be just double, but multiple times higher than it is now. That’s very tempting, isn’t it? Who would not want it? But it is just an illusion. I think that most people from HerbaLife-like companies will never get rich. Here is why.

Bad Motivation

HerbaLife people want to get rich without actually creating anything valuable. They dream about driving a fancy car, getting up at 10 o’clock and living in Hawaii in a financial freedom. The don’t dream about running a startup, inventing something useful, building an killer app or contributing to the world. They are in fact just lazy dreamers.

Premature Satisfaction

You will be told on their meetings to tell your dreams aloud. I advise you not to do it. Because if you do and people will like your dream, they will tell you how great your dream is and how high-potential person your are. But you have not yet created anything and yet you have already received some kind of satisfaction. This will decrease your motivation to actually pursue your dream and full fill it. It is better if you just (humbly) write your dream down only for your self. Make a personal commitment  and follow it daily. Only after you have kept doing it for lets say half a year, and feel strong enough, tell someone about it. But only to small group of good friends who know you really trust. Don’t go public too early.

Creating money out of nothing

This is one of the things I don’t like about Kiyosaki. In one chapter he explains how he created lot of money out of nothing by buying confiscated house for a fraction of its price and selling it shortly afterwards for full price. He earned about 60 000$ in 5 hours. At the risk of being old fashioned I think this is kind of immoral. I understand that if he had not done than someone else would have. I am not naive, this world is hard and it will always be. But is it right to get rich on someone else’s misfortune? Do you have the stomach for it? If you do you are likely to become a rich asshole.


In general I agree with most of what Kiyosaki says, especially with his opinion on our educational system, but I just cant buy his idea of “creating money out of nothing”. Money comes out of people’s labour. Even if you invest in stocks or own a company. If you just create money (read “make money”), you are not creating something valuable but only green papers.


Convert local time to UTC time in Javascript

This might come in handy. Simple function which converts local time to UTC (Universal Coordinated Time). It accepts single argument of type Date.

//converts local time to UTC (Universal Time)
function toUTC(/*Date*/date) {
    return Date.UTC(
        , date.getMonth()
        , date.getDate()
        , date.getHours()
        , date.getMinutes()
        , date.getSeconds()
        , date.getMilliseconds()
} //toUTC()

Proposal for WordPress plugin – customScript

You will only see the demo animation if you click link to this post


For this blog I am using WordPress and I am quite happy with it, but I miss one feature – the ability to add
custom javascript code to given post. I do not want to have separate demo pages when I am want to demostrate
some piece of code or something. Sometimes I need it to modify the Html structure of page, or add a simple
animation or for whatever just crosses my mind:) I’ve tried to write my own wordpress plugin for this, but I don’t have enough time to finish it. I have already
spent three evenings on it. Writing a WP plugin proved to be much more difficult task than I thought it to be.
So I deciced to crowdsource the idea. Hopefully someone will read this and write the plugin 🙂 Anyway, there is a workaround, but it is not very convenient. And it requires access to file system, so it will
not work on wordpress.com hosting.


If you really need to add custom javascript to some Worpress code, use this workaround:

  • install Single Post Template Plugin by Nathan Rice
  • create your own template page for single post
  • it must contain
  • on the first lines:
  • /* Single Post Template: [Descriptive Template Name]
  • Description: This part is optional, but helpful for describing the Post Template */
  • wp_enqueue_script( ‘jquery’ );
  • Write your post
  • Choose the template you have created (see above)
  • Write the Javascript code you wish to run on this post in some editor
  • Minify it.  JSMinifier
  • Switch to HTML view
  • Add <code class=”customscript” style=”display:none;”>Replace-with-your-code</code>
  • Switch back to Visual view
  • Replace text in <code> with your minified javascript code. If you don’t minify it, you risk that WordPress will replace new lines with <br/> and breaks your code.
  • Go to Preview of your post. The javascript code in <code> should run.

Important notice

If your script needs some special HTML structure (as a placeholder or a container – as in my case), make sure you back it up somewhere. WordPress deletes empty html elements on save! Don’t forget that not everything you write in HTML view will actually stay there.


I am looking for someone who will write this WP plugin 🙂 Please.

The moving thing below is created via custom script. I do need a WP plugin for such demos.

PS: The animation is taken from RaphaelJS demos.

Problem with printing background images

I have recently wasted almost two hours trying to figure out why some HTML based report wont display logo in its header. I am quite sure this will make someone else’s life easier, so I am sharing it. The problem is that most browsers ignore background-image and background-color. So whatever I did I could only set border, width, heights etc but not the image. At first I thought the problem was in wrong path to background image.  It wasn’t but I found that it is not possible (at least as I know) to inspect DOM elements in print-preview. Something like Firebug but for print-preview. There is nothing like that.

How do you print images without using background-image?

Simply return to the good old <img> tag 🙂

Or if you need two different images for screen and print version then you have add them both to your page and set display via css. Like this.

<div class="header">
  <img src="bigImage.jpg" class="defaultImage"/>
  <img src="smallImage.jpg" class="printThisImage"/>
@media screen {
  .defaultImage {

  .printThisImage {

@media print {
  .defaultImage {

  .printThisImage {

Click here to see the demo.