Specifying parameters encoding by action in Rails

At work I needed to accept a Windows-1250 encoding in URL parameters on some actions in one of our Rails API endpoint. The problem is that Rails will scream at you since everything needs to come as UTF-8. Future! Unfortunately some 3rd party Windows software might be still in the past… at that time I was trying to find a way how to write a middleware or patch Rails’ ActionPack to handle this request and what I found was actually a commit that adds this to Rails in master. Continue reading

Creating staging and other environments in Rails

Ruby on Rails come with three environments by default – development, testing and production. But sooner or later one has a need for staging environment. And don’t get me wrong, you can (or should?) use the production settings there, but if you run it locally or on the same server as production, chances are you need a different database. And while you are at it, it may be handy to allow logging to console or change any other of Rails settings for that matter. In fact you can create as many other environments as you want and since it’s really easy I encourage you to do so. Continue reading

Building and consuming JSON API with Crystal

When I firstly heard about Crystal language, I got really exited. It fixes exactly four problems I sometimes have with Ruby; types, speed, memory consumption and compilation to machine code. After many months silently following its development I decided to try it out for a simple program I need — a simple server standing between Google Maps API and my application to catch the geocoding responses in local Redis instance not to hit the limit imposed on using the service (plus, Google suggests you to do it anyway). Continue reading

What to do if Vagrant machine becomes unresponsive (KVM)

If you are using Vagrant with KVM (with vagrant-libvirt plugin) on Fedora, you might have experienced that sometimes the KVM virtual machine becomes unresponsive. Simply put you would wait forever for trying to ssh to the machine using vagrant ssh. It unfortunately happens to me sometimes when my laptop goes to sleep. So the simple answer is to avoid this and to always halt your Vagrant VMs when you finished working. Here is another thing to try out if you that happens and you don’t want to recreate the machine from scratch (vagrant destroy && vagrant up). Continue reading

DNS for your Vagrant needs: with Landrush, libvirt and dnsmasq

Have you ever needed a DNS server that would be visible both on your host and your Vagrant guests? Landrush is one of those things that can pretty much save you. Unfortunately it was designed around VirtualBox and Mac OS, so it does not work on Linux out-of-the-box. And it does not work with libvirt provider at all. Until of course recently since I added the support there. Here is how to make all that work together on Fedora. Continue reading

Debugging Vagrant with pry-byebug

What to do when running Vagrant with --debug flag is not enough? As Vagrant is nothing else than a Ruby program, you can use famous pry gem together with pry-byebug to debug it. The only thing you need to do to use pry from the Vagrant code base is to make sure it’s installed and available in the Vagrant environment. Continue reading