(a bit of) whitespace

Has someone just said “lowlevel”?

Let’s Play With Ruby Code

Are you tired of aligning those pesky equality signs by hand? Do you obsess over using (or not using) and, do and then? Do you want to enforce your corporative style guide without fixing all the indentation by hand?

All of the above, and without accidentally breaking code structure and unrelated formatting?

Parser has you covered.

Unmentioned Features of Ruby 2.0

It has been a while since the release of Ruby 2.0, and a lot of comprehensive guides to the new 2.0 features were written. However, I feel that some of them are still left in obscurity. The justice shall be served.

Ruby Hacking Guide Ch. 11: Finite-state Scanner

Foreword

The following is a translation of a single chapter from a Japanese book Ruby Hacking Guide (Rubyソースコード完全解説, ISBN 4-8443-1721-0), written for the people who want to understand the source code of Ruby MRI better. The book covers Ruby 1.7.3; however, the parts of parse.y discussed in this chapter are still the same in Ruby 2.0.

I’m very grateful to my employer Evil Martians, who sponsored the work, and Nikolay Konovalenko, who put more effort in this translation than I could ever wish for. Without them, I would be still figuring out what COND_LEXPOP() actually does.

Rack::UTF8Sanitizer

Do you have a bunch of these errors in your Airbrake, Honeybadger, Ratch… er, Rollbar or whatever’s the trending error reporting app?

1
2
3
4
#123430: ActiveRecord::StatementInvalid in releases # show in production
ActiveRecord::StatementInvalid: PG::Error: ERROR: invalid byte sequence for encoding "UTF8":
0xd1 0xf0 : INSERT INTO "raw_stats" ("collected_at", "kind", "resource_id", "resource_type",
"site_id", "user_agent", "utm_source_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"

I do. And one day, I’ve finally had enough of these bogus reports.

Meet Rack::UTF8Sanitizer! Install it, enable it, and forget about encoding bugs for the rest of your life.

A Language for Embedded Developers

I am currently working on a dialect of Ruby well-suited for programing embedded systems. My goals are to make it fast, flexible and predictable while not giving up the convenience which Ruby offers.

This article is primarily targeted at software engineers working on embedded systems and other low-level software, and does not require any prior knowledge of Ruby. Everyone else is welcome as well.

Parsing Ruby

Suppose you need to parse a chunk of Ruby code (and by Ruby I obviously mean Ruby 1.9). What options do you have?

Why Raspberry Pi Is Unsuitable for Education

Raspberry Pi was designed for education. As any popular product is bound to, Raspberry Pi has been criticized a lot (Lateral Opinion and C&Y are typical examples) for things like lack of a box, absence of supplied charger or even WiFi.

Seriously, since the EU bill everyone has a spare micro-USB charger, and kids have suitable boxes in abundance. Most importantly, these problems are solvable: you might need to buy an USB hub or dig through some old stuff to find a forgotten micro-SD card, but that’s it.

Raspberry Pi has a much more fundamental flaw, which directly conflicts with its original goal: it is a black box tightly sealed with patents and protected by corporations. It isn’t even remotely an open platform.

Let’s Destroy Flash Together

Adobe Flash is obsolete. It is a proprietary technology controlled by a single company, it has hundreds of gaping security holes, it drains battery like crazy, it is not supported anymore on mobile devices (Apple, Google and Microsoft) and Linux. Even Adobe themselves think that Flash should die; let’s help them to weed the garden!

Quite a few people are still relying on Flash for publishing dynamic content. One of their reasons is, apparently, the possibility of code protection (1, 2, 3, 4, etc.) This is plain wrong: there is no viable code protection in Flash. I’m going to prove this once and for all.

Reaching the Limits of Adobe Stupidity

Lately, I’ve been working on Flash ActionScript 3 decompiler, and I noticed an interesting pattern. Normally, if you work with a piece of well-known software and something goes wrong, it’s your fault. But with Flash it’s not anything like that! If it doesn’t work, then it’s probably a bug in the compiler which was preserved for compatibility. Or the specification is plain wrong. Or it’s a bug in the compiler which no one noticed or attributed to cosmic rays instead.

I’ll give a few examples.

Statically Compiled Ruby

Ruby is a very dynamic language by its nature, and it has quite a generalized interface. Everything is an object, objects communicate only by sending messages to each other, variables are untyped and everything can be modified at runtime, even (almost) any of the builtins.

This has a serious drawback, through: evaluating Ruby code is a slow process. Even when you have an expression like 5 + 2 (which is syntactic sugar for 5.+(2)), one cannot safely assume that + method has not been redefined as something completely different. Thus, one is required to follow the generic method lookup procedure, which isn’t trivial at all and therefore isn’t fast either.

I have found a way, through, to significantly improve Ruby code performance by restricting just a few of its metaprogramming capabilities.