Posts for Tag: development

Choosing a Ruby gem

Instead of writing yet another list of gems you should be using, i'll try to explain how i choose a gem for a particular task or function. This is by no means a complete checklist, it's just my typical way of going about things.

Rubygems

If you're a Ruby developer you are probably familiar with the website rubygems.org. It's "the" repository for all information about Ruby gems.

Things i find important when looking for a gem:

Number of total downloads

Though it will not tell you whether a gem is any good, it does tell you whether a lot of people looked at it as a good candidate for the job you need done. It's also an indicator for the community you can expect around this gem (helps when looking for tutorials, documentation, and general help).

Release date of the last versions

This will show you how frequently is the gem updated, which is useful to know how fast are fixes and new features introduced.

Sometimes it can happen that a really good gem hasn't had a release in a while. For example a couple of weeks ago i was looking for a gem that wrapped the Marvel Comics API. If you look for gems for that you find that most are really old. Doesn't mean they don't work properly, it just means that the API hasn't changed since and they are still relevant. When that's the case, i usually go for the one that was released last, just because the author had the gift of hindsight over the other ones and might have done a better, more polished job at it. Not always true, but... :)

Dependencies and License

To a lesser degree, i also take a look at these.

The less dependencies a gem has the lighter your code will be. Again, not always true, but it's a good rule of thumb. Also pay attention if the license is compatible with your own project.

    If a particular gem feels like a good candidate, I then visit its...

    ...Github/Repository/Website

    There, i usually check for a couple of things:

    Documentation

    This is how you learn how to use the gem, so it helps if the docs are really good (and maintained!).

    If it's an opensource project (which most gems are), then i also look for:

    Last commit date

    A clear indicator of the health of the gem. Also, take into consideration what i wrote earlier about gems that don't update often: it might be because they just don't need to.

    Number of contributors, commenters, discussions

    They show how active the community is around this gem. If big, it helps later when trying to find information how to do things if you get stuck, for example.

    Number of open issues (and resolved)

    If you take a glance at the last issues, when they were created, when they were replied to or resolved, this will also give you a good idea of how active the developers are, and how fast can you expect a response if you report something.

    Code

    Looking at the source code, though not as important as the rest, can also provide some insight to how performant, optimized the gem is at the job it does. It might also help you figure out if will be easy to monkey patch something to fit your needs later. And who knows, you mighty also learn something new from it :)

    Conclusion

    Though not (by any means) a complete guide for choosing a gem, this might be a good starting point. Also, some of these "metrics" might apply for choosing other software and code libraries.

    Like most things in life, your mileage may vary.

    Happy coding!

    Problem starting Sidekiq in development

    If you ever get this error:

    can't link outside actor context

    Followed by something like:

        /Library/Ruby/Gems/2.0.0/gems/celluloid-0.16.0/lib/celluloid.rb:176:in `new_link'
        /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/lib/sidekiq/launcher.rb:21:in `initialize'
        /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/lib/sidekiq/cli.rb:81:in `new'
        /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/lib/sidekiq/cli.rb:81:in `run'
        /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/bin/sidekiq:8:in `<top (required)>'
        /Library/Ruby/Gems/2.0.0/bin/sidekiq:23:in `load'
        /Library/Ruby/Gems/2.0.0/bin/sidekiq:23:in `<main>'

    It's mostly likely somehow related with either ZenTest or another testing framework. 

    In my case, i was adding the ZenTest gem both in the development and test groups of my Gemfile. Moving it away from the development group solved the problem.

    'New keyboard and KeyRemap4MacBook key bindings'

    Bought a new keyboard, the DAS Keyboard Professional S. Maybe now i'll finally learn how to code properly :)

    Also, took some time to create key bindings for media and brightness controls (for [KeyRemap4MacBook](https://pqrs.org/macosx/keyremap4macbook/)) for it. Feel free to use my private.xml file and modify as you see fit. The script will only modify keys when the external keyboard is connected. Also, you might need to use the app's EventViewer to change the Vendor and Device ID values :)

    I tried to get the sleep key to lock my mac, but i think i'll need to tinker with AppleScript to accomplish that one. Just haven't had the time yet.

    Here's the script:

    DAS 0x24f0

    DAS_KEYBOARD 0x0137

    KeyCode::VK_OPEN_URL_APP_Lock file:///Applications/QuickLock.app

    DAS Media Volume Mute private.das_vol_mute DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F1, KeyCode::VK_CONSUMERKEY_VOLUME_MUTE

    DAS Media Volume Down private.das_vol_down DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F2, KeyCode::VK_CONSUMERKEY_VOLUME_DOWN

    DAS Media Volume Up private.das_vol_up DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F3, KeyCode::VK_CONSUMERKEY_VOLUME_UP

    DAS Media Play/Pause private.das_play_pause DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F5, KeyCode::VK_CONSUMERKEY_MUSIC_PLAY

    DAS Media Prev private.das_prev DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F7, KeyCode::VK_CONSUMERKEY_MUSIC_PREV

    DAS Media Next private.das_next DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F8, KeyCode::VK_CONSUMERKEY_MUSIC_NEXT

    DAS Brightness Down private.das_brightness_down DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F9, KeyCode::VK_CONSUMERKEY_BRIGHTNESS_DOWN

    DAS Brightness Up private.das_brightness_up DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F10, KeyCode::VK_CONSUMERKEY_BRIGHTNESS_UP

    Lock private.das_lock __KeyToKey__ KeyCode::F12, KeyCode::VK_OPEN_URL_APP_Lock