Parsing Binary Data With Node.js

I’ll start by highlighting some of the pillars of binary data, hopefully in a breeze. If you find yourself very attracted to these topics, I recommend this book (you can skip the HLA/assembly parts). Also note that it’s a bit oldschool (I read that more than 10 years ago but it left quite an impression) so there may be newer and better resources to learn from.

Words

A “computer” word, is a sort of unit of grouping of bits. For example, a word can be 8, 16, 32, 64 etc, bits wide. Typically a word’s width is coupled to the CPU’s architecture’s width (i.e. 64bit CPU) but in our case, we’ll treat the meaning of word as “a set of N fixed-size bits” where N is the number of bits.

Endianness

The term “endian” comes from “end”. When you look at a sequence of bytes and want to convert a group of bytes to a plain old number, it stands to denote which end of the number is first; in the case of big endian the first part is the bigger one. In the case of little endian the first part is the little one.

For example, there are two ways to look at the couple of bytes appearing in a binary file: 01 23.

Asset Pipeline Internals

Almost a year ago, I wrote about build management for Javascript projects.

In a hindsight a year proved to be a ton of time on the client-side.

Most notably Grunt (which I only mentioned briefly) took off like a rocket, and in the same manner Yeoman - which I almost instantly considered a swiss army knife for doing my client-side only projects.

Yeoman though, which relies on Grunt, is going through some fundamental changes and looks like it is being re-arranged and re-planned for a while now.

For what it’s worth I do support the new Yeoman changes, but instead of waiting for it to crystalize I tought it is time to re-evaluate what’s out there today and see if Yeoman can be replaced altogather (the answer is ‘Yes’, keep reading :).

ZeroMQ and Ruby a Practical Example

For a specific high-performance workloads, I wanted to include a new and highly optimized endpoint onto Roundtrip.

If you don’t know what Roundtrip is yet, feel free to quickly check out the previous Roundtrip post and come back once you got the idea of what it does.

I had to select both a wire protocol and an actual transport that will be very efficient. To gain an even higher margin over HTTP, I knew I wanted it to be at least binary and not very chatty.

A good option for this would be Thrift, for example. However I wanted to go as low as I could, because I didn’t really need anything more than the bare simplest RPC mechanism.

However, going with straight up TCP wouldn’t gain me much because I typically hold development ease and maintainability as an additional value. There was only one thing I felt offering an awesome development model and being as close to (or even better than, on some occasions) TCP…

Tracking Your Business

You’ve built (or are maintaining) a product which has many services that span over different machines at the backend. These services are all orchestrating together to implement one or many more business processes.

How are you tracking it?

Pragmatic Concurrency With Ruby

I’m coming from a parallel computation, distributed systems background by education, and have relatively strong foundations in infrastructural concurrent/parallel libraries and products that I’ve built and maintained over the years both on the JVM and .Net.

Recently, I’ve dedicated more and more time building and deploying real concurrent projects with Ruby using JRuby, as opposed to developing with Ruby (MRI) with concurrency the way it is (process-level and GIL thread-level). I’d like to share some of that with you.

Feel free to bug me on twitter:

Administrative notes«EOF:

This may come as a lengthy information-packed read. You can put the blame on me for this one because I wanted to increase the value for the reader as much as possible and pack something that could have been a lengthy book, into a single highly concentrated no-bullshit article.

As an experiment, I also put most of the example code in a repository including the source of this article. Please feel free to fork and apply contributions of any kind, I’ll gladly accept pull requests.

Github repo: https://github.com/jondot/pcwr

EOF

Translations

This article was recently translated to Serbo-Croatian language by Anja Skrba from Webhostinggeeks.com - Thanks Anja!

Concurrency is Awesome!

Remember those old 8-bit games you used to play as a child?. In a hindsight - you know its awesome, but if you’re a gamer or just a casual gamer, and you’re forced to play it today, the graphics will feel bad.

This is because it’s a detail thing; just like childhood computer games, as time passes, it seems like your brain doesn’t care (or forgets) the proper details.

So given that one is an MRI Ruby developer, her mindset would be that concurrency just works, and it is easy and awesome. But you might be right guessing that due to the level of cynicism going around here - it isn’t the end of it.

The MRI Ruby GIL is gracefully keeping some details away from you: yes things are running in parallel with the help of properly built I/O libraries (for example: historically, the MySQL gem was initially not doing it properly, which meant your thread would block on I/O), but surely, code isn’t running in parallel. It’s just like what your brain did when it covered up for those horrific 8-bit graphics that you were sure are still awesome.

Building Your Tools With Thor

Thor is not new; first built as a rake and sake replacement, first commit is well over 4 years ago.

Jump ahead several years and Thor is part of the foundation of the new-generation rails generator, and very popular tools such as Bundler and Foreman.

Recently, @wykatz emerged a fantastic looking (and much deserved) Thor website, and although I’ve started doing Thor based projects over two years ago, I think its the right time to write about Thor itself.

Today, Thor can serve as a rake replacement, great generator building framework, and a general purpose CLI toolkit.

First Look at Mruby

mruby is minimalistic Ruby, developed by Matz (Ruby’s creator) and funded by the Japanese ministry of Economy.

I’ve been waiting for this to go public since Matz’ early announcements of him being working on it. This is very exciting.

Installing

  $ git clone https://github.com/mruby/mruby
  $ make

Compilation is a fantastic error-less breeze, around 20 seconds.

Hello mruby

Lets see how this thing should work.

$ cd bin
$ cat > hello.rb
puts "hello mruby!"
^D
$ ./mruby hello.rb
hello mruby!

Programming Is a Culture

tl;dr

You might or might not have heard about the 501 manifesto. A 501 programmer is the one that runs out of the office at 5:01, regardless of any importance of him staying and keep his responsibilities aligned.

While I do believe in family values and socializing, I think that part of the manifesto is pretty generic, and the addendum of pitying open source or programmers who love what they’re doing is pretty insulting. We (programmers) are a culture now, and usually the passionate ones are the ones that are being mocked.

Fast ID Generation Part I

Update: Hello HN!, Please use this for discussion

tl;dr

In a distributed storage environment you may no longer generate IDs in traditional ways. You need a fast service that generates IDs, which, given constraints such as bit size, isn’t obvious to build.

Twitter’s Snowflake does it following a set of their own constraints, but given more lenient constraints there are other ways such as compositing an ID with a time component and random jitter. There are also important risks and guarantees to take into consideration.

Parting Ways with Auto Increments

You want to generate IDs when you’re working in a sharded setup; in which non of the shards can take responsibility for generating IDs on its own.

Further, you might want an independent service or component to be responsible for ID generation, in a complex transactional usecases, where multiple systems might be affected.

In other cases you’ll want to perform intricate tracking which requires generation at the client side, or far from the server.

Build Management for Javascript, Coffescript and Friends

Update, 16-feb: I’ve added Brewer.js to the review.

tl;dr

Find a tool that can compile coffeescript, take javascripts and vendor javascript libs, join them preserving order, and minify them into one file good for release. If that tool can do CSS/stylus/sass all the better. I pick sprockets eventually and show how you can tailor it to your needs.