Articles tagged as “ruby”

On Ruby modules and concerns

Modules are useful for highly specialized code that can be injected into other classes for fun and profit or for creating Namespaces. An interesting approach is to use modules as an alternative to classical inheritance (without its the usual trade-offs) : the core idea is to share an abstracted role that can be inclu ...

read more

On semantic Ruby block constructs

I was cruising around my Github notifications and I found an interesting open issue created by Jim Weirich : “The Semantic Rule for { } VS do/end” in the Ruby style guide repository .

>The semantic rule says use { } for blocks where the primary purpose of the block is t ...

read more

On Ruby 2.0 memory usage, Unicorn and Heroku

On UNIX-like operating systems (e.g. Linux) there's the concept of process forking via the fork() system call. When one calls fork from a parent-process it will spawn a new child-process - that is a copy of its parent, then both processes return from fork. The child-process has an exact copy of the parent's memory in ...

read more

Improve Rails performance by adding a few gems

Working with Rails for some time you start nitpicking on how to improve it. This is a first in the series of articles regarding on how to improve (even marginally) Rails's performance.

I'll focus on a bunch of gems that speed up, in some cases considerably, small parts of Rails, like the html escaping, the String#bla ...

read more

Is Rubinius 2.2.3 production ready ?

Ruby 2.1 was released this Christmas, great news everyone! It sports a better GC (RGenGC - gerational GC), hierarchical method caching, some small syntax changes and non-experimental rafinements. All in all one can expect 5% to 15% performance increase which is quite awesome.

As I was reading the comments in the hack ...

read more

Chunked transfer encoding in Rails (streaming)

Anyone that has written a little PHP knows what the flush() family of functions do. The ideal usage scenario for using chunked transfer[0] is when we have something costly to render e.g. the first three most recent articles on a blog. Why ? one might ask.

Is rather simple: in a normal request where the server respo ...

read more

Shedding some light into UUID version 4 in Ruby and Rails

Ruby's standard library and Rails's PostgreSQL adapter use by default version 4 UUIDs. This can be changed in Rails migrations via:

default: 'uuid_generate_v1()'

param whereas Ruby's stdlib only supports version 4.

Another interesting difference is in the implementations:

In the Ruby's s ...
read more

Using RVM for quite some time? You should clean it up a bit

I can't even remember the last time I ran rvm implode, I'd reckon I've been using RVM for about three years.

Sure: I always update it via rvm get stable but I never really clean up old Rubys or gems, I only run bundle clean --force in each repository from time to time since I don't always use bundle exec.

...

read more

Programming archaeology: PHP's dollar sigil

I started out with Java as my professional language and before I discovered Ruby, PHP was my main programming language of choice for new projects. This was probably six to seven years ago or more. I had some pretty good times with CodeIgniter [0] and various libraries like HHMVC [1].

In any case, I digress - even ba ...

read more

The perils of writing request specs using concurrent-ruby under the JVM

When I write an API, though I'm not a hard core TDD practitioner, I do like writing specs - especially requests specs that test the whole stack.

Adding them into an API is fast and yields quite good results compared to an app with an UI where you have to use chrome-cli or phantomjs just to get near of that level but ...

read more

Interesting links - Is logging a "code smell" ?

I was reading this article it raises quite an unexpected question - "Can we consider logging as a code smell"?

Clearly - the answer is more nuanced than that and whilst I do enjoy the event bus approach from the article - that seems like overkill for m ...

read more

Moving from iTerm2 to Kitty for simplicity and performance

I love iTerm2, but it can be sluggish sometimes on my old late 2016 MacBook Pro. Plus, many of its features I never use. I had tried Alacritty before, but making it look and act like iTerm2 was a no-go. This time, I tried Kitty, and within two hours of work, it looked and behaved just like my iTerm2 configuration. This ...

read more