STERE
OBOOS
TERBL
OG

Collection of my ideas and thoughts. Think of it like a place where each idea gets its own URL.

Linux Performance Tools

2017-02-10 01:47ZLinux KernelOperating SystemCPUInterconnectMemoryBusCPU1DRAMI/O BusExpander InterconnectInterface TransportsI/O BridgeI/O ControllerDiskDiskSwapNetwork ControllerPortPortVarious, observability:http://www.brendangregg.com/linuxperf.html 2017Power SupplyFANFirmwareApplicationsSystem Call InterfaceVFSFile SystemsVolume ManagerBlock Device Int.SocketsTCP/UDPIPEthernetSchedulerVirtual MemorySystem LibrariesDevice DriversClocksourcelsofpcstatobservability toolsstyle inspired by reddit.com/u/redcttop htop ps pidstatstraceperf tracesysdigpidstat -dperfftracestaplttngbcc(BPF)iostatiotopblktraceGPUswapon -s/proc/swapsethtoolifconfigsnmpgetlldptoolnicstatnetstatiptcpdumpnetstatiptraf-ngperftiptopvmstatslabtop free/proc/meminfonumastattiptopperf pcmturbostatrdmsrmpstatpowertop/proc/statssltracesar -m FANLinux Performance ToolsHardwarestatic performance toolsdf -hmdadm lvmdmsetupstorcliMegaClilsblk lsscsi blockdevsmartctl fdisk -llspci lsusbldd/proc/cpuinfocpuid lscpulstoponumactlApp Configmultipathiprouteiptables/sys/...sar /procdstat dmesgVarious, static:sysctl /sysdmesg lshwjournalctllsmodopensnoop statsnoopsyncsnoopperf-tools/bcc tracing toolshttps://github.com/brendangregg/perf-tools https://github.com/iovisor/bcccpudist execsnooprunlat cpudistoffcputimefunccountfunclatencystackcountkprobeuprobeargdisttraceprofileext4slowerext4distbtrfs*xfs*zfs*cachestat dcsnoopfiletop fileslowermountsnoopbiotop biosnoopbiolatency bitesizememleak oomkillslabratetopgethostlatencytcptop tcplifetcpconnect tcpaccepttcpconnlat tcpretransmdflushhardirqsttysnoopintel_gpu_topintel_gpu_timeintel_gpu_\frequencyipmitooldmidecodelatencytopllcstatprofileVarious, tracing:capabledmesgschedtoolthese can observe the state of the system at rest, without loadugc ucallsmysqld_qslower, ...

Source: http://www.brendangregg.com/linuxperf.html

Do not know who made this, but this is awesome example of pictograms for programming paradigms. Want pictograms for categories.

source

Dynamic type system

Dynamic type system: ES6 almost LISP (Scheme)

Given the fact that ES6 has dynamic type system, higher order functions (e.g. functions which can accept and/or return other function), tail call optimisation (TCO), brings ES6 to level of LISP (Scheme).

First time this idea was suggested by Douglas Crockford. But Crockford suggested it when there was no TCO in standard.

With TCO and fat arrow (=>) ES6 become closer to LISP (in some aspects) e.g. you can take SICP and implement all examples using ES6. Yay!

Side note: there exist variations of LISP with static type system, but historically LISP was dynamically typed.

About testing

Mental barrier

Next time you will think something is impossible, take some time to reconsider

History repeating: public fear

history repeating

I wanted to compare public fear of GMO with public fear of vaccination in early periods of smallpox vaccine development. But it appears that it wasn’t so irrational fear: there were death accidents and other negative consequences in early stages of research. My initial purpose was to show, that fear of GMO is irrational, but my approach was wrong.

I’m trying to be scientific and objective. Still sometimes I fail and use logic fallacies. Errare humanum est.

This meant to be series of “history repeating” posts: to show recurring patterns in history.

The word is about, there’s something evolving,
whatever may come, the world keeps revolving.
They say the next big thing is here,
that the revolution’s near,
but to me it seems quite clear
that it’s all just a little bit of history repeating

History Repeating - Shirley Bassey

In the early empirical days of vaccination, before Louis Pasteur's work on establishing the germ theory and Lister's on antisepsis and asepsis, there was considerable cross-infection

Source: <a href=https://en.wikipedia.org/wiki/Smallpox_vaccine>Wikipedia</a>

Anti-GMO organization exploits public fear to fight with genetic engineering

In case of smallpox vaccination, experimentation was done before there was strong scientific theory developed. There were errors. So caricature by James Gillray depicting the early controversy surrounding Jenner’s vaccination theory had some ground behind it. While anti GMO-poster simply using public fear without any background or research.

See also:

TL;DR There is no one “canonical” definition of OOP. There are at least two of them. From my POV there are two big definitions, which deserves separate names. I named them after biggest advocates. Those two definition have some differences and some commonalities.

I was about to get into another argue on OOP on the internet. I decided to do some research on the subject. I found more than one definition of OOP. Some of the definitions are variations of the same “tune”, some are useless. On my opinion there are two main directions of thoughts in this domain, which from two schools of OOP. School as in school of thought. The same way as there were philosophical schools in ancient Greece. The same way there are two schools of OOP:

  • Alan Kay’s school or message focused
  • Bjarne Stroustrup’s school or class focused or “PolymorphismEncapsulationInheritance” in terms of c2

I must emphasize that this article is not about what is best way to do OOP, because such discussion will lead to holy war. Instead purpose of this article is to help to recognize the fact that there are two ways to think about OOP. I believe this will help to build more constructive discussions about OOP. Next time you will start discussion on OOP or OOP vs make sure you know which school of OOP you are talking about.

About names

I choose Alan Kay and Bjarne Stroustrup as founders of schools, because they are big advocates of OOP and authors of first OOP languages of each school correspondingly. I’m aware that there are arguments on which programming language is the first OOP language and who invented OOP. See history section.

Kay's school

Stroustrup's school

TL;DR Describing typical problems with ruby function arguments. How I solved them with a gem. What other options are.

Ruby syntax

keyword arguments

Ruby 2.0 introduced first-class support for keyword arguments:

def foo(bar: 'default')
  puts bar
end

foo # => 'default'
foo(bar: 'baz') # => 'baz'

Programming mantras

programming

What is programming mantra? This is small advice or rule of thumb that should help write better code. Lets see some examples

  1. Less code is better
  2. Prefer composition over inheritance
  3. Don’t repeat yourself (DRY)

Sometime developers forget what is the purpose of mantras and start follow them blindly without giving a thought on what they actually doing.

Your aim as a developer write good code, not follow mantras. Mantras suppose to help you, not to make decisions instead of you.

Good code:

  • does what it is suppose to do
  • is readable and maintainable (in one row, because they are the sides of the same coin)

Here is the story from Sandi Metz which explains how DRY mantra can get you into bad position.

Duplication is far cheaper than the wrong abstraction.

See also: Too DRY - The Grep Test.

The future is already here — it's just not very evenly distributed.

Naming is hard

There are only two hard things in Computer Science: cache invalidation and naming things.

Phil Karlton

Unix philosophy

This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

You gotta do what you gotta do

psychology, herd behavior

Duck typing

Ruby decorators

rails, ruby

Good overview of decorator options for ruby listed in thoughtbot article

The simplest implementation is:

class Decorator < SimpleDelegator
  def self.wrap(collection)
    collection.map do |obj|
      new obj
    end
  end

  # to mimic draper
  # Be aware that draper does some magic to implement it,
  # so this will not work exactly the same as draper
  # https://github.com/drapergem/draper/blob/master/lib/draper/view_context.rb
  def h
    ActionController::Base.helpers
  end
end

class WorkerDecorator < Decorator
end

See also this article.

Draper

Draper is de facto choice for Rails projects. But be aware that there are some issues with it:

Cells

Cells is part of trailblazer project, which tries to bring “a high-level architecture for web applications”.

Rails: fighting N+1 query problem

rails, ruby

This problem is well known and have been solved 1000 times before. But most articles on rails and N+1 problem address mostly includes function. There are actually some more techniques (much simpler, but not obvious to fight this problem). I want to list them all.

Responsive big bold text

typography, Houdini

There are existing solutions for creating responsive big bold text. Most reliable so far are JS based.

JS

  • big-ideas-text. No jQuery!
  • fitText (32 sloc). Use this plugin on your fluid or responsive layout to achieve scalable headlines that fill the width of a parent element.
  • TextTailor (165 sloc). Responsive text to fill the height of the parent element or ellipse it when it doesn’t fit.
  • slabText (207 sloc). jQuery plugin for producing big, bold & responsive headlines. Implementation of slabtype alogorithm
  • BigText (248 sloc). jQuery plugin, calculates the font-size and word-spacing needed to match a line of text to a specific width.
  • hatchshow.js. jQuery plugin

If you take a look in source code, you will notice it is not complicated code. But all of them depend on jQuery. So it will introduce ~50kb of JS dependency for such simple functionality. Possible solution of this problem:

  • use lighter jQuery alternative
  • implement same functionality without jQuery dependency
  • implement using Houdini (when it will be ready)

Paint for Mac OS

mac

I believe all new Mac users have been asking the same question. This is just super strange that there is no simple, free image editor for Mac OS. Here is roundup of all options.