Capture ideas and more with org-capture

I've recently started using org-capture. I heard great things about it long ago but never dag in on what it was, until I recently watched Rainer König's series on Getting yourself organized with OrgMode, which I can't recommend enough. In this article I'll explain how I understand it and use it. I'll leave a trick on the sleeve for a future post. What is org-capture? org-capture is a way to take notes in Emacs in an unobstructive way. [Read More]

Automatically refreshing files in Emacs

I like my editor to auto-refresh the file I'm visiting if it has changed on disc. To give a simple example, I tend to run the pessimize command after installing dependencies for a project. This adds version numbers to the project's Gemfile. But I usually do this right after adding or removing a gem from the file, which means it's almost a fact that the file will be opened in a buffer on Emacs. [Read More]

One step back

I don't believe in new year's resolutions, that's why I didn't make any this year (or any other for that matter). But what I did do is make some mid-term plans. One of them was to start blogging every day, not forever, but for 12 weeks. I also started exercising every day and, after some forced time of, I also needed to make up some work time. I'm trying to blog every single day because I have a goal to finish a book and to do some teaching and I think that making a habit of writing will help me achieve those goals. [Read More]

Running RSpec specs on a Virtual Machine from the outside with emacs

As we saw on the previous article, we can run our specs using rspec-mode in emacs. But when working with code behind a wall, such as a VM environment, there's a catch. We write code on the host machine (in a shared directory), but the specs need to be run inside the virtual machine. This means that, for one, we need to modify the running command to previously access the target environment and on the other hand, there's a high probability that our directory structure differs from one side to the other. [Read More]

Rspec-mode

Here's the basic TDD workflow: Write a test Run the tests Write enough code to make it pass Run the tests Refactor the code Run the tests Repeat Give or take that's how it works. If you take a quick look at that list, you're running the test suite after every change you make either in the code or the suite itself. [Read More]

Executing a command in a VirtualBox VM from the outside

At work, I regularly have to run scripts, tests or commands on a Virtual Machine. To do this, the common approach is to log in via SSH and then just run what I need to run. But sometimes, there are commands that need to be run repeatedly. VirtualBox allows us to do it from outside the machine by using vagrant ssh -c '<command>' <vm_name> which is a huge help. [Read More]

Hash#transform_keys

Ruby 2.5 introduced several new methods. Everyone is happy for yield_self (don't get my wrong, me too), but I'm very excited for one I've been waiting for: Hash#transform_keys. It does exactly what it name implies, it provides a way to transform each key on the Hash. What's the use for this? well, let's explore one of them. Say we're writing a method that takes a Hash and returns a Json string representing that hash for an API. [Read More]

Make parent directory if it doesn't exist when saving a file in Emacs

Sometimes I create a buffer by navigating into a directory that doesn't exist. For example, I create a brand new project (an empty dir), then navigate into <project_dir>/lib/<project_name>.rb. Emacs happily allows me to do this because buffers don't necessarily need to be bound to an actual file, so no problem there. The problem comes when I try to save. As the lib directory doesn't exist, I get an error. [Read More]

Algorithm for Secret Santa

In my family, we have the tradition of doing Secret Santa for gift exchange, so I wrote a small program that randomly selects pairs of gifters and receivers and then sends an email to each of them informing who they have to give a gift to. The first iteration of this problem was very convoluted, it tried to use an array of people and randomly select two of them, then it performed a series of checks in order to obey to the game's constraints: You can't give a gift to yourself You only give one gift You can only receive one gift You can't give to a person and receive from the same person (not sure if this is actually a rule, but in my mind it is) This solution is similar to most of other ones I've seen online. [Read More]

Renaming and deleting the current file in Emacs

There are multiple ways to delete a file in Emacs, but, as far as I know, they all require you to leave or find the file you want to operate on. At some point I came across the tip I'll share today, but unfortunately, I don't remember where I found it. Not having to leave the current buffer really speed up the delete/rename process and, for that purpose, I have two custom commands in my config File: =fdx/rename-current-buffer-file This command will try to rename the current buffer. [Read More]