subscribe via RSS

  • Sending Build Output to Vim [ruby, rust, vim]

    Vim is actually quite easy to build from source with a make install. You can edit src/Makefile to enable features and custom language extensions. Turns out, I hadn’t scrolled through that file in a while, since version 8.0.1295 comes with an interesting addition – the compilation flag --enable-autoservername.

    Running the editor with a --servername parameter allows remote connections from a different instance using command-line flags or function calls. I’ve been using this functionality to build a custom testing framework in Ruby, but you have to knowingly launch it with that flag. Now, each instance can be available to connect with by default.

    It’s not necessary, exactly – you could always make yourself a shell alias like alias vim="vim --servername VIM-$RANDOM". But the discovery gave me an idea of how to remove a tiny bit of friction from my Rust workflow, and I might end up using the same technique in the future. Read on to learn how to send your build output to a Vim instance for easier processing.

  • From Vim to Presentation Slides [talks, vim]

    There’s a little-known Vim command called :TOhtml that does something quite surprising for a built-in – it converts the current Vim window into raw HTML. This includes syntax highlighting for code, and even line numbers. It can convert the full buffer or a range of selected lines.

    While I’ve always considered it a fun trick, it was somewhat recently that I realized it has a very practical use – to paste syntax-highlighted code into presentation slides.

  • Testing in Rust: Writing to Stdout [rust, testing]

    For the last two years, I’ve been one of the organizers of an elective Rust course in Sofia University. Last semester, one of the homework assignments we came up with was to build several kinds of “logger” structs with buffering, multiple outputs, and with tagged logging. (The full assignment is here, but all the instructions are in Bulgarian.)

    It was a pretty good exercise on using Rc and RefCell that wasn’t a linked list or a similar data structure. The goal was to ensure a logger can be cloned, with the copies sharing both the same buffer and output.

    Testing the code seemed easy at first glance, but I did run into a bit of a problem when simulating loggers printing to “the screen”. The solution is not exactly complicated, but I think it’s a good pattern to share.

  • Testing in Rust: Temporary Files [rust, testing]

    I recently wrote a tool to manipulate images embedded in mp3 tags: id3-image. To be able to make changes to the code with confidence, I needed tests. Rust comes with the very sensible Write trait that could have allowed me to mock any IO (a blog post for another day), but in this case, the project relied on the excellent id3 crate, so I wasn’t doing any file-writing myself.

    Instead, I wanted to have an actual mp3 file and an actual image, apply my code to them, and inspect the results. This generally isn’t difficult to do, but I ran into a few unexpected gotchas, so I’ll summarize how I ended up implementing it.

  • Code Alignment [rules]

    Okay, this is going to be a bit bikesheddy. It’s about a code style rule that some people love and some people hate, and I have an ✨opinion✨ about. It’s not a particularly strong opinion, as in, if the team I’m working with disagrees with me, I have no issue following the popular vote. It’s a small enough thing that it might not matter in the long term.

    Let’s start by examining some code:

  • Building a Better gf Mapping [ember, vim]

    I recently started working with ember.js. It’s a nice framework, but, like most newish technologies, Vim support is minimal. So, as I usually do in such cases, I started working on some tools to help me out with navigation. Tim Pope’s projectionist helped a lot, but I wanted more, so I started building it up in what would later be published as ember_tools.

    The biggest feature was the gf mapping (“go to file”), which was inspired by the one in vim-rails. Using gf in a rails project almost always does “the right thing” for whatever you can think of. So, I poked around in that one, tried to figure out how it was implemented. In the process, I learned a few things and had a bunch of pretty good ideas, which I’ll talk about in this blog post.

  • The New(ish) Facebook Authentication Process [facebook, rails, ruby]

    Facebook changed their authentication process fairly recently. Instead of using a global user id, users would now get an app-specific id instead. This took me by surprise, and I had to jump through some hoops to get stuff to work with our setup. This is a short post that outlines what we did to work around the problem.

  • Small Refactorings [rails, ruby]

    A common piece of advice for dealing with bad rails code is to avoid making huge rewrites all at once. Instead, make small fixes whenever you see a problem. An often-cited variant of this is the “boyscout rule” – leave the code better than you found it.

    This is solid advice. Putting hacks and workarounds would only make things worse. Rewriting swaths of code for even small features would take a long amount of time and introduce risk. The best approach is to make small refactorings and build new features with new, better, code.

    As with most good advice, this can still backfire. Ever seen an app with five different caching mechanisms and seven different event tracking approaches, all slightly different? This may have been a result of multiple developers going “this is horrible, I’ll fix it”. In the end, they created an even larger mess, despite their good intentions. How did this happen?

  • The "Back to School" idea [education, talks]

    OHM was a place full of amazing ideas and clever hacks. In this atmosphere, a friend and I started talking about our education system and the age-old promise of “multimedia” in the classroom. It’s a popular topic these days, education. Startups like coursera are providing free online lessons, clever tools like geddit are trying to improve teacher-student interaction. What Vloo and me discussed was using presentation slides in class in order to improve engagement.

    Something like this is already in use in my home country of Bulgaria. There are specialized classrooms equipped with computers and projectors, and every once in a while, the students have an “interactive class”, where they watch videos and perform quizzes. However, this is something that happens rarely and is considered a “special” lesson. I was more interested in turning any lesson into an actual lecture. Just as lecturers at tech conferences teach me about the latest, greatest web framework, it should be perfectly possible to use the same tools for a chemistry, or biology, or history lecture.

    As we were describing what a lesson would look like, we realized we could actually prepare one. We dubbed the event “Back to School” and I started working on a chemistry lecture to present at the local hackerspace, initLab.

  • OHM 2013 [conferences, vim]

    I went to OHM (Observe, Hack, Make) this year, a hacker festival in the Netherlands. It was a fun week of camping, freedom talks, technology, retro-gaming and all sorts of other cool stuff. Since I was going there anyway, I decided to make a Vim event to spread word of the One True Editor.