Enter Spacemacs!

It has been a great while since the last time I put up a blog post. I can’t say I have particularly good reason for this, part from trying to spend enough time studying for my last exam, which hopefully went well enough so that I soon can call myself an engineer :facepunch:.

Now on to the good stuff: I have to come to make a decision that may well impact my career as a developer! Nope, just kidding. I’ve decided to try out Spacemacs!. But what happened to Atom, you might ask? Nothing happened to Atom, I just figured I’d give something else a try. I rely heavily on plugins like vim-mode, so I figured: Why not use an editor where vim editing is a first-class citizen?

#editorwars

I also thought it would prove a useful experience to have my hand with Emacs. The eternal “Vi vs Emacs” war has been something that really has been that interesting to me, but I’ve heard stories from a whole lot of people having strong opinions regarding one of the two. Myself, I’ve been using Vim pretty much just for editing commit messages and while poking around at servers over SSH. I was not tied to my dotfile for this usage whatsoever, neither I using my dotfiles very extensively when configuring Atom. I figured there was not much for me to lose to try my hand with Spacemacs.

First steps -> spacing out(!)

The name Spacemacs comes from the fact that you end up pressing the spacebar A LOT. Both emacs and vim operate with a type of “leader key”, which is the key you press, then release, followed by a sequence of key to perform some action. Traditionally in emacs, this “leader key” combination has been C-x, i.e. Ctrl-x, but this cumbersome to type, and has lead to a number of hardcore emacs users RSI. For this reason, by default, Spacemacs uses Space as the leader key, allowing for swift access to to the most commonly used commands known from both vim and emacs. It also features the full power of the Emacs Lisp platform, but I have yet to delve properly into its depths. I’ve only heard the legends so far! :large_blue_diamond:

Is it worth it, then?

You may be wondering whether this “hassle” to learn using a new editor is really worth it. To be honest, I’m probably not the best person to ask about the matter lol, but I found Spacemacs easy to learn, especially if you have some experience in using vim. But whatever floats your boat: If you’re one of those wizards out there with a super-mega-ultra-awesome vim configuration, take pride in it and keep using it. But if you’re not particularly tied to your config, like yours truly, I recommend you at least give Spacemacs a try.

Until next time, happy coding! :smile_cat:

The rise of the Electrons!

Blogging like never before these days, probably to keep myself from studying for this final and starting my journey to become a glorious, certified programmer. (watch out, Java Programme I and II, daddy’s coming!)

This post is on my experience with the Electron ecosystem. I haven’t gotten around to using it that much myself, but I have enjoyed a set of applications built on top of it. The title of this post comes simply from me wanting to write about my experiences with using Electron-based applications. I think we have only come to see the beginning of these applications on desktop environments.

Atom

Atom is what gave life to the Electron framework, as it was born when the GitHub team working on the development of Atom, separated the application platform from the Atom core, originally naming it Atom Shell. I’ve been using Atom daily for the past year and a half or so, and it has never let me down. The ability to easily add custom shortcuts and actions and tweak the styling by editing Less and JavaScript files, makes it a very powerful tool for any developer from a frontend background. Check out my dotfiles repository for some examples on how I customize my Atom environment.

Nylas N1

The second application on the list of useful applications worth knowing about is N1, which is a an email client. It is part of a new force of applications utilizing a “synchronization engine” to act as the middleware between the client application and the IMAP, SMTP magic happening at the email providers. It does so by wrapping the interactions with the old protocols, in a REST API. The big downside with Nylas is that it requires you to either host the mentioned “sync engine” service yourself or pay for a premium membership to use the hosted service provided by Nylas, the startup developing the application. You get a month free trial when signing up, and if you don’t feel very attached to the features exclusive to the premium version, running a self-hosted version is not hard. I run it using Docker.

WebTorrent - stream those torrents instead!

I like to watch movies, and some movies are hard to come by, and one has to resort to the coolest illegal thing ever: torrents. Prior to discovering WebTorrent, I got by using whatever torrenting client provided by the OS, or one of the first three hits when I Googled it. WebTorrent has this cool feature that I never thought of: streaming. Instead of having to wait for the download to complete, it can play on-the-fly (I mostly use it to download videos). It also interacts nicely with video players like VLC, which is a plus!

HyperTerm

As a developer, the application “suffering” from the most keystrokes is (part from Atom) my terminal prompt. I’ve already written a post on how I use zsh. But one can go one step further, namely by taking control of the terminal application itself. I used by a Mac user, and a friend recommended using iTerm2, which I used until switching to Ubuntu. On Ubuntu I stuck with using the good-ol “Terminal” application, not giving any available options any further thought. That was until a few days ago at the time of writing this post: I discovered HyperTerm, which is built on Electron. It allows for so much easier configuration than the classical Terminal application of Debian, as it leverages the Web technologies made available by the Electron environment to customize the look-and-feel of the application. The startup time is about 1 second or so slower than for the built-in application, but since it is usually just running, and I don’t close and start whole windows as often as I do tabs, it is a fairly small price to pay.

Other applications

There will eventually be a small army of applications built on Electron, some of of which we are all going to use at some point. However, if you want to get a head start and check out some of the cool applications available, including the ones described in this post, the Electron team maintains a list of feature applications. Until next time! :dog::octocat:

Long live functional programming!

The following post is highly opinionated, and may cause you to yell :scream_cat: at your screen. Fear not! This is expected and no caution should be taken. Read on, and be glad you did! :traffic_light:

The time has come, dear readers: The time has come for us to embrace functional programming once and for all. Here comes the blog post we should regard as the Gospel of potential programming adventures, including my own. I will touch very briefly on some core concepts in said programming paradigm. If this is not enough to spark your interest in doing more functional programming, I’ll have to try harder in another post (which I will, with some practical examples, hopefully).

Side effects leads to anger…

The first programming language I learned to use (not counting MATLAB :sleeping:) was Python. Python is simple to learn, making a great language for beginners, but its simplicity is also its “worst enemy”. You can do anything, at ANY TIME. Read that sentence over. What does it imply? The answer is dead simple: CHAOS. With no restrictions of when to perform actions with possible side effects, there is no telling what may happen at a given time. A function claiming to give you the size of a list may actually do some crazy remote procedure call to some ominous website, handing over your info to the CIA! (extremely exaggerated, but you get the picture) Your code may drift towards becoming harder and harder to properly test, due to the lack of separation. But fear not, for there is a solution, and we call it: pure functional programming.

Pure functional programming: Drink the Kool-Aid!

To understand the term pure functional programming, one must go back to the roots of programming: mathematics. According to Wikipedia, a function is a relation between a set of inputs and a set of permissible outputs. The key to whether a function is pure, is the presence of any side effects. In the programming world, side effects are actions that take place during the execution of a function, that are not necessarily reflected in the returned value of the function call, but instead involve some mutation of state in the program otherwise. The first step to nirvana is to separate code considered pure from the one considered impure. This roughly equates to doing IO (file and network stuff) by itself, and make a whole lot of small functions that compose the transformation of the data you are working with.

Immutability: use it. PLEASE use it :stew:

This would turn into an awfully lengthy post if I were to go on and on about the cons of embracing the concept of immutability, and how it goes hand in hand with functional programming. Immutability is part of ensuring that a program enforces a clear separation of pure and impure code. I mentioned Python earlier, and it is a language where basically everything is comprised of objects, meaning that most pieces of data during the life of a program are mutable indeed. Other languages, such as Haskell and Elm, support immutability out-of-the-box.

Static typing: Compiling and other forms of wizardry

I’ve experimented a bit with Haskell lately (following this book), and I have fallen madly in love with the way it seems to predict what I want to do in many cases. this due to Haskell being statically typed, which allows the compiler to detect any anomalies in the program caused by passing parameter of the wrong type. This would never be possible in Python or JavaScript (unless one uses something like TypeScript or Flow), because they are dynamically typed, which has its own benefits.

This post may not have been as bold as it may have looked to be in the introduction, but maybe thats for the better? :rugby_football: I will definitely write more posts on functional programming, and they will be practically oriented.

Open Source Adventures

During the past year, while I should have spent most of my time writing my project and Master’s theses :stuck_out_tongue_winking_eye:, I discovered a whole new way of procrastinating: Contributing to open-source projects! I figured I might as well write something about some of my contributions. Perhaps some of you will feel inspired to make your first contribution or contribute to a whole new project!

Github-Utils: My first Atom package

When I first started using Atom, I was working as a summer intern at Capra Consulting. I was working a project along with two other interns, supervised by some of the junior developers at the company. We used GitHub to manage the source code and collaboration flow. While doing this, I got into using the open-on-github package to save some navigate on GitHub directly from Atom. Howver, I discovered that the package had a particular short-coming: it did not support opening pull requests, since this required communicating with the GitHub API. There you have it. Over the weekend I created the first version of the package and published it. A great experience in communicating the a terrific community and learning to wield some new tools (Coffeescript and ES2015, in particular). This turned out to be but the beginning of my journey in open-source contributions.

Hacking on Atom: enter vim-mode

I’ve already written a post on using vim keybindings. As a developer, one of the tools I use the most is Atom. Following this, one of the add-ons I interact with frequently is Atom’s vim-mode. I use the “traditional vim from time to time, either as I’m doing work on a server at the time, but do to being a little bit lazy at times :stuck_out_tongue_winking_eye:. When working with the “god-ol’” vim, I noticed that one of the traditional “motions”, where not implemented in Atom’s vim-mode, namely the ( and ) motions, which moves the cursor to the beginning of the current sentence, and to the next one, respectively.

I figured that implementing this action might be a nice way to start contributing to the Atom ecosystem, as similar actions were already implemented by other developers. I suspected that the code might involve something as easy as copying some of the existing code, and tweaking the regex used to detect sentences. Turns out, I was right! After a couple of hours wrestling with the proper regex (I can never get it right the first couple of times, and always result to asking some friends.

I have read page up and page down about how people encourage developers to contribute to open source projects, and how the initial feedback varies. I reckon myself fortunate in this situation, as I received nothing but constructive feedback. This had been a lot of fun! I had never realized how easy one can influence functionality of tools and plugins I use on a regular basis.

Other endeavors

After having the above contribution accepted, I started looking for other projects to contribute to. I will not go into detail on these the way I did earlier, as this post would become too long.

  • open-on-github: adding support for wiki-style urls at GitHub repositories for the prevously described Atom plugin.
  • Nylas N1: I added a fix for skipping the onboarding screen when being a non-premium user.

Apart from looking good when someone decides to Google you, contributing to open source projects is one of the best ways to learn software. I hope this post has inspired some of you readers to take up some open-source work yourselves. To rephrase: If it’s broken, fix it!”

Thank you, Docker

This post may well have a somewhat misleading title. I wanted to write a bit of an homeage to Docker, who has come to my rescue while being “trapped” in a hotel room.

Sunburns, ouch!

As I’m writing this post I’m sitting alone in my hotel room in Crete, the Greek island in the Mediterranean Ocean that happens to be FLOODED with Norwegian tourists at the time. Even though this blog is not intended to be something of a personal diary, it’s fun to put out there the reason why I ended up writing this post while on vacation. I should be out tanning or swimming, right?

Believe me, I have been tanning and swimming. Perhaps a bit too much, one might say. I have developed a bit of a tradition while vacationing over the years. It may be summed up like this:

  1. Get a bad sunburn the first day
  2. Spend the remainder of the vacation nursing my inflamed skin, adding fuel to the fire for the people that keep telling me that I should spend more time in the sun BEFORE going on vacation (not that they are wrong :expressionless:).

Docker to the rescue

As I had not intended to be a victim of my own pale skin, I had not thought to bring along my precious laptop, so that I may spend some time writing code or blogging. Luckily, my brother’s girlfriend brought her MacBook along (luckily in her hand luggage, because her suitcase is still nowhere to be found :worried:). It struck me that this was a great opportunity to see for myself how far Docker has come in terms of portability and usability. Just before heading off on vacation, I had successfully been able to run this site locally using a Docker image I found, providing Jekyll. If I could install Docker on the available MacBook, I could blog like never before!

Installing the Docker Toolbox

At the time of writing, there are two options for running Docker on a Mac. If it runs a recent version of OS X, there’s Docker for Mac. Unfortunately, the MacBook at hand was running OS X 10.9, while the minimum version required was 10.10 (Yosemite), so the remaining option for me was to have go with Docker Toolbox, which leverages VirtualBox to host a lightweight virtual machine to run the Docker daemon. This worked like a charm with two minor exceptions:

  1. I totally missed any info on which IP I would use to reach the virtual machine (naïvely, I reckoned it would be reachable at localhost, which turned out to be wrong). A quick search at DuckDuckGo remedied that issue rather quickly.
  2. When blogging, I enjoy the luxury of automatic rebuilding of the site. This was a bit tricky to pull off with Toolbox, but I eventually solved it by running Jekyll as jekyll serve --force_polling. Apparently it had to do with some file system quirk, that I didn’t bother delving any further into.

I can code again!

That’s it. Docker runs like it has never run before. What took the longest time was, in fact, downloading the software (I had to download Atom and GitHub Desktop as well, for different reasons), but after successfully downloading, there were no issues in installing them. Hopefully they’re just as easy to remove, as said MacBook is crammed with “junk” (images, movies and such) and is closing in on being full on storage.

If my condition persists, aka halfway roasted, I may even put out some more posts this week. Until then, enjoy the summer! I know I’m trying to :sunny::pizza: