Tag: Ruby

  • random_unique_id version 1.0.0 released

    random_unique_id version 1.0.0 released

    The core of random_unique_id was developed for Watu very early on, which means that it has been used in production for more than two years and a few thousands millions of records. It’s been released as a gem and we had a few iterations. It has 100% code coverage, code climate rating 4.0, 100% documentation coverage, a […]

  • Wrapped exceptions in Ruby

    Sometimes you want to raise an exception when a method fails but without losing information about an inner exception. Let me explain it with an example. At Watu we have a method that causes a user to be indexed in our search engine. This method is called many times in different situations. One of those […]

  • Making your app work with no data

    Most applications, web, desktop or mobile, handle some kind of data. When we are developing them we generally generate some sample data to play with and we forget to ever run the application without it. The problem is that the first impression people will get of our app is without data. And first impressions are […]

  • Full URL in Rails’ logs

    I find myself needing to have the full URLs in Rails’ logs. Normally you get something like: but I needed because the app does different things depending on the domain and when it fails, I have to know which URL was hit. The solution I ended up with was adding this in an initializer: That’s […]

  • Getting rid of RubyGems deprecation warnings

    A recent update to RubyGems is causing a lot of deprecation warnings like these: I generally like software to move forward and the way to do that is deprecate and then after a while, make backwards incompatible changes. It’s painful but there’s no other way. I do have a problem with all the cron jobs […]

  • Careful with that email

    When you are building systems like my Keep on Posting or my DNSk9 that send emails there’s always the danger that you’ll accidentally fire emails from your development machine to real users. You really don’t want to do that because it’s annoying and extremely unprofessional. It happened to me a couple of times. Thankfully, nothing […]

  • Rake tasks for production

    When I need to run something periodically on production, I always implement it as a rake tasks and install it as a cron job. Nevertheless there’s some setup to do in the task to have proper logging and error reporting. This is the template I use for creating those tasks: namespace :projectx do desc “Do […]

  • Another useful collection method? Enumerable#select_first

    For a personal project I’m working on, I need to find out the smallest time period with more than 5 records. I essentially wrote this code: period = [1.week, 1.month, 1.year].select_first do |period| Record.where(“published_at >= ?”, period.ago).count >= 5 end only to find out that the select_first method doesn’t exist. So I wrote it: module […]

  • A hash map method that returns a hash

    I’ve just released another gem, this one extends Hash to contain another method called hmap. This solves a problem I face ofter: how to run a map in a hash that returns another hash, for example: {:a => 1, :b => 2, :c => 3} being converted into {:a => 2, :b => 3, :c […]

  • Have a sense of humor

    I love it when company have a sense of humor that shows they are not enterprise drones but people like their users, with normally the same goals and intentions. Way to go JetBrains with your new install screen for RubyMine.