Posty

Wyświetlanie postów z 2012

Retreat

If you know me well then you know that from time to time I try to do something good in my spare time. I speak at Ruby User Group which I love, I try to write Open Source libraries, I was one of the organizers of 1st wroc_love.rb edition and tried to help a little to organize the second edition. But as of today I give up.

I decided to devote all my spare time to fight with my health problems. In last 12 months I was 3 times in hospital, had 2 ear surgeries and as it turned out it was all for nothing. Or at least this is how I perceive it. Because a one tiny infection later and again I am practically deaf in one of my ear.

And that makes me really really sad. So sad that everything requires lot of effort. Working, smiling, everything. And I don't have that much energy when I am sick. I can only imagine how it is to be a healthy programmer. I would have so much time more if I didn't have to fight my illness. And I would love to spend it doing Open Source. I admire everyone who d…

Native system notifications in rails applications (development mode)

Obraz
Let's just say that from time to time you would like to display a notification on your screen of some event that occurred. As an example let's display a request time. The problem occurs when you work in heterogeneous environment and your friends use either linux or mac. In that case you might be tempted to define Gemfile as:


That is not going to work correctly and will lead to problems. Every time you run bundle install on different platform it will resolve dependencies differently and cause problems for your coworkers that are in the second operating system camp. And in worst scenario you will be hit when last Gemfile.lock is committed from Mac but you try to deploy to linux production server using bundle --deployment which is not allowed to recalculate dependencies. You can recognize it by the message "You have modified your Gemfile in development but did not check the resulting snapshot (Gemfile.lock) into version control".

What we basically want to achive is des…

Apotomo - API done right

Obraz
During the wroc_love.rb conference I had the opportunity to speak with Nick Sutterer (the original author and maintainer of great Cells and Apotomo gems) and thank him for the architectural choices made for the libraries. He said that I should blog about and help spread the good word instead of just telling him about the things that I like. So, here I am writing this post and keeping my promise.

The architectural choices are not obvious when reading Apotomo tutorial and probably they don't bring so much to most users of the library. Nevertheless they were extremely important to me. If you are not familiar with apotomo, just jump to the official website and Apotomo tutorial to get an idea of how it works.

Here is a little example of what we used apotomo widgets for:


Conceptually in apotomo it all starts in a controller.

But that's a very simple and basic thing you can do with apotomo. It all becomes much more interesting when you realize that the proc used by has_widgets method…

#drug.pl irc channel activity

Obraz

[PL] Nothing about programming

Obraz

Everything You Always Wanted to Know About Fibers * But Were Afraid to Ask

I recently found out that most Ruby developers that are not familiar with Event Machine usually knows very little about fibers. So I decided to share some very trivial examples that will help you understand them quickly. Each example should push your knowledge and imagination about possible usages a little further. Tell me in comments if that worked for you.

Example 1:


What happened here, you may ask. We created new fiber. At the begining it was stopped. So we resumed it. It executed and ended. Trying to resume it again did not work. Actually that was very similar to Proc except that we can always call Proc multiple times.

Example 2:


While being inside fiber we can yield. That means that fiber stops and control goes back to the line that resumed fiber. We resumed the fiber second time starting from where we escaped (yielded) previously.

Example 3:


As you see, you can return value from fiber when yielding out. That value is accessible to code that called fiber (resumed it). How is it acce…

Model logic

We all know that our models should be fat and controllers / views are supposed to be simple (dumb). Recently I was asked why such code should be put into model :


What's wrong with using Ad.unverified_ads.last in the view. I don't have an answer for the "why?" question often asked by beginner programmers. You can trust your more advanced colleagues that it should, that it is beneficial and will make your life easier or stick with your current way, wait until the application gets bigger, and regret it later. Anyway, I always ask myself one question when I have to decide whether something probably is part of the model. Would I need this method if the application had different way of interacting with the user. If it was a console application or just an API serving JSON to some clients. Given the previous code example. Can I image an usecase that requires me to display last unverified ad to user interacting with the program via command line. Yep, I can. Is it possible tha…

Active Reload - mission accomplished

Obraz
Once upon a time I was working on a big Rails application and every time I wanted to fix some CSS or JS issues I had to wait for a few seconds to reload the page which was making me really unproductive and unmotivated. I knew I was not the only one who suffered from such delays when working with big Rails apps. I occasionally spotted some comment about it here and there, in blog comments, reddit, rails forums. There were also other solutions that tried to fix the problem rails-dev-boost, rails_dev_mode_performance but had their limitations. So I decided to do something about. My initial trials were overcomplicated, error prone but eventually I created something that was working fine for my project. And it made my productive on that project again and much more happier. The solution was so incredibly simple (in concept and in materialization) that I still find it astonishing that no one before released such thing as a gem.

The fact that it was working for me meant nothing and proved not…