A case for 80-rule

The [in]famous 80 character line length limit, recommended and hated by so many, has caused thousands of manhours of endless debates, lost productivity and missed deadlines. This text is yet another attempt to reason with the opponents by exploring the history of characters per line limits and how they incidentally correlate with what has been known in typography for decades: line length affects comprehension effectiveness and especially so when we’re talking about code.

[Read More]

Disconsolate Puppeteering

The gross, the horror and the terror (basically a giant rant).

“The three types of terror: The Gross-out: the sight of a severed head tumbling down a flight of stairs, it’s when the lights go out and something green and slimy splatters against your arm. The Horror: the unnatural, spiders the size of bears, the dead waking up and walking around, it’s when the lights go out and something with claws grabs you by the arm. And the last and worse one: Terror, when you come home and notice everything you own had been taken away and replaced by an exact substitute. It’s when the lights go out and you feel something behind you, you hear it, you feel its breath against your ear, but when you turn around, there’s nothing there …” — Stephen King


There are numerous people out there who are better and more competent than me. I’m happy to have my mistakes corrected (maybe not ridiculed though, but hey — it’s the Internet) and hope to learn from them.

I’ve started working with Puppet around 5 years ago when I volunteered to fill the vacant position of “operations guy” at a small/mid sized company. Having some years of experience with Ruby, this opportunity was exciting and Puppet didn’t scare me much since I knew if worst comes to worst I can always throw in some binding.pry statements and feel very much at home.

Configuration management was a new field to me and major competitors at the time were (and still are) Puppet and Chef. After spending some time learning differences between the two, and even though Chef was pure Ruby inside-out, Puppet had won me over by virtue of using a declarative/ functional approach to describe infrastructure details and dependencies, and leaving the nitty-gritty details of OS-specific file/package/service management to the tool. Chef just felt much more mutable and procedural, maybe because Ruby inherently is (yes, yes, i know you can do functional Ruby) and people inescapably mess things up over time.

I firmly believe functional/declarative is the right approach to manage infrastructure, but after all these years I’ve witnessed how even this amazing idea can be horribly undermined by poor execution. This post has been brewing for the last ~4 years and spans multiple releases (0.28–4.5) and multiple minor and major upgrade events.

[Read More]
puppet  rant 

TinyRedis ruby client

Sometimes you don’t really want to add a gem dependency to talk to Redis server from your Ruby scripts. Here’s a piece of code you can just copy-paste and stop caring:

# Copyright 2017 Maksym Melnychok
# MIT License - https://opensource.org/licenses/MIT
# inspired by https://github.com/ptrofimov/tinyredisclient

require 'socket'

class TinyRedis
  RN = "\r\n"

  def initialize(host='localhost', port=6379)
    @socket = TCPSocket.new(host, port)

  def method_missing(method, *args)
    args.unshift method
    data = ["*#{args.size}", *args.map {|arg| "$#{arg.to_s.size}#{RN}#{arg}"}]
    @socket.write(data.join(RN) << RN)

  def parse_response
    case line = @socket.gets
    when /^\+(.*)\r\n$/ then $1
    when /^:(\d+)\r\n$/ then $1.to_i
    when /^-(.*)\r\n$/  then raise "Redis error: #{$1}"
    when /^\$([-\d]+)\r\n$/
      $1.to_i >= 0 ? @socket.read($1.to_i+2)[0..-3] : nil
    when /^\*([-\d]+)\r\n$/
      $1.to_i > 0 ? (1..$1.to_i).inject([]) { |a,_| a << parse_response } : nil
  def close

Also as a Github repo.

ruby  redis 

Crypto-index calculator

Do I buy Bitcoin? Maybe Ethereum? What about Ripple? And how much?

FEAR NOT! Here’s a little tool to help you answer these questions: Crypto-index calculator.

The calculator will fetch market data from Coinmarketcap API and tell you how to optimally re-balance your positions according to capitalization-weighted index (does not take into account fees and volume yet).

None of this is investment advise.


Did not find object for shallow <sha>

If you’re in a rush just mash those buttons:

vim .git/shallow↵
/<paste offending sha>↵

In plain english - remove the sha you’re getting in error message from .git/shallow file. You supposedly have a shallow copy of a repository and in that mode git sends contents of .git/shallow to remote you’re pulling from so that it knows what to send down the internet pipes. And one of those lines in shallow file is referencing an object that has been GCed from the repository.