Posty

Ruby vs Kotlin: Custom Comparable classes

Often it's nice to be able to sort custom objects and compare which one is bigger or smaller. Today we are going to implement such MyDate class in Ruby and Kotlin. I found it interesting that interfaces in Kotlin, similarly to modules in Ruby, can contain an implementation. Let's see a very simple example.

First in Ruby:

class MyDate < Struct.new(:year, :month, :day_of_month)
  include Comparable

  def <=>(other)
    diff_year = year - other.year
    return diff_year if diff_year.nonzero?

    diff_month = month - other.month
    return diff_month if diff_month.nonzero?

    day_of_month - other.day_of_month
  end
end

def check_in_range(date, first, last)
  Range.new(first, last).cover?(date)
end


and now in Kotlin.

data class MyDate(
  val year: Int, 
  val month: Int, 
  val dayOfMonth: Int
) : Comparable {
    override operator fun compareTo(other: MyDate): Int {
        val diffYear = year - other.year
        if (diffYear != 0) { return diffYear }

        val diffMonth = month - other.mo…

Ruby vs Kotlin syntax for lambdas

The same code expressed in Kotlin

orders.flatMap{ it.products }
orders.flatMap(Order::products)
orders.flatMap{ o -> o.products }

and Ruby:

orders.flat_map(&:products)
orders.flat_map{|o| o.products }

re-enable tray icons in ubuntu 13.10?

sudo apt-get install libappindicator1
sudo add-apt-repository ppa:mc3man/systray-white
sudo apt-get update; sudo apt-get dist-upgrade gsettings set com.canonical.Unity.Panel systray-whitelist "['all']" # log in again
More on this sad subject: https://bugs.launchpad.net/ayatana-design/+bug/974480https://bugs.launchpad.net/ayatana-ubuntu/+bug/1119420http://askubuntu.com/questions/362135/how-to-re-enable-tray-icons-for-applications-in-ubuntu-13-10https://launchpad.net/~mc3man/+archive/systray-whitehttp://www.ubuntugeek.com/ubuntu-tip-simplified-way-to-add-ppa-repositories-in-karmic.html

[PL] Czym jest dla mnie praca zdalna ?

Chciałem napisać kilka słów o pracy zdalnej. Jak ją postrzegam z mojego osobistego punktu widzenia.

Schronienie w czasie burzy

Kto mnie zna, ten wie, że w poprzednim oraz tym roku dużo chorowałem, jeździłem po szpitalach i lekarzach, urzędach, doradach, kupowałem mieszkanie, przeprowadzałem się i brałem ślub. Na szczęści, przy pracy zdalnej, nie jest to tak duży problem. W szczególności, jeśli jako cała firma  praktykujemy pracęw sposób asynchroniczny. Zatem jeśli akurat boli Cię głowa, musisz iść na pocztę, do lekarza, wyremontować dom albo sąsiad wierci. Nie ma sprawy. Dwa słowa "będę później" i cały zespół jest w stanie sobie poradzić.

Oczywiście można to wszystko ogarnąć pracując z biura też. Pytanie na jak długo i na jak często? Jeden wyjątkowy raz? Co jeśli boli Cię głowa przez dwa miesiące codziennie ? Ja tak miałem. Nie wiem co byłbym w stanie w tym czasie zrobić z biura. Chyba bym tylko wszystkim przeszkadzał.

Kultura firmy

Nawet jeśli możesz pracować zdalnie od czasu…

Rails acceptance testing with Virtual Machines

I often test software on Vagrant virtual machines. Sometimes however they use real browsers and require some X server running. This is often the case when using Cucumber, Capybara, Selenium and Firefox. When everything is running smoothly we usually use at +Arkency  one of this:

xvfb-run -a bundle exec rake cucumber
xvfb-run -a bundle exec cucumber features/name.feature:line_number

It is however sometimes useful to see the tests being executed. For that I use:

Xvfb -screen 0 1280x1024x24 -ac
DISPLAY=:0 ratpoison
x11vnc -display :0
DISPLAY=:0 bundle exec rake cucumber

And connect to the Vagrant machine using Vinagre.

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…